37template <
class ImageType,
class MaskType>
47 catch (std::exception& e)
49 std::cerr <<
"ERROR: Could not save " <<
exportImageInfo.getFileName() << std::endl
50 <<
"Cause: " << e.what() << std::endl;
59 std::cout <<
"Warning: Filetype " <<
filetype <<
" does not support alpha channels." << std::endl
60 <<
"Saving image without alpha channel." << std::endl;
65 catch (std::exception& e)
67 std::cerr <<
"ERROR: Could not save " <<
exportImageInfo.getFileName() << std::endl
68 <<
"Cause: " << e.what() << std::endl;
75 std::cerr <<
"ERROR: Output filetype " <<
filetype <<
" does not support " <<
inputNumberBands <<
" channels." << std::endl
76 <<
"Can't save image." << std::endl;
83template <
class ImageType,
class MaskType>
93 if (vigra::isPixelTypeSupported(
encoder->getFileType(),
"UINT16"))
96 output.setForcedRangeMapping(0, vigra::NumericTraits<
typename vigra::NumericTraits<typename ImageType::PixelType>::ValueType>::max(), 0, 65535);
101 if (vigra::isPixelTypeSupported(
encoder->getFileType(),
"UINT8"))
104 output.setForcedRangeMapping(0, vigra::NumericTraits<
typename vigra::NumericTraits<typename ImageType::PixelType>::ValueType>::max(), 0, 255);
109 std::cerr <<
"ERROR: Output file type " <<
encoder->getFileType() <<
" does not support" << std::endl
111 <<
"Save output in other file format." << std::endl;
122 if (!compression.empty())
124 if (
ext ==
"JPEG" ||
ext ==
"JPG")
126 output.setCompression(std::string(
"JPEG QUALITY=" + compression).
c_str());
130 output.setCompression(compression.c_str());
136template <
class ImageType>
143 vigra::Size2D imageSize(
imageInfos[0].getCanvasSize());
144 if (imageSize.area() == 0)
152 vigra::BImage mask(imageSize);
154 std::pair<typename ImageType::Iterator, typename ImageType::Accessor>(image.upperLeft() +
imageInfos[0].getPosition(), image.accessor()),
155 std::pair<typename vigra::BImage::Iterator, typename vigra::BImage::Accessor>(mask.upperLeft() +
imageInfos[0].getPosition(), mask.accessor()));
156 std::cout <<
"Loaded " <<
imageInfos[0].getFileName() << std::endl;
162 vigra::BImage
mask2(image2.size());
164 std::cout <<
"Loaded " <<
imageInfos[
i].getFileName() << std::endl;
185 std::cout << name <<
": blend images using watershed algorithm" << std::endl
188 <<
"Usage: " << name <<
" [options] images" << std::endl
190 <<
" --output=FILE Set the filename for the output file." << std::endl
191 <<
" --compression=value Compression of the output files" << std::endl
192 <<
" For jpeg output: 0-100" << std::endl
193 <<
" For tiff output: PACKBITS, DEFLATE, LZW" << std::endl
194 <<
" -w, --wrap Wraparound 360 deg border." << std::endl
195 <<
" --seam=hard|blend Select the blend mode for the seam" << std::endl
196 <<
" --bigtiff Write output in BigTIFF format" << std::endl
197 <<
" (only with TIFF output)" << std::endl
198 <<
" -h, --help Shows this help" << std::endl
205template<
class ImageType,
class MaskType>
209 MaskType mask(image.size());
213 vigra::importImage(
importInfo, vigra::destImage(image));
228 std::cerr <<
"ERROR: Images with several alpha channels are not supported." << std::endl;
232 std::cout <<
"Loaded " <<
importInfo.getFileName() << std::endl;
242 vigra::BImage label(image.size());
243 vigra::omp::transformImage(vigra::srcImageRange(mask), vigra::destImage(label), vigra::functor::ifThenElse(vigra::functor::Arg1() > vigra::functor::Param(
maskMax / 2), vigra::functor::Param(1), vigra::functor::Param(5)));
246 vigra::inspectImage(vigra::srcImageRange(label),
labelMinmax);
249 std::cout <<
"Filling edges" << std::endl;
253 vigra::initImage(vigra::destImageRange(mask),
maskMax);
256 const vigra::Rect2D
roi(vigra::Point2D(0, 0), image.size());
284 std::string compression;
287 bool useBigTIFF =
false;
349 std::vector<std::string> files;
379 if (files.size() == 1)
419 std::cerr <<
" ERROR: unsupported pixel type: " <<
pixeltype << std::endl;
451 std::cerr <<
" ERROR: unsupported pixel type: " <<
pixeltype << std::endl;
457 std::vector<vigra::ImageImportInfo>
imageInfos;
458 for (
size_t i = 0;
i < files.size(); ++
i)
466 std::cerr <<
"ERROR: Image does not contain alpha channel." << std::endl;
470 for (
size_t i = 1;
i < files.size(); ++
i)
474 std::cerr <<
"ERROR: You can't merge color and grayscale images." << std::endl;
479 std::cerr <<
"ERROR: You can't merge image with different number of channels." << std::endl
480 <<
" Image \"" <<
imageInfos[0].getFileName() <<
"\" has " <<
imageInfos[0].numBands() <<
" channels," << std::endl
481 <<
" but image \"" <<
imageInfos[
i].getFileName() <<
"\" has " <<
imageInfos[
i].numBands() <<
" channels." << std::endl;
486 std::cerr <<
"ERROR: You can't merge images with different pixel types." << std::endl
487 <<
" Image \"" <<
imageInfos[0].getFileName() <<
"\" has pixel type " <<
imageInfos[0].getPixelType() <<
"," << std::endl
488 <<
" but image \"" <<
imageInfos[
i].getFileName() <<
"\" has pixel type " <<
imageInfos[
i].getPixelType() <<
"." << std::endl;
525 std::cerr <<
" ERROR: unsupported pixel type: " <<
pixeltype << std::endl;
561 std::cerr <<
" ERROR: unsupported pixel type: " <<
pixeltype << std::endl;
568 std::cout <<
"Written result to " <<
output << std::endl;
class AlphaIterator class AlphaAccessor inline void importImageAlpha(const ImageImportInfo &import_info, ImageIterator image_iterator, ImageAccessor image_accessor, AlphaIterator alpha_iterator, AlphaAccessor alpha_accessor)
class AlphaIterator class AlphaAccessor inline void exportImageAlpha(ImageIterator image_upper_left, ImageIterator image_lower_right, ImageAccessor image_accessor, AlphaIterator alpha_upper_left, AlphaAccessor alpha_accessor, const ImageExportInfo &export_info)
vigra::FRGBImage ImageType
std::string toupper(const std::string &s)
std::string getExtension(const std::string &basename2)
Get extension of a filename.
void EnforceExtension(std::string &filename, const std::string &defaultExtension)
check if filename contains extension, if not add default extension
std::string tolower(const std::string &s)
convert a string to lowercase
bool IsFileTypeSupported(const std::string &filename)
return true, if file type by extension is supported by vigra
std::string GetHuginVersion()
return a string with version numbers
bool FileExists(const std::string &filename)
checks if file exists
std::string stripPath(const std::string &filename)
remove the path of a filename (mainly useful for gui display of filenames)
void transformImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc, const Functor &func)
void PoissonBlend(ImageType &image1, const ImageType &image2, const MaskType &mask2, const vigra::BImage &labels, const vigra::Point2D &offsetPoint, const bool doWrap)
void MergeImages(ImageType &image1, MaskType &mask1, const ImageType &image2, const MaskType &mask2, const vigra::Diff2D offset, const bool wrap, const bool hardSeam)
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
int main(int argc, char *argv[])
bool LoadAndMergeImages(std::vector< vigra::ImageImportInfo > imageInfos, const std::string &filename, const std::string &compression, const bool wrap, const bool hardSeam, const bool useBigTiff)
loads image one by one and merge with all previouly loaded images, saves the final results
bool SaveImage(ImageType &image, MaskType &mask, vigra::ImageExportInfo &exportImageInfo, std::string filetype, std::string pixelType, const vigra::Rect2D &roi, const int inputNumberBands)
save image, when possible with alpha channel, take care of formats which does not support alpha chann...
void SetCompression(vigra::ImageExportInfo &output, const std::string &compression)
set compression for jpeg or tiff
bool SaveFinalImage(ImageType &image, MaskType &mask, const std::string &inputPixelType, const int inputNumBands, vigra::ImageExportInfo &output, const vigra::Rect2D &roi)
save final image, take care of some supported pixel types and convert when necessary to smaller pixel...
bool ResaveImageFill(const vigra::ImageImportInfo &importInfo, vigra::ImageExportInfo &exportInfo, bool fillEdges, bool doWrap)
resave a single image LoadAndMergeImage would require the full canvas size for loading,...
functions to manage ROI's