27#include <vigra/distancetransform.hxx>
52#define TRACE_IMG(X) {if (iPanoDetector.getVerbose() > 1) { TRACE_INFO("i" << ioImgInfo._number << " : " << X << std::endl);} }
53#define TRACE_PAIR(X) {if (iPanoDetector.getVerbose() > 1){ TRACE_INFO("i" << ioMatchData._i1->_number << " <> " \
54 "i" << ioMatchData._i2->_number << " : " << X << std::endl)}}
123template <
class SrcImageIterator,
class SrcAccessor>
126 vigra::Diff2D
imgSize = img.second - img.first;
137 if(!
SrcImg.isInside(vigra::Point2D(x,y)))
163 template <
class T2,
class A>
177template <
class ImageType,
class PixelTransform>
194 mask =
new vigra::BImage(image->size(), vigra::UInt8(255));
216template <
class ImageType>
226 mask =
new vigra::BImage(image->size(), vigra::UInt8(255));
235 vigra::resizeImageNoInterpolation(vigra::srcImageRange(*image), vigra::destImageRange(*
finalImage));
242 vigra::resizeImageNoInterpolation(vigra::srcImageRange(*mask), vigra::destImageRange(*
finalMask));
273 TRACE_INFO(
"Image with multiple alpha channels are not supported");
285 vigra::DImage* image =
new vigra::DImage(
aImageInfo.size());
286 vigra::BImage* mask =
NULL;
295 vigra::importImage(
aImageInfo, vigra::destImage(*image));
300 if (
aImageInfo.getPixelType() == std::string(
"FLOAT") ||
aImageInfo.getPixelType() == std::string(
"DOUBLE") ||
301 aImageInfo.getPixelType() == std::string(
"UINT32") ||
aImageInfo.getPixelType() == std::string(
"INT32"))
303 vigra::FindAverageAndVariance<float>
mean;
304 vigra::inspectImage(vigra::srcImageRange(*image),
mean);
319 vigra::transformImage(vigra::srcImageRange(*image), vigra::destImage(*image),
329 vigra::transformImage(vigra::srcImageRange(*image), vigra::destImage(*image),
356 TRACE_IMG(
"Downscale and transform to suitable grayscale...");
363 TRACE_IMG(
"Transform to suitable grayscale...");
367 vigra::transformImage(vigra::srcImageRange(*
final_img), vigra::destImage(*
final_img), vigra::linearRangeMapping(0, 1, 0, 255));
372 TRACE_IMG(
"Celeste does not work with grayscale images. Skipping...");
396 case vigra::ImageImportInfo::UINT8:
400 vigra::BImage* mask =
NULL;
440 vigra::UInt16RGBImage* image16=
new vigra::UInt16RGBImage(
scaled->size());
441 vigra::transformImage(vigra::srcImageRange(*
scaled), vigra::destImage(*image16),
442 vigra::linearIntensityTransform<vigra::RGBValue<vigra::UInt16> >(255));
444#ifdef DEBUG_LOADING_REMAPPING
462 TRACE_IMG(
"Convert to greyscale double...");
464 vigra::copyImage(vigra::srcImageRange(*
scaled, vigra::RGBToGrayAccessor<vigra::RGBValue<vigra::UInt8> >()),
469 case vigra::ImageImportInfo::UINT16:
473 vigra::BImage* mask =
NULL;
514#ifdef DEBUG_LOADING_REMAPPING
531 TRACE_IMG(
"Convert to greyscale double...");
534 vigra::transformImage(vigra::srcImageRange(*
scaled, vigra::RGBToGrayAccessor<vigra::RGBValue<vigra::UInt16> >()),
535 vigra::destImage(*
final_img), vigra::functor::Arg1() / vigra::functor::Param(255.0));
543 vigra::BImage* mask =
NULL;
558 aImageInfo.getPixelType() == std::string(
"UINT32") ||
aImageInfo.getPixelType() == std::string(
"INT32");
561 vigra::FindAverageAndVariance<float>
mean;
562 vigra::inspectImage(vigra::srcImageRange(*
rgbImage, vigra::RGBToGrayAccessor<vigra::RGBValue<double> >()),
mean);
592 vigra::transformImage(vigra::srcImageRange(*
rgbImage), vigra::destImage(*
rgbImage),
608 TRACE_IMG(
"Transform to suitable grayscale...");
616 vigra::UInt16RGBImage* image16 =
new vigra::UInt16RGBImage(
scaled->size());
619 vigra::transformImage(vigra::srcImageRange(*
scaled), vigra::destImage(*image16),
620 vigra::linearIntensityTransform<vigra::RGBValue<vigra::UInt16> >(255));
624 vigra::transformImage(vigra::srcImageRange(*
scaled), vigra::destImage(*image16),
625 vigra::linearIntensityTransform<vigra::RGBValue<vigra::UInt16> >(65535));
628#ifdef DEBUG_LOADING_REMAPPING
646 TRACE_IMG(
"Convert to greyscale double...");
651 vigra::copyImage(vigra::srcImageRange(*
scaled, vigra::RGBToGrayAccessor<vigra::RGBValue<double> >()), vigra::destImage(*
final_img));
655 vigra::transformImage(vigra::srcImageRange(*
scaled, vigra::RGBToGrayAccessor<vigra::RGBValue<double> >()),
656 vigra::destImage(*
final_img), vigra::functor::Arg1() * vigra::functor::Param(255.0));
665 TRACE_INFO(
"Cpfind works only with grayscale or RGB images");
671#ifdef DEBUG_LOADING_REMAPPING
673 std::ostringstream filename;
674 filename <<
ioImgInfo._name <<
"_grey.JPG";
675 vigra::ImageExportInfo
exinfo(filename.str().c_str());
690 vigra::Threshold<vigra::BImage::PixelType, vigra::BImage::PixelType>(1, 255, 0, 255));
692 vigra::distanceTransform(vigra::srcImageRange(*
final_mask), vigra::destImage(
ioImgInfo._distancemap), 255, 2);
693#ifdef DEBUG_LOADING_REMAPPING
706 catch (std::exception& e)
708 TRACE_INFO(
"An error happened while loading image : caught exception: " << e.what() << std::endl);
779 TRACE_IMG(
"Make keypoint descriptors...");
826 TRACE_IMG(
"Remapping back keypoints...");
870 ioImgInfo._flann_index =
new flann::Index<flann::L2<double> > (
ioImgInfo._flann_descriptors, flann::KDTreeIndexParams(4));
915 typedef std::pair<lfeat::KeyPointPtr, int>
TmpPair_t;
962 delete[]
dists.ptr();
986 TRACE_PAIR(
"RANSAC Filtering with Panorama model...");
990 TRACE_PAIR(
"Too few matches ... removing all of them.");
997 TRACE_PAIR(
"Not enough matches for RANSAC filtering.");
1056 TRACE_PAIR(
"RANSAC found more than 50% outliers, removing all matches");
1064 TRACE_PAIR(
"Too few matches ... removing all of them.");
1095 TRACE_PAIR(
"Too few matches ... removing all of them.");
1102 TRACE_PAIR(
"Not enough matches for RANSAC filtering.");
1126 TRACE_PAIR(
"More than 50% outliers, removing all matches");
1151 double aMinX = std::numeric_limits<double>::max();
1152 double aMinY = std::numeric_limits<double>::max();
1153 double aMaxX = -std::numeric_limits<double>::max();
1154 double aMaxY = -std::numeric_limits<double>::max();
1219 std::cerr <<
"ERROR couldn't write to output file '" <<
_outputFile <<
"'!" << std::endl;
1227 std::ofstream
aOut(
imgInfo._keyfilename.c_str(), std::ios_base::trunc);
!! from PTOptimise.h 1951
void HandleDownscaleImage(const HuginBase::SrcPanoImage &srcImage, ImageType *&image, vigra::BImage *&mask, size_t detectWidth, size_t detectHeight, bool downscale, ImageType *&finalImage, vigra::BImage *&finalMask)
downscale image if requested, optimized code for non-downscale version to prevent unnecessary copying...
void applyMaskAndCrop(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > img, const HuginBase::SrcPanoImage &SrcImg)
apply the mask and the crop of the given SrcImg to given mask image
void RemapImage(const HuginBase::SrcPanoImage &srcImage, const HuginBase::PanoramaOptions &options, size_t detectWidth, size_t detectHeight, ImageType *&image, vigra::BImage *&mask, const PixelTransform &pixelTransform, ImageType *&finalImage, vigra::BImage *&finalMask)
helper function to remap image to given projection, you can supply a pixelTransform,...
static int ptProgress(int command, char *argument)
static int ptinfoDlg(int command, char *argument)
Contains functions to transform whole images.
Dummy progress display, without output.
@ RESPONSE_LINEAR
linear response
represents a control point
virtual PanoramaData * getNewSubset(const UIntSet &imgs) const =0
const vigra::Rect2D & getROI() const
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
bool WritePTOFile(const std::string &filename, const std::string &prefix="")
write data to given pto file
static std::vector< int > findInliers(PanoramaData &pano, int i1, int i2, double maxError, Mode mode=RPY)
All variables of a source image.
virtual void operator()(const lfeat::KeyPoint &k)
lfeat::KeyPointVect_t & _v
KeyPointVectInsertor(lfeat::KeyPointVect_t &iVect)
static bool AnalyzeImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
static bool MakeKeyPointDescriptorsInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
void writeKeyfile(ImgData &imgInfo)
static bool FindMatchesInPair(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
static bool FindKeyPointsInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
HuginBase::Panorama * _panoramaInfo
static bool FilterKeyPointsInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
static bool BuildKDTreesInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
static bool RansacMatchesInPairHomography(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
static bool FreeMemoryInImage(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
static bool RansacMatchesInPair(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
static bool RansacMatchesInPairCam(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
static bool LoadKeypoints(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
static bool RemapBackKeypoints(ImgData &ioImgInfo, const PanoDetector &iPanoDetector)
static bool FilterMatchesInPair(MatchData &ioMatchData, const PanoDetector &iPanoDetector)
static void drawRansacMatches(std::string &i1, std::string &i2, lfeat::PointMatchVector_t &iOK, lfeat::PointMatchVector_t &iNOK, lfeat::Ransac &iRansac, bool iHalf)
void setIterations(int iIters)
functions to handle icc profiles in images
class AlphaIterator class AlphaAccessor inline void importImageAlpha(const ImageImportInfo &import_info, ImageIterator image_iterator, ImageAccessor image_accessor, AlphaIterator alpha_iterator, AlphaAccessor alpha_accessor)
vigra::FRGBImage ImageType
void ApplyICCProfile(ImageType &image, const vigra::ImageImportInfo::ICCProfile &iccProfile, const cmsUInt32Number imageFormat)
converts given image with iccProfile to sRGB/gray space, need to give pixel type in lcms2 format work...
std::vector< ControlPoint > CPVector
std::set< unsigned int > UIntSet
vigra::BImage * getCelesteMask(struct svm_model *model, vigra::UInt16RGBImage &input, int radius, float threshold, int resize_dimension, bool adaptThreshold, bool verbose)
calculates the mask using SVM
std::string getPathPrefix(const std::string &filename)
Get the path to a filename.
ImageInfo loadKeypoints(const std::string &filename, KeyPointVect_t &vec)
std::shared_ptr< KeyPoint > KeyPointPtr
std::shared_ptr< PointMatch > PointMatchPtr
std::vector< PointMatchPtr > PointMatchVector_t
std::vector< KeyPointPtr > KeyPointVect_t
void transformImage(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, vigra::Diff2D destUL, TRANSFORM &transform, PixelTransform &pixelTransform, bool warparound, Interpolator interpol, AppBase::ProgressDisplay *progress, bool singleThreaded=false)
Transform an image into the panorama.
void transformImageAlpha(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, std::pair< SrcAlphaIterator, SrcAlphaAccessor > srcAlpha, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, vigra::Diff2D destUL, TRANSFORM &transform, PixelTransform &pixelTransform, bool warparound, Interpolator interpol, AppBase::ProgressDisplay *progress, bool singleThreaded=false)
Transform image, and respect a possible alpha channel.
double getMaxValForPixelType(const std::string &v)
void applyMapping(vigra::triple< SrcIterator, SrcIterator, SrcAccessor > img, vigra::pair< DestIterator, DestAccessor > dest, T min, T max, int mapping)
bool set_contains(const _Container &c, const typename _Container::key_type &key)
functor to scale image on the fly during other operations
T2 operator()(const T2 &a, const hugin_utils::FDiff2D &p) const
A hdrWeight(T2 v, A a) const
ScaleFunctor(double scale)
T operator()(const T &a) const
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.