Debian Codegraph @

include/vigra/affine_registration_fft.hxx

raw symbols SCIP
1 /************************************************************************/cxx . . $ `<file>/include/vigra/affine_registration_fft.hxx`/
2 /* */
3 /* Copyright 2007-2014 by Benjamin Seppke */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* [email protected] or */
10 /* [email protected] */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35
36 #ifndef VIGRA_AFFINE_REGISTRATION_FFT_HXX
37 #define VIGRA_AFFINE_REGISTRATION_FFT_HXXcxx . . $ `include/vigra/affine_registration_fft.hxx:37:9`!
38
39 #include "mathutil.hxx"cxx . . $ `<file>/include/vigra/mathutil.hxx`/
40 #include "matrix.hxx"cxx . . $ `<file>/include/vigra/matrix.hxx`/
41 #include "linear_solve.hxx"cxx . . $ `<file>/include/vigra/linear_solve.hxx`/
42 #include "tinyvector.hxx"cxx . . $ `<file>/include/vigra/tinyvector.hxx`/
43 #include "splineimageview.hxx"cxx . . $ `<file>/include/vigra/splineimageview.hxx`/
44 #include "imagecontainer.hxx"cxx . . $ `<file>/include/vigra/imagecontainer.hxx`/
45 #include "multi_shape.hxx"cxx . . $ `<file>/include/vigra/multi_shape.hxx`/
46 #include "affinegeometry.hxx"cxx . . $ `<file>/include/vigra/affinegeometry.hxx`/
47 #include "correlation.hxx"cxx . . $ `<file>/include/vigra/correlation.hxx`/
48
49 #include <cmath>
50
51 namespace vigracxx . . $ vigra/ {
52
53 /** \addtogroup Registration Image Registration
54 */
55 //@{
56
57 /********************************************************/
58 /* */
59 /* transformToPolarCoordinates */
60 /* */
61 /********************************************************/
62
63 /** \brief Transforms a given image to its (image-centered) polar coordinates representation.
64
65 This algorithm transforms a given image (by means of an spline image view) to its
66 image-centered polar coordinates reprensentation. The sampling of the polar coordinate system
67 is determined by the shape of the dest. image.
68
69 <b> Declarations:</b>
70
71 <b>\#include</b> \<vigra/affine_registration_fft.hxx\><br>
72 Namespace: vigra
73
74 pass 2D array views:
75 \code
76 namespace vigra {
77 template <class SplineImage,
78 class T1, class S1>
79 void
80 transformToPolarCoordinates(SplineImage const & src,
81 MultiArrayView<2, T1, S1> dest);
82 }
83 \endcode
84
85 \deprecatedAPI{estimateTranslation}
86 pass \ref ImageIterators and \ref DataAccessors :
87 \code
88 namespace vigra {
89 template <class SplineImage,
90 class DestIterator, class DestAccessor>
91 void
92 transformToPolarCoordinates(SplineImage const & src,
93 DestIterator dul, DestIterator dlr, DestAccessor dest)
94 }
95 \endcode
96 use argument objects in conjunction with \ref ArgumentObjectFactories :
97 \code
98 namespace vigra {
99 template <class SplineImage,
100 class DestIterator, class DestAccessor>
101 void
102 transformToPolarCoordinates(SplineImage const & src,
103 triple<DestIterator, DestIterator, DestAccessor> dest)
104 }
105 \endcode
106 \deprecatedEnd
107 */
108
109 template <class SplineImage,
110 class DestIterator, class DestAccessor>
111 void
112 transformToPolarCoordinatescxx . . $ vigra/transformToPolarCoordinates(a3a2ab9a5b050536).(SplineImage const & src,
113 DestIterator d_ul, DestIterator d_lr, DestAccessor d_acc)
114 {
115 typename DestIterator::difference_type d_shape = (d_lr -cxx . . $ vigra/operator-(76177e72537f9555). d_ul);
116
117 int s_w = src.width(),
118 s_h = src.height();
119
120 int s_size = mincxx . . $ vigra/min(2a338fce5842aa6a).(s_w, s_h);
121
122 int d_w = d_shape.x,
123 d_h = d_shape.y;
124
125 double r_max = s_size / 2.0;
126
127 DestIterator yd = d_ul;
128 DestIterator xd = yd;
129
130 for (int t_step = 0; t_step < d_h; t_step++,cxx . . $ `operator,`(876636f5a97307ab). yd.y++)
131 {
132 xd = yd;
133 for (int r_step = 0; r_step < d_w; r_step++,cxx . . $ `operator,`(876636f5a97307ab). xd.x++)
134 {
135 double theta = 2.0 * M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! * double(t_step) / double(d_h);
136 double r = r_max * double(r_step) / double(d_w);
137 double u = r * coscxx . . $ vigra/cos(447c67c6676f75c3).(theta) + r_max;
138 double v = r * -sincxx . . $ vigra/sin(447c67c6676f75c3).(theta) + r_max;
139
140 if ( u >= 0 && u < s_size
141 && v >= 0 && v < s_size)
142 {
143 d_acc.set(src(u, v), xd);
144 }
145 }
146 }
147 }
148
149 template <class SplineImage,
150 class DestIterator, class DestAccessor>
151 inline void
152 transformToPolarCoordinatescxx . . $ vigra/transformToPolarCoordinates(affe3d6795b68fb6).(SplineImage const & src,
153 vigracxx . . $ vigra/::triplecxx . . $ vigra/triple#<DestIterator, DestIterator, DestAccessor> dest)
154 {
155 transformToPolarCoordinatescxx . . $ vigra/transformToPolarCoordinates(affe3d6795b68fb6).(src, dest.firstcxx . . $ vigra/triple#first., dest.secondcxx . . $ vigra/triple#second., dest.thirdcxx . . $ vigra/triple#third.);
156 }
157
158 template <class SplineImage,
159 class T1, class S1>
160 void
161 transformToPolarCoordinatescxx . . $ vigra/transformToPolarCoordinates(c977fe41712123a9).(SplineImage const & src,
162 MultiArrayViewcxx . . $ vigra/MultiArrayView#<2, T1, S1> dest)
163 {
164 transformToPolarCoordinatescxx . . $ vigra/transformToPolarCoordinates(c977fe41712123a9).(src, srcImageRangecxx . . $ vigra/srcImageRange(e7ff792e09326fe4).(dest));
165 }
166
167
168
169
170 namespace detailcxx . . $ vigra/detail/
171 {
172 template <class SrcIterator, class SrcAccessor,
173 class DestIterator, class DestAccessor>
174 void
175 maximumFastNCCcxx . . $ vigra/detail/maximumFastNCC(27230ce5eea64d18).(SrcIterator s_ul, SrcIterator s_lr, SrcAccessor s_acc,
176 DestIterator d_ul, DestIterator d_lr, DestAccessor d_acc,
177 TinyVectorcxx . . $ vigra/TinyVector#<int,2> & position,
178 double & correlation_coefficent)
179 {
180 typename DestIterator::difference_type s_shape = s_lr -cxx . . $ vigra/operator-(76177e72537f9555). s_ul;
181 typename DestIterator::difference_type d_shape = d_lr -cxx . . $ vigra/operator-(76177e72537f9555). d_ul;
182
183 MultiArraycxx . . $ vigra/MultiArray#<2, float> src(s_shape.x, s_shape.y), dest(d_shape.x, d_shape.y), ncc(d_shape.x, d_shape.y);
184 BasicImageViewcxx . . $ vigra/BasicImageView#<float> src_view = makeBasicImageViewcxx . . $ vigra/makeBasicImageView(fc996bb561100fc8).(src);
185 BasicImageViewcxx . . $ vigra/BasicImageView#<float> dest_view = makeBasicImageViewcxx . . $ vigra/makeBasicImageView(fc996bb561100fc8).(dest);
186
187 copyImagecxx . . $ vigra/copyImage(ce5253e6e346ced2).(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(s_ul, s_lr, s_acc), destImagecxx . . $ vigra/destImage(72669d5dc57296dd).(src_view));
188 copyImagecxx . . $ vigra/copyImage(ce5253e6e346ced2).(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(d_ul, d_lr, d_acc), destImagecxx . . $ vigra/destImage(72669d5dc57296dd).(dest_view));
189
190 fastNormalizedCrossCorrelationcxx . . $ vigra/fastNormalizedCrossCorrelation(67077ecb319ddc0f).(dest, src, ncccxx . . $ vigra/MultiArrayView#MultiArrayView(a19856c5df46745c).);
191
192 int max_x = 0;
193 int max_y = 0;
194 float val = 0.0;
195 float max_val = -1.0;
196
197 for (int y = 0; y <cxx . . $ vigra/`operator<`(b84b089163f6fc8). ncc.heightcxx . . $ vigra/MultiArrayView#height(57a65ae535d7db84).()-cxx . . $ vigra/operator-(76177e72537f9555).s_shape.y; y++)
198 {
199 for (int x = 0; x <cxx . . $ vigra/`operator<`(b84b089163f6fc8). ncc.widthcxx . . $ vigra/MultiArrayView#width(57a65ae535d7db84).()-cxx . . $ vigra/operator-(76177e72537f9555).s_shape.x; x++)
200 {
201 val = ncc(x+cxx . . $ vigra/operator+(76177e72537f9555).s_shape.x/cxx . . $ vigra/`operator/`(6f3a3930211914e8).2, y+cxx . . $ vigra/operator+(76177e72537f9555).s_shape.y/cxx . . $ vigra/`operator/`(6f3a3930211914e8).2);
202
203 if (val > max_val)
204 {
205 max_x = x;
206 max_y = y;
207 max_val = val;
208 }
209 }
210 }
211
212 position[cxx . . $ vigra/TinyVectorBase#`operator[]`(ba6817f8939d4b6).0] = max_x;
213 position[cxx . . $ vigra/TinyVectorBase#`operator[]`(ba6817f8939d4b6).1] = max_y;
214
215 correlation_coefficent = max_val;
216 }
217
218 template <class SrcIterator, class SrcAccessor,
219 class DestIterator, class DestAccessor>
220 inline void
221 maximumFastNCCcxx . . $ vigra/detail/maximumFastNCC(6504ef7cd81f8e21).(triplecxx . . $ vigra/triple#<SrcIterator, SrcIterator, SrcAccessor> src,
222 triplecxx . . $ vigra/triple#<DestIterator, DestIterator, DestAccessor> dest,
223 TinyVectorcxx . . $ vigra/TinyVector#<int,2> & position,
224 double & correlation_coefficent)
225 {
226 maximumFastNCCcxx . . $ vigra/detail/maximumFastNCC(6504ef7cd81f8e21).(src.firstcxx . . $ vigra/triple#first., src.secondcxx . . $ vigra/triple#second., src.thirdcxx . . $ vigra/triple#third.,
227 dest.firstcxx . . $ vigra/triple#first., dest.secondcxx . . $ vigra/triple#second., dest.thirdcxx . . $ vigra/triple#third.,
228 position,
229 correlation_coefficent);
230 }
231
232 template <class SrcIterator, class SrcAccessor,
233 class DestIterator, class DestAccessor>
234 void fourierLogAbsSpectrumInPolarCoordinatescxx . . $ vigra/detail/fourierLogAbsSpectrumInPolarCoordinates(7171777f12d705bf).(SrcIterator s_ul, SrcIterator s_lr, SrcAccessor s_acc,
235 DestIterator d_ul, DestIterator d_lr, DestAccessor d_acc)
236 {
237 using namespace vigra;
238
239 typename SrcIterator::difference_type shape = s_lr -cxx . . $ vigra/operator-(76177e72537f9555). s_ul;
240
241 FFTWComplexImagecxx . . $ vigra/FFTWComplexImage# fourier(shape);
242 FImagecxx . . $ vigra/FImage# fft_mag(shape);
243
244 fourierTransformcxx . . $ vigra/fourierTransform(d7f9ca4ac247a10f).(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(s_ul, s_lr, s_acc), destImagecxx . . $ vigra/destImage(8c4c2d3abe6298e9).(fourier));
245 moveDCToCentercxx . . $ vigra/moveDCToCenter(4f71ab89f9af58a7).(srcImageRangecxx . . $ vigra/srcImageRange(64150091e7179134).(fourier, FFTWMagnitudeAccessorcxx . . $ vigra/FFTWMagnitudeAccessor#<>()), destImagecxx . . $ std/pair#pair(59816e23a2f1b31c).(fft_mag));
246
247 vigracxx . . $ vigra/::SplineImageViewcxx . . $ vigra/SplineImageView#<2, double> splcxx . . $ vigra/SplineImageView#SplineImageView(f12b8ccfa25d7d29).(srcImageRangecxx . . $ vigra/srcImageRange(7c331c9245579717).(fft_mag));
248
249 transformToPolarCoordinatescxx . . $ vigra/transformToPolarCoordinates(c977fe41712123a9).(spl,
250 destIterRangecxx . . $ vigra/destIterRange(2ceebe6e6c1351bc).(d_ul, d_lr, d_acc));
251
252 transformImagecxx . . $ vigra/transformImage(f174c640fa59bdbf).(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(d_ul,d_lr,d_acc), destItercxx . . $ vigra/destIter(1f630c50eae6282).(d_ul,d_acc), logcxx . . $ vigra/functor/log(57ac05b5f67cf0c).(abscxx . . $ vigra/functor/abs(a5b6a85cdf45cc95).(functorcxx . . $ vigra/functor/::Arg1cxx . . $ vigra/functor/Arg1(a4da62cfef49877).())));
253 }
254
255 template <class SrcIterator, class SrcAccessor,
256 class DestIterator, class DestAccessor>
257 void fourierLogAbsSpectrumInPolarCoordinatescxx . . $ vigra/detail/fourierLogAbsSpectrumInPolarCoordinates(f7ca511b53912c2e).(triplecxx . . $ vigra/triple#<SrcIterator, SrcIterator, SrcAccessor> src,
258 triplecxx . . $ vigra/triple#<DestIterator, DestIterator, DestAccessor> dest)
259 {
260 fourierLogAbsSpectrumInPolarCoordinatescxx . . $ vigra/detail/fourierLogAbsSpectrumInPolarCoordinates(f7ca511b53912c2e).(src.firstcxx . . $ vigra/triple#first., src.secondcxx . . $ vigra/triple#second., src.thirdcxx . . $ vigra/triple#third., dest.firstcxx . . $ vigra/triple#first., dest.secondcxx . . $ vigra/triple#second., dest.thirdcxx . . $ vigra/triple#third.);
261 }
262 } //namespace detail
263
264
265
266
267 /********************************************************/
268 /* */
269 /* estimateGlobalRotation */
270 /* */
271 /********************************************************/
272
273 /** \brief Estimate the rotation between two images by means of a normalized cross correlation matching of the FFT spectra.
274
275 This algorithm uses the fast normalized cross correlation to determine a global rotation
276 between two images (from image2 to image1). To derive the rotation, the algorithm performs the following steps:
277 <ol>
278 <li>Transforming both images to the frequency domain using FFTW</li>
279 <li>Create LogAbs PolarCoordinate representations for each spectrum.</li>
280 <li>Determining the final Rotation by performing a fast normalized cross correlation
281 based on the polar representations.</li>
282 </ol>
283 The images are cropped to the corresponding images center-squared before the estimation
284 takes place.
285
286 <b> Declarations:</b>
287
288 <b>\#include</b> \<vigra/affine_registration_fft.hxx\><br>
289 Namespace: vigra
290
291 pass 2D array views:
292 \code
293 namespace vigra {
294 template <class T1, class S1,
295 class T2, class S2>
296 void
297 estimateGlobalRotation(MultiArrayView<2, T1, S1> const & src,
298 MultiArrayView<2, T2, S2> dest,
299 Matrix<double> & affineMatrix,
300 double & correlation_coefficent);
301 }
302 \endcode
303
304 \deprecatedAPI{estimateGlobalRotation}
305 pass \ref ImageIterators and \ref DataAccessors :
306 \code
307 namespace vigra {
308 template <class SrcIterator, class SrcAccessor,
309 class DestIterator, class DestAccessor>
310 void
311 estimateGlobalRotation(SrcIterator sul, SrcIterator slr, SrcAccessor src,
312 DestIterator dul, DestIterator dlr, DestAccessor dest,
313 Matrix<double> & affineMatrix,
314 double & correlation_coefficent)
315 }
316 \endcode
317 use argument objects in conjunction with \ref ArgumentObjectFactories :
318 \code
319 namespace vigra {
320 template <class SrcIterator, class SrcAccessor,
321 class DestIterator, class DestAccessor>
322 void
323 estimateGlobalRotation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
324 triple<DestIterator, DestIterator, DestAccessor> dest,
325 Matrix<double> & affineMatrix,
326 double & correlation_coefficent)
327 }
328 \endcode
329 \deprecatedEnd
330 */
331 doxygen_overloaded_functioncxx . . $ `include/vigra/config.hxx:329:11`!(template <...> void estimateGlobalRotation)
332
333 template <class SrcIterator, class SrcAccessor,
334 class DestIterator, class DestAccessor>
335 void
336 estimateGlobalRotationcxx . . $ vigra/estimateGlobalRotation(e81aebca5c544cd).(SrcIterator s_ul, SrcIterator s_lr, SrcAccessor s_acc,
337 DestIterator d_ul, DestIterator d_lr, DestAccessor d_acc,
338 Matrixcxx . . $ vigra/Matrix#<double> & affineMatrix,
339 double & correlation_coefficient)
340 {
341 //determine squared centers of both images without consuming any additional memory!
342 typename SrcIterator::difference_type s_shape = s_lr -cxx . . $ vigra/operator-(76177e72537f9555). s_ul;
343 Diff2Dcxx . . $ vigra/Diff2D# s2_shape(mincxx . . $ vigra/min(2a338fce5842aa6a).(s_shape.x, s_shape.y),mincxx . . $ vigra/min(2a338fce5842aa6a).(s_shape.x, s_shape.y));
344 Diff2Dcxx . . $ vigra/Diff2D# s2_offset = (s_shape-cxx . . $ vigra/operator-(76177e72537f9555).s2_shape)/cxx . . $ vigra/`operator/`(6f3a3930211914e8).2;
345
346 typename DestIterator::difference_type d_shape = d_lr -cxx . . $ vigra/operator-(76177e72537f9555). d_ul;
347 Diff2Dcxx . . $ vigra/Diff2D# d2_shape(mincxx . . $ vigra/min(2a338fce5842aa6a).(d_shape.x, d_shape.y),mincxx . . $ vigra/min(2a338fce5842aa6a).(d_shape.x, d_shape.y));
348 Diff2Dcxx . . $ vigra/Diff2D# d2_offset = (d_shape-cxx . . $ vigra/operator-(76177e72537f9555).d2_shape)/cxx . . $ vigra/`operator/`(6f3a3930211914e8).2;
349
350 //Determine Shape for united polar coordinate representation
351 Diff2Dcxx . . $ vigra/Diff2D# mean_shape = (s_shape +cxx . . $ vigra/operator+(76177e72537f9555). d_shape)/cxx . . $ vigra/`operator/`(6f3a3930211914e8).2;
352
353 int size = mincxx . . $ vigra/min(2a338fce5842aa6a).(mean_shape.xcxx . . $ vigra/Diff2D#x., mean_shape.ycxx . . $ vigra/Diff2D#y.);
354 if(size %2 == 0)
355 size++;
356
357 const int pc_w = size,
358 pc_h = size*6+1;
359
360
361 DImagecxx . . $ vigra/DImage# s_polCoordscxx . . $ vigra/BasicImage#BasicImage(61295470e0adf2c1).(pc_w, pc_h/2),
362 d_polCoordscxx . . $ vigra/BasicImage#BasicImage(61295470e0adf2c1).(pc_w, pc_h),
363 ncccxx . . $ vigra/BasicImage#BasicImage(61295470e0adf2c1).(pc_w, pc_h);
364
365 detailcxx . . $ vigra/detail/::fourierLogAbsSpectrumInPolarCoordinatescxx . . $ vigra/detail/fourierLogAbsSpectrumInPolarCoordinates(7171777f12d705bf).(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(s_ul+cxx . . $ vigra/operator+(76177e72537f9555).s2_offset, s_ul+cxx . . $ vigra/operator+(76177e72537f9555).s2_offset+cxx . . $ vigra/operator+(76177e72537f9555).s2_shape, s_acc),
366 destImageRangecxx . . $ vigra/destImageRange(e944f295d54d356e).(d_polCoords));
367 copyImagecxx . . $ vigra/copyImage(4f71ab89f9af58a7).(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(d_polCoords.upperLeftcxx . . $ vigra/BasicImage#upperLeft(2a4eb6086e810ac5).(), d_polCoords.upperLeftcxx . . $ vigra/BasicImage#upperLeft(2a4eb6086e810ac5).() +cxx . . $ vigra/BasicImageIteratorBase#operator+(2de694e33484d87a). vigracxx . . $ vigra/Diff2D#Diff2D(3e454b8ccf442868).::Diff2Dcxx . . $ vigra/Diff2D#(pc_w, pc_h/2), d_polCoords.accessorcxx . . $ vigra/BasicImage#accessor(7a7dcb109ee72464).()),
368 destImagecxx . . $ std/pair#pair(59816e23a2f1b31c).(s_polCoords));
369
370 detailcxx . . $ vigra/detail/::fourierLogAbsSpectrumInPolarCoordinatescxx . . $ vigra/detail/fourierLogAbsSpectrumInPolarCoordinates(7171777f12d705bf).(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(d_ul+cxx . . $ vigra/operator+(76177e72537f9555).d2_offset, d_ul+cxx . . $ vigra/operator+(76177e72537f9555).d2_offset+cxx . . $ vigra/operator+(76177e72537f9555).d2_shape, d_acc),
371 destImageRangecxx . . $ vigra/destImageRange(e944f295d54d356e).(d_polCoords));
372
373 //Basic Cross correlation is assumed to be faster here, as there are only pc_h comparisons possible...
374 normalizedCrossCorrelationcxx . . $ vigra/normalizedCrossCorrelation(65bb180db66f1578).(srcImageRangecxx . . $ vigra/srcImageRange(7c331c9245579717).(d_polCoords), srcImageRangecxx . . $ vigra/srcImageRange(7c331c9245579717).(s_polCoords), destImagecxx . . $ std/pair#pair(59816e23a2f1b31c).(ncc));
375
376 int max_idx = 0;
377 double max_val = -1;
378
379 const int x=pc_w/2;
380 double val;
381
382 //Only look at a stripe for the maximum angle of rotation
383 //at the image center, at find the best fitting angle...
384 for (int y=0; y<pc_h/2; y++)
385 {
386 val = ncc(cxx . . $ vigra/BasicImage#`operator()`(dec216c5a8c06a71).x,y+pc_h/4);
387
388 if (val > max_val)
389 {
390 max_idx = y;
391 max_val = val;
392 }
393 }
394
395 double theta = double(max_idx) / pc_h * 360.0;
396
397 affineMatrix =cxx . . $ vigra/linalg/Matrix#`operator=`(9647555ab509ab98). rotationMatrix2DDegreescxx . . $ vigra/rotationMatrix2DDegrees(6d9891191503e01b).(theta, vigracxx . . $ vigra/::TinyVectorcxx . . $ vigra/TinyVector#<double,2>(s_shape.x/cxx . . $ vigra/`operator/`(6f3a3930211914e8).2.0, s_shape.y/cxx . . $ vigra/`operator/`(6f3a3930211914e8).2.0));
398 correlation_coefficient = max_val;
399 }
400
401 template <class SrcIterator, class SrcAccessor,
402 class DestIterator, class DestAccessor>
403 inline void
404 estimateGlobalRotationcxx . . $ vigra/estimateGlobalRotation(4613a861c5939dd0).(triplecxx . . $ vigra/triple#<SrcIterator, SrcIterator, SrcAccessor> src,
405 triplecxx . . $ vigra/triple#<DestIterator, DestIterator, DestAccessor> dest,
406 Matrixcxx . . $ vigra/Matrix#<double> & affineMatrix,
407 double & correlation_coefficient)
408 {
409 estimateGlobalRotationcxx . . $ vigra/estimateGlobalRotation(4613a861c5939dd0).(src.firstcxx . . $ vigra/triple#first., src.secondcxx . . $ vigra/triple#second., src.thirdcxx . . $ vigra/triple#third.,
410 dest.firstcxx . . $ vigra/triple#first., dest.secondcxx . . $ vigra/triple#second., dest.thirdcxx . . $ vigra/triple#third.,
411 affineMatrix,
412 correlation_coefficient);
413 }
414
415 template <class T1, class S1,
416 class T2, class S2>
417 inline void
418 estimateGlobalRotationcxx . . $ vigra/estimateGlobalRotation(5ddbefaee6c4b28d).(MultiArrayViewcxx . . $ vigra/MultiArrayView#<2, T1, S1> const & src,
419 MultiArrayViewcxx . . $ vigra/MultiArrayView#<2, T2, S2> dest,
420 Matrixcxx . . $ vigra/Matrix#<double> & affineMatrix,
421 double & correlation_coefficent)
422 {
423 estimateGlobalRotationcxx . . $ vigra/estimateGlobalRotation(5ddbefaee6c4b28d).(srcImageRangecxx . . $ vigra/srcImageRange(e7ff792e09326fe4).(src),
424 destImageRangecxx . . $ vigra/destImageRange(246099ca35085b7).(dest),
425 affineMatrix,
426 correlation_coefficent);
427 }
428
429 /********************************************************/
430 /* */
431 /* estimateGlobalTranslation */
432 /* */
433 /********************************************************/
434
435 /** \brief Estimate the translation between two images by means of a normalized cross correlation matching.
436
437 This algorithm uses the fast normalized cross correlation to determine a global translation
438 between two images (from image2 to image1). To derive the translation, the algorithm consists of differents steps:
439 <ol>
440 <li>Separation of the second image<br/>
441 The second image (the one, for which the translation shall be determined) is cut into five
442 subregions: UpperLeft, UpperRight, Center, LowerLeft and LowerRight, each of 1/4 the size of
443 the original image. Using a border > 0 results in (all) overlapping regions.</li>
444 <li>Cross-Correlation of the subimages to the first image<br/>
445 The subimages are normalized cross-correlated to the (complete) first image.
446 The resulting maximum-likelihood translations and the correlation coefficients are stored for the next step.</li>
447 <li>Determining the final Translation by voting<br/>
448 Each correlation vector gets one vote at the beginning. For each equality of derived motion vectors,
449 the voting to these vectors is incremented. If the maximum number of votes is larger than 1, the vector with the
450 most votes is chosen. If the maximum number of votes is 1, the vector with the maximum likelihood is choosen.</li>
451 </ol>
452 <b> Declarations:</b>
453
454 <b>\#include</b> \<vigra/affine_registration_fft.hxx\><br>
455 Namespace: vigra
456
457 pass 2D array views:
458 \code
459 namespace vigra {
460 template <class T1, class S1,
461 class T2, class S2>
462 void
463 estimateGlobalTranslation(MultiArrayView<2, T1, S1> const & src,
464 MultiArrayView<2, T2, S2> dest,
465 Matrix<double> & affineMatrix,
466 double & correlation_coefficent,
467 Diff2D border = Diff2D(0,0));
468 }
469 \endcode
470
471 \deprecatedAPI{estimateGlobalTranslation}
472 pass \ref ImageIterators and \ref DataAccessors :
473 \code
474 namespace vigra {
475 template <class SrcIterator, class SrcAccessor,
476 class DestIterator, class DestAccessor>
477 void
478 estimateGlobalTranslation(SrcIterator sul, SrcIterator slr, SrcAccessor src,
479 DestIterator dul, DestIterator dlr, DestAccessor dest,
480 Matrix<double> & affineMatrix,
481 double & correlation_coefficent,
482 Diff2D border = Diff2D(0,0))
483 }
484 \endcode
485 use argument objects in conjunction with \ref ArgumentObjectFactories :
486 \code
487 namespace vigra {
488 template <class SrcIterator, class SrcAccessor,
489 class DestIterator, class DestAccessor>
490 void
491 estimateGlobalTranslation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
492 triple<DestIterator, DestIterator, DestAccessor> dest,
493 Matrix<double> & affineMatrix,
494 double & correlation_coefficent,
495 Diff2D border = Diff2D(0,0))
496 }
497 \endcode
498 \deprecatedEnd
499 */
500 doxygen_overloaded_functioncxx . . $ `include/vigra/config.hxx:329:11`!(template <...> void estimateGlobalTranslation)
501
502 template <class SrcIterator, class SrcAccessor,
503 class DestIterator, class DestAccessor>
504 void estimateGlobalTranslationcxx . . $ vigra/estimateGlobalTranslation(feca9508e842bc12).(SrcIterator s_ul, SrcIterator s_lr, SrcAccessor s_acc,
505 DestIterator d_ul, DestIterator d_lr, DestAccessor d_acc,
506 Matrixcxx . . $ vigra/Matrix#<double> & affine_matrix,
507 double & correlation_coefficent,
508 Diff2Dcxx . . $ vigra/Diff2D# border =cxx . . $ vigra/Diff2D#Diff2D(5951b0e1e3ce1dea). Diff2Dcxx . . $ vigra/Diff2D#Diff2D(3e454b8ccf442868).(0,0))
509 {
510 ignore_argumentcxx . . $ vigra/ignore_argument(77d9f17553126ecb).(d_lr);
511 typename SrcIterator::difference_type s_shape = s_lr -cxx . . $ vigra/operator-(76177e72537f9555). s_ul;
512
513 //determine matrix by using 5 quater-matches and a maximum likelihood decision:
514 Diff2Dcxx . . $ vigra/Diff2D# q_shape = (s_shape -cxx . . $ vigra/operator-(76177e72537f9555). border -cxx . . $ vigra/operator-(76177e72537f9555). border)/cxx . . $ vigra/`operator/`(6f3a3930211914e8).2;
515 if (q_shape.xcxx . . $ vigra/Diff2D#x. % 2 == 0) q_shape.xcxx . . $ vigra/Diff2D#x.--;
516 if (q_shape.ycxx . . $ vigra/Diff2D#y. % 2 == 0) q_shape.ycxx . . $ vigra/Diff2D#y.--;
517
518 Diff2Dcxx . . $ vigra/Diff2D# q_offsetscxx . . $ vigra/Diff2D#Diff2D(49f6e7a06ebc5aa8).[5];
519 q_offsets[0] =cxx . . $ vigra/Diff2D#`operator=`(8037e08fc8c20dcd). border;
520 q_offsets[1] =cxx . . $ vigra/Diff2D#`operator=`(8037e08fc8c20dcd). Diff2Dcxx . . $ vigra/Diff2D#(s_shape.x, 0)/cxx . . $ vigra/Diff2D#`operator/`(c079ed1fb81b47aa).2 +cxx . . $ vigra/operator+(76177e72537f9555). border;
521 q_offsets[2] = s_shape/cxx . . $ vigra/`operator/`(6f3a3930211914e8).4;
522 q_offsets[3] =cxx . . $ vigra/Diff2D#`operator=`(8037e08fc8c20dcd). Diff2Dcxx . . $ vigra/Diff2D#(0, s_shape.y)/cxx . . $ vigra/Diff2D#`operator/`(c079ed1fb81b47aa).2 +cxx . . $ vigra/operator+(76177e72537f9555). border;
523 q_offsets[4] = s_shape/cxx . . $ vigra/`operator/`(6f3a3930211914e8).2 +cxx . . $ vigra/operator+(76177e72537f9555). border;
524
525 TinyVectorcxx . . $ vigra/TinyVector#<int,2> translation_vectorscxx . . $ vigra/TinyVector#TinyVector(49f6e7a06ebc5aa8).[5];
526 double translation_correlations[5] = {0.0,0.0,0.0,0.0,0.0};
527 int translation_votes[5] = {1,1,1,1,1};
528
529 int max_corr_idx=0;
530
531 for (int q=0; q!=5; q++)
532 {
533 Diff2Dcxx . . $ vigra/Diff2D# offset = q_offsetscxx . . $ vigra/Diff2D#Diff2D(5951b0e1e3ce1dea).[q];
534
535 //we are searching a transformation from img2 -> transformed image1, thus we switch dest and tmp
536 detailcxx . . $ vigra/detail/::maximumFastNCCcxx . . $ vigra/detail/maximumFastNCC(27230ce5eea64d18).(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(d_ul+cxx . . $ vigra/operator+(76177e72537f9555).offset, d_ul+cxx . . $ vigra/operator+(76177e72537f9555).offset+cxx . . $ vigra/operator+(76177e72537f9555).q_shape, d_acc),
537 srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(s_ul, s_lr, s_acc),
538 translation_vectors[q],
539 translation_correlations[q]);
540
541 translation_vectors[q] =cxx . . $ vigra/TinyVector#`operator=`(6dda69335b07f604). translation_vectors[q] -cxx . . $ vigra/operator-(73b4c9a10badb89d). TinyVectorcxx . . $ vigra/TinyVector#<int,2>(offset);
542
543 if(translation_correlations[q] > translation_correlations[max_corr_idx])
544 {
545 max_corr_idx=q;
546 }
547
548 for (int q_old=0; q_old!=q; q_old++)
549 {
550 if (translation_vectors[q] ==cxx . . $ vigra/`operator==`(b84b089163f6fc8). translation_vectors[q_old])
551 {
552 translation_votes[q_old]++;
553 }
554 }
555 }
556
557 int max_votes_idx=0;
558
559 for (int q=0; q!=5; q++)
560 {
561 if(translation_votes[q] > translation_votes[max_votes_idx])
562 {
563 max_votes_idx=q;
564 }
565 }
566
567 int best_idx=0;
568 if(translation_votes[max_votes_idx] > 1)
569 {
570 best_idx = max_votes_idx;
571 }
572 else
573 {
574 best_idx = max_corr_idx;
575 }
576
577 affine_matrix =cxx . . $ vigra/linalg/Matrix#`operator=`(9647555ab509ab98). translationMatrix2Dcxx . . $ vigra/translationMatrix2D(740607c4e261b1c6).(translation_vectorscxx . . $ vigra/TinyVector#TinyVector(21c6c52cd454bffe).[best_idx]);
578 correlation_coefficent = translation_correlations[best_idx];
579 }
580
581 template <class SrcIterator, class SrcAccessor,
582 class DestIterator, class DestAccessor>
583 inline void
584 estimateGlobalTranslationcxx . . $ vigra/estimateGlobalTranslation(e0772058c20c6b7e).(triplecxx . . $ vigra/triple#<SrcIterator, SrcIterator, SrcAccessor> src,
585 triplecxx . . $ vigra/triple#<DestIterator, DestIterator, DestAccessor> dest,
586 Matrixcxx . . $ vigra/Matrix#<double> & affineMatrix,
587 double & correlation_coefficent,
588 Diff2Dcxx . . $ vigra/Diff2D# border =cxx . . $ vigra/Diff2D#Diff2D(5951b0e1e3ce1dea). Diff2Dcxx . . $ vigra/Diff2D#Diff2D(3e454b8ccf442868).(0,0))
589 {
590 estimateGlobalTranslationcxx . . $ vigra/estimateGlobalTranslation(e0772058c20c6b7e).(src.firstcxx . . $ vigra/triple#first., src.secondcxx . . $ vigra/triple#second., src.thirdcxx . . $ vigra/triple#third.,
591 dest.firstcxx . . $ vigra/triple#first., dest.secondcxx . . $ vigra/triple#second., dest.thirdcxx . . $ vigra/triple#third.,
592 affineMatrix,
593 correlation_coefficent,
594 border);
595 }
596
597 template <class T1, class S1,
598 class T2, class S2>
599 inline void
600 estimateGlobalTranslationcxx . . $ vigra/estimateGlobalTranslation(e87dd6974407eecd).(MultiArrayViewcxx . . $ vigra/MultiArrayView#<2, T1, S1> const & src,
601 MultiArrayViewcxx . . $ vigra/MultiArrayView#<2, T2, S2> dest,
602 Matrixcxx . . $ vigra/Matrix#<double> & affineMatrix,
603 double & correlation_coefficent,
604 Diff2Dcxx . . $ vigra/Diff2D# border =cxx . . $ vigra/Diff2D#Diff2D(5951b0e1e3ce1dea). Diff2Dcxx . . $ vigra/Diff2D#Diff2D(3e454b8ccf442868).(0,0))
605 {
606 estimateGlobalTranslationcxx . . $ vigra/estimateGlobalTranslation(e87dd6974407eecd).(srcImageRangecxx . . $ vigra/srcImageRange(e7ff792e09326fe4).(src),
607 destImageRangecxx . . $ vigra/destImageRange(246099ca35085b7).(dest),
608 affineMatrix,
609 correlation_coefficent,
610 border);
611 }
612
613 /********************************************************/
614 /* */
615 /* estimateGlobalRotationTranslation */
616 /* */
617 /********************************************************/
618
619 /** \brief Estimate the (global) rotation and translation between two images by means a normalized cross correlation matching.
620
621 This algorithm use the functions \ref estimateGlobalRotation() and
622 \ref estimateGlobalTranslation() to estimate a matrix which describes
623 the global rotation and translation from the second to the first image.
624
625 <b> Declarations:</b>
626
627 <b>\#include</b> \<vigra/affine_registration_fft.hxx\><br>
628 Namespace: vigra
629
630 pass 2D array views:
631 \code
632 namespace vigra {
633 template <class T1, class S1,
634 class T2, class S2>
635 void
636 estimateGlobalRotationTranslation(MultiArrayView<2, T1, S1> const & src,
637 MultiArrayView<2, T2, S2> dest,
638 Matrix<double> & affineMatrix,
639 double & rotation_correlation,
640 double & translation_correlation,
641 Diff2D border = Diff2D(0,0));
642 }
643 \endcode
644
645 \deprecatedAPI{estimateGlobalRotationTranslation}
646 pass \ref ImageIterators and \ref DataAccessors :
647 \code
648 namespace vigra {
649 template <class SrcIterator, class SrcAccessor,
650 class DestIterator, class DestAccessor>
651 void
652 estimateGlobalRotationTranslation(SrcIterator sul, SrcIterator slr, SrcAccessor src,
653 DestIterator dul, DestIterator dlr, DestAccessor dest,
654 Matrix<double> & affineMatrix,
655 double & rotation_correlation,
656 double & translation_correlation,
657 Diff2D border = Diff2D(0,0))
658 }
659 \endcode
660 use argument objects in conjunction with \ref ArgumentObjectFactories :
661 \code
662 namespace vigra {
663 template <class SrcIterator, class SrcAccessor,
664 class DestIterator, class DestAccessor>
665 void
666 estimateGlobalRotationTranslation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
667 triple<DestIterator, DestIterator, DestAccessor> dest,
668 Matrix<double> & affineMatrix,
669 double & rotation_correlation,
670 double & translation_correlation,
671 Diff2D border = Diff2D(0,0))
672 }
673 \endcode
674 \deprecatedEnd
675 */
676 doxygen_overloaded_functioncxx . . $ `include/vigra/config.hxx:329:11`!(template <...> void estimateGlobalRotationTranslation)
677 template <class SrcIterator, class SrcAccessor,
678 class DestIterator, class DestAccessor>
679 void
680 estimateGlobalRotationTranslationcxx . . $ vigra/estimateGlobalRotationTranslation(6acbaa5be0ec3b15).(SrcIterator s_ul, SrcIterator s_lr, SrcAccessor s_acc,
681 DestIterator d_ul, DestIterator d_lr, DestAccessor d_acc,
682 Matrixcxx . . $ vigra/Matrix#<double> & affineMatrix,
683 double & rotation_correlation,
684 double & translation_correlation,
685 Diff2Dcxx . . $ vigra/Diff2D# border =cxx . . $ vigra/Diff2D#Diff2D(5951b0e1e3ce1dea). Diff2Dcxx . . $ vigra/Diff2D#Diff2D(3e454b8ccf442868).(0,0))
686 {
687 typename DestIterator::difference_type d_shape = d_lr -cxx . . $ vigra/operator-(76177e72537f9555). d_ul;
688
689 //First step: Estimate rotation from img2 -> img1.
690 Matrixcxx . . $ vigra/Matrix#<double> rotation_matrixcxx . . $ vigra/linalg/Matrix#Matrix(49f6e7a06ebc5aa8).;
691 estimateGlobalRotationcxx . . $ vigra/estimateGlobalRotation(5ddbefaee6c4b28d).(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(s_ul+cxx . . $ vigra/operator+(76177e72537f9555).border, s_lr-cxx . . $ vigra/operator-(76177e72537f9555).border, s_acc),
692 srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(d_ul+cxx . . $ vigra/operator+(76177e72537f9555).border, d_lr-cxx . . $ vigra/operator-(76177e72537f9555).border, d_acc),
693 rotation_matrix,
694 rotation_correlation);
695
696 //Second step: correct image according to the estimated rotation:
697 FImagecxx . . $ vigra/FImage# tmp(d_shape);
698 SplineImageViewcxx . . $ vigra/SplineImageView#<3, double> spl(srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(s_ul, s_lr, s_acc));
699 affineWarpImagecxx . . $ vigra/affineWarpImage(cda1768bb3cc7185).(spl, destImageRangecxx . . $ vigra/destImageRange(e944f295d54d356e).(tmp), rotation_matrix);
700
701 //Third step: find rotation between temp image (of step 2) and dest:
702 Matrixcxx . . $ vigra/Matrix#<double> translation_matrixcxx . . $ vigra/linalg/Matrix#Matrix(49f6e7a06ebc5aa8).;
703 estimateGlobalTranslationcxx . . $ vigra/estimateGlobalTranslation(e87dd6974407eecd).(srcImageRangecxx . . $ vigra/srcImageRange(7c331c9245579717).(tmp),
704 srcIterRangecxx . . $ vigra/srcIterRange(2ceebe6e6c1351bc).(d_ul, d_lr, d_acc),
705 translation_matrix,
706 translation_correlation,
707 border);
708
709 affineMatrix =cxx . . $ vigra/linalg/Matrix#`operator=`(9647555ab509ab98). rotation_matrix *cxx . . $ vigra/linalg/`operator*`(2462aae653b81c01). translation_matrix;
710 }
711
712 template <class SrcIterator, class SrcAccessor,
713 class DestIterator, class DestAccessor>
714 inline void
715 estimateGlobalRotationTranslationcxx . . $ vigra/estimateGlobalRotationTranslation(1a4b2cd8e6e18e82).(triplecxx . . $ vigra/triple#<SrcIterator, SrcIterator, SrcAccessor> src,
716 triplecxx . . $ vigra/triple#<DestIterator, DestIterator, DestAccessor> dest,
717 Matrixcxx . . $ vigra/Matrix#<double> & affineMatrix,
718 double & rotation_correlation,
719 double & translation_correlation,
720 Diff2Dcxx . . $ vigra/Diff2D# border =cxx . . $ vigra/Diff2D#Diff2D(5951b0e1e3ce1dea). Diff2Dcxx . . $ vigra/Diff2D#Diff2D(3e454b8ccf442868).(0,0))
721 {
722 estimateGlobalRotationTranslationcxx . . $ vigra/estimateGlobalRotationTranslation(1a4b2cd8e6e18e82).(src.firstcxx . . $ vigra/triple#first., src.secondcxx . . $ vigra/triple#second., src.thirdcxx . . $ vigra/triple#third.,
723 dest.firstcxx . . $ vigra/triple#first., dest.secondcxx . . $ vigra/triple#second., dest.thirdcxx . . $ vigra/triple#third.,
724 affineMatrix,
725 rotation_correlation,
726 translation_correlation,
727 border);
728 }
729
730 template <class T1, class S1,
731 class T2, class S2>
732 inline void
733 estimateGlobalRotationTranslationcxx . . $ vigra/estimateGlobalRotationTranslation(1e4bd970a90b029f).(MultiArrayViewcxx . . $ vigra/MultiArrayView#<2, T1, S1> const & src,
734 MultiArrayViewcxx . . $ vigra/MultiArrayView#<2, T2, S2> dest,
735 Matrixcxx . . $ vigra/Matrix#<double> & affineMatrix,
736 double & rotation_correlation,
737 double & translation_correlation,
738 Diff2Dcxx . . $ vigra/Diff2D# border =cxx . . $ vigra/Diff2D#Diff2D(5951b0e1e3ce1dea). Diff2Dcxx . . $ vigra/Diff2D#Diff2D(3e454b8ccf442868).(0,0))
739 {
740 estimateGlobalRotationTranslationcxx . . $ vigra/estimateGlobalRotationTranslation(1e4bd970a90b029f).(srcImageRangecxx . . $ vigra/srcImageRange(e7ff792e09326fe4).(src),
741 destImageRangecxx . . $ vigra/destImageRange(246099ca35085b7).(dest),
742 affineMatrix,
743 rotation_correlation,
744 translation_correlation,
745 border);
746 }
747
748 //@}
749
750 } // namespace vigra
751
752
753 #endif /* VIGRA_AFFINE_REGISTRATION_FFT_HXX */