Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PointSampler.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
24 #include "PointSampler.h"
25 
29 #include <vigra/convolution.hxx>
30 
31 namespace HuginBase
32 {
33 
36 {
37  m_minI = -FLT_MAX;
38  m_maxI = FLT_MAX;
39 };
40 
43 {
44  switch (limit)
45  {
46  case LIMIT_UINT8:
47  m_minI = 1 / 255.0f;
48  m_maxI = 250 / 255.0f;
49  break;
50  case LIMIT_UINT16:
51  m_minI = 1 / 65535.0f;
52  m_maxI = 65000 / 65535.0f;
53  break;
54  case LIMIT_FLOAT:
55  m_minI = -FLT_MAX;
56  m_maxI = FLT_MAX;
57  break;
58  };
59 };
60 
62 {
63  // is this correct? how much progress requierd?
65 
67  {
69  };
70 
71  return wasCancelled();
72 }
73 
75 {
76  PanoramaData& pano = *(o_panorama.getNewCopy()); // don't forget to delete!
77  std::vector<vigra::FRGBImage*>& images = o_images;
78  int& nPoints = o_numPoints;
79  std::vector<vigra_ext::PointPairRGB>& points = o_resultPoints;
80 
81  std::vector<vigra::FImage *> lapImgs;
82  std::vector<vigra::Size2D> origsize;
83 
84  // convert to interpolating images
86  std::vector<InterpolImg> interpolImages;
87 
89  // adjust sizes in panorama
91  for (unsigned i=0; i < pano.getNrOfImages(); i++)
92  {
93  SrcPanoImage simg = pano.getSrcImage(i);
94  origsize.push_back(simg.getSize());
95  simg.resize(images[i]->size(), &vars[i]);
96  pano.setSrcImage(i, simg);
97  interpolImages.push_back(InterpolImg(srcImageRange(*(images[i])), interp, false));
98 
99  vigra::FImage * lap = new vigra::FImage(images[i]->size());
100  lapImgs.push_back(lap);
101  }
102  // now update all possible linked variables
103  // this has to be done separately, otherwise the linked variables
104  // would be updated several times
105  for (unsigned i = 0; i < pano.getNrOfImages(); ++i)
106  {
107  if (!vars[i].empty())
108  {
109  pano.updateVariables(i, vars[i]);
110  };
111  };
112 #pragma omp parallel for
113  for (int i = 0; i < pano.getNrOfImages(); i++)
114  {
115  vigra::laplacianOfGaussian(srcImageRange(*(images[i]), vigra::GreenAccessor<vigra::RGBValue<float> >()), destImage(*(lapImgs[i])), 1);
116  }
117 
118  // extract the overlapping points.
119 // PanoramaOptions opts = pano.getOptions();
120 // double scale = CalculateOptimalScale::calcOptimalPanoScale(pano.getSrcImage(0),opts);
121 // opts.setWidth(utils::roundi(opts.getWidth()*scale), true);
122 // pano.setOptions(opts);
123  // center panorama and do fit to get minimum of black/unused space around panorama
124  CenterHorizontally(pano).run();
125  PanoramaOptions opts = pano.getOptions();
126  CalculateFitPanorama fitPano(pano);
127  fitPano.run();
128  opts.setHFOV(fitPano.getResultHorizontalFOV());
130  // set roi to maximal size, so that the whole panorama is used for sampling
131  // a more reasonable solution would be to use the maximal
132  // used area, but this is currently not support to
133  // calculate optimal roi
134  opts.setROI(vigra::Rect2D(opts.getSize()));
135  pano.setOptions(opts);
136  SetWidthOptimal(pano).run();
137 
138  // if random points.
139  // extract random points.
140  // need to get the maximum gray value here..
141 
142  std::vector<std::multimap<double, vigra_ext::PointPairRGB> > radiusHist(10);
143 
144  unsigned nGoodPoints = 0;
145  unsigned nBadPoints = 0;
146 
147 
148  // call the samplePoints method of this class
149  progress->setMessage("sampling points");
150  samplePoints(interpolImages,
151  lapImgs,
152  pano,
153  m_limits,
154  radiusHist,
155  nGoodPoints,
156  nBadPoints,
157  progress);
158 
159  // select points with low laplacian of gaussian values.
160  progress->setMessage("extracting good points");
161  sampleRadiusUniform(radiusHist, nPoints, points, progress);
162 
163  // scale point coordinates to fit into original panorama.
164  for (size_t i=0; i < points.size(); i++) {
165  double scaleF1 = origsize[points[i].imgNr1].x / (float) images[points[i].imgNr1]->size().x;
166  double scaleF2 = origsize[points[i].imgNr2].x / (float) images[points[i].imgNr2]->size().x;
167  points[i].p1.x = points[i].p1.x * scaleF1;
168  points[i].p1.y = points[i].p1.y * scaleF1;
169  points[i].p2.x = points[i].p2.x * scaleF2;
170  points[i].p2.y = points[i].p2.y * scaleF2;
171  }
172 
173  for (size_t i=0; i < images.size(); i++) {
174  delete images[i];
175  delete lapImgs[i];
176  }
177 
178  delete &pano; // deleting the NewCopy
179 }
180 
181 }; // namespace
182 
LimitIntensity()
default constructor, is identical to LimitIntensity(LIMIT_FLOAT)
vigra_ext::ImageInterpolator< vigra::FRGBImage::const_traverser, vigra::FRGBImage::ConstAccessor, vigra_ext::interp_cubic > InterpolImg
Definition: PointSampler.h:80
static void sampleRadiusUniform(const std::vector< std::multimap< double, PointPairClass > > &radiusHist, unsigned nPoints, std::vector< PointPairClass > &selectedPoints, AppBase::ProgressDisplay *)
extract some random points out of the bins.
Definition: PointSampler.h:270
void setHeight(unsigned int h)
set panorama height
int roundi(T x)
Definition: hugin_math.h:73
float m_minI
internal stored limits
Definition: PointSampler.h:63
LimitType
some pre-defined limits
Definition: PointSampler.h:48
virtual void setSrcImage(unsigned int nr, const SrcPanoImage &img)=0
set input image parameters TODO: Propagate changes to linked images.
virtual void cancelAlgorithm()
Call this when the algorithm is cancelled.
&quot;wrapper&quot; for efficient interpolation access to an image
virtual void run()
runs the algorithm.
std::vector< vigra::FRGBImage * > o_images
Definition: PointSampler.h:139
virtual void samplePoints(const std::vector< InterpolImg > &imgs, const std::vector< vigra::FImage * > &voteImgs, const PanoramaData &pano, const LimitIntensityVector limitI, std::vector< std::multimap< double, vigra_ext::PointPairRGB > > &radiusHist, unsigned &nGoodPoints, unsigned &nBadPoints, AppBase::ProgressDisplay *)=0
cubic interpolation
std::vector< VariableMap > VariableMapVector
LimitIntensityVector m_limits
Definition: PointSampler.h:142
virtual bool runAlgorithm()
implementation of the algorithm.
virtual AppBase::ProgressDisplay * getProgressDisplay() const
void sampleAndExtractPoints(AppBase::ProgressDisplay *progress)
virtual void setOptions(const PanoramaOptions &opt)=0
set new output settings This is not used directly for optimizing/stiching, but it can be feed into ru...
virtual double getResultHeight()
Definition: FitPanorama.h:75
void resize(const vigra::Size2D &size, VariableMap *potentialLinkedVars)
&quot;resize&quot; image, adjusts all distortion coefficients for usage with a source image of size size potent...
virtual const PanoramaOptions & getOptions() const =0
returns the options for this panorama
void setMessage(const std::string &message, const std::string &filename="")
sets the message to given string
Model for a panorama.
Definition: PanoramaData.h:81
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
Definition: ROIImage.h:324
void setROI(const vigra::Rect2D &val)
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
void setHFOV(double h, bool keepView=true)
set the horizontal field of view.
virtual double getResultHorizontalFOV()
Definition: FitPanorama.h:68
virtual SrcPanoImage getSrcImage(unsigned imgNr) const =0
get a complete description of a source image
virtual std::size_t getNrOfImages() const =0
number of images.
All variables of a source image.
Definition: SrcPanoImage.h:194
Panorama image options.
vigra::Size2D getSize() const
get size of output image
virtual void updateVariables(const VariableMapVector &vars)=0
Set the variables.
virtual PanoramaData * getNewCopy() const =0