Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtractPoints.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
30 #include <hugin_basic.h>
31 
32 #include <vigra/error.hxx>
33 #include <vigra/impex.hxx>
34 
35 #include <vigra_ext/Pyramid.h>
36 #include <vigra_ext/impexalpha.hxx>
38 
39 template<class ImageType>
40 std::vector<ImageType *> loadImagesPyr(std::vector<std::string> files, int pyrLevel, int verbose, HuginBase::LimitIntensityVector& limits, float& imageStepSize)
41 {
42  std::vector<ImageType *> srcImgs(files.size());
43  limits.resize(srcImgs.size());
44 #ifdef _WIN32
45  // init vigra codec manager before threaded section
46  // otherwise there could be sometimes race conditions
47  // which results in exceptions
48  std::string s = vigra::impexListExtensions();
49 #endif
50 #pragma omp parallel for schedule(dynamic)
51  for (int i=0; i < files.size(); i++) {
52  ImageType * tImg = new ImageType();
53  ImageType * tImg2 = new ImageType();
54  std::ostringstream buf;
55  vigra::ImageImportInfo info(files[i].c_str());
56  tImg->resize(info.size());
57  if (verbose)
58  buf << "loading: " << files[i] << std::endl;
59 
60  const std::string pixelType(info.getPixelType());
61  if (info.numExtraBands() == 1) {
62  // dummy mask
63  vigra::BImage mask(info.size());
65  if (pixelType == "FLOAT" || pixelType == "DOUBLE")
66  {
68  vigra::inspectImageIf(vigra::srcImageRange(*tImg), vigra::srcImage(mask), minmax);
69  imageStepSize = std::min(imageStepSize, (minmax.max - minmax.min) / 16384.0f);
70  };
71  } else {
72  vigra::importImage(info, vigra::destImage(*tImg));
73  if (pixelType == "FLOAT" || pixelType == "DOUBLE")
74  {
76  vigra::inspectImage(vigra::srcImageRange(*tImg), minmax);
77  imageStepSize = std::min(imageStepSize, (minmax.max - minmax.min) / 16384.0f);
78  };
79  }
80  float div = 1;
82  if (pixelType== "UINT8") {
83  div = 255;
85  imageStepSize = std::min(imageStepSize, 1 / 255.0f);
86 
87  } else if (pixelType=="UINT16") {
88  div = (1<<16)-1;
90  imageStepSize = std::min(imageStepSize, 1 / 65536.0f);
91  }
92 
93  if (pyrLevel) {
94  ImageType * swap;
95  // create downscaled image
96  if (verbose > 0) {
97  buf << "downscaling: ";
98  }
99  for (int l=pyrLevel; l > 0; l--) {
100  if (verbose > 0) {
101  buf << tImg->size().x << "x" << tImg->size().y << " " << std::flush;
102  }
103  vigra_ext::reduceToNextLevel(*tImg, *tImg2);
104  swap = tImg;
105  tImg = tImg2;
106  tImg2 = swap;
107  }
108  if (verbose > 0)
109  buf << std::endl;
110  }
111  if (div > 1) {
112  div = 1/div;
114  vigra::functor::Arg1()*vigra::functor::Param(div));
115  }
116  srcImgs[i]=tImg;
117  delete tImg2;
118  if (verbose > 0)
119  {
120  std::cout << buf.str();
121  };
122  }
123  return srcImgs;
124 }
125 
126 
127 // needs 2.0 progress steps
128 void loadImgsAndExtractPoints(HuginBase::Panorama pano, int nPoints, int pyrLevel, bool randomPoints, AppBase::ProgressDisplay& progress, std::vector<vigra_ext::PointPairRGB> & points, int verbose, float& imageStepSize)
129 {
130  // extract file names
131  std::vector<std::string> files;
132  for (size_t i=0; i < pano.getNrOfImages(); i++)
133  files.push_back(pano.getImage(i).getFilename());
134 
135  std::vector<vigra::FRGBImage*> images;
137  imageStepSize = 1 / 255.0f;
138 
139  // try to load the images.
140  images = loadImagesPyr<vigra::FRGBImage>(files, pyrLevel, verbose, limits, imageStepSize);
141 
142  progress.setMessage("Sampling points");
143  if(randomPoints)
144  points = HuginBase::RandomPointSampler(pano, &progress, images, limits, nPoints).execute().getResultPoints();
145  else
146  points = HuginBase::AllPointSampler(pano, &progress, images, limits, nPoints).execute().getResultPoints();
147  progress.taskFinished();
148 }
void reduceToNextLevel(ImageIn &in, ImageOut &out)
Definition: Pyramid.h:136
static void swap(T &x, T &y)
Definition: svm.cpp:67
class for storing the limits of an image used by the sampler to exclude too dark or too bright pixel ...
Definition: PointSampler.h:44
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 loadImgsAndExtractPoints(HuginBase::Panorama pano, int nPoints, int pyrLevel, bool randomPoints, AppBase::ProgressDisplay &progress, std::vector< vigra_ext::PointPairRGB > &points, int verbose, float &imageStepSize)
vigra::pair< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImage(const ROIImage< Image, Mask > &img)
Definition: ROIImage.h:300
PointPairs getResultPoints()
Definition: PointSampler.h:130
Model for a panorama.
Definition: Panorama.h:152
void taskFinished()
call when a task has finished and the status message should be cleared
std::size_t getNrOfImages() const
number of images.
Definition: Panorama.h:205
vigra::FRGBImage ImageType
std::vector< ImageType * > loadImagesPyr(std::vector< std::string > files, int pyrLevel, int verbose, HuginBase::LimitIntensityVector &limits, float &imageStepSize)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: ExtractPoints.h:40
void setMessage(const std::string &message, const std::string &filename="")
sets the message to given string
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
Definition: ROIImage.h:324
vigra::triple< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImageRange(const ROIImage< Image, Mask > &img)
helper function for ROIImages
Definition: ROIImage.h:287
VALUETYPE min
the current min
Definition: utils.h:362
void importImageAlpha(const ImageImportInfo &import_info, ImageIterator image_iterator, ImageAccessor image_accessor, AlphaIterator alpha_iterator, AlphaAccessor alpha_accessor)
Read the image specified by the given vigra::ImageImportInfo object including its alpha channel...
Definition: impexalpha.hxx:479
VALUETYPE max
the current max
Definition: utils.h:364
std::vector< LimitIntensity > LimitIntensityVector
Definition: PointSampler.h:65
static void info(const char *fmt,...)
Definition: svm.cpp:95
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition: Panorama.h:211
PointSampler & execute()
Definition: PointSampler.h:119
static T min(T x, T y)
Definition: svm.cpp:62