Hugin trunk 0.1
Loading...
Searching...
No Matches
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
31namespace HuginBase
32{
33
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;
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 {
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");
151 lapImgs,
152 pano,
153 m_limits,
157 progress);
158
159 // select points with low laplacian of gaussian values.
160 progress->setMessage("extracting good points");
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
virtual double getResultHorizontalFOV()
Definition FitPanorama.h:68
virtual double getResultHeight()
Definition FitPanorama.h:75
LimitType
some pre-defined limits
float m_minI
internal stored limits
LimitIntensity()
default constructor, is identical to LimitIntensity(LIMIT_FLOAT)
virtual void run()
runs the algorithm.
Model for a panorama.
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 const PanoramaOptions & getOptions() const =0
returns the options for this panorama
virtual void setSrcImage(unsigned int nr, const SrcPanoImage &img)=0
set input image parameters TODO: Propagate changes to linked images.
virtual SrcPanoImage getSrcImage(unsigned imgNr) const =0
get a complete description of a source image
virtual void updateVariables(const VariableMapVector &vars)=0
Set the variables.
virtual std::size_t getNrOfImages() const =0
number of images.
virtual PanoramaData * getNewCopy() const =0
Panorama image options.
void setHFOV(double h, bool keepView=true)
set the horizontal field of view.
void setHeight(unsigned int h)
set panorama height
void setROI(const vigra::Rect2D &val)
vigra::Size2D getSize() const
get size of output image
void sampleAndExtractPoints(AppBase::ProgressDisplay *progress)
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.
std::vector< vigra::FRGBImage * > o_images
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
LimitIntensityVector m_limits
virtual bool runAlgorithm()
implementation of the algorithm.
vigra_ext::ImageInterpolator< vigra::FRGBImage::const_traverser, vigra::FRGBImage::ConstAccessor, vigra_ext::interp_cubic > InterpolImg
All variables of a source image.
void resize(const vigra::Size2D &size, VariableMap *potentialLinkedVars)
"resize" image, adjusts all distortion coefficients for usage with a source image of size size potent...
virtual void cancelAlgorithm()
Call this when the algorithm is cancelled.
virtual AppBase::ProgressDisplay * getProgressDisplay() const
"wrapper" for efficient interpolation access to an image
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
std::vector< VariableMap > VariableMapVector
int roundi(T x)
Definition hugin_math.h:73
cubic interpolation
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.
Definition threshold.h:41