This file is indexed.

/usr/include/vigra/correlation.hxx is in libvigraimpex-dev 1.10.0+git20160211.167be93+dfsg-2+b5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
/************************************************************************/
/*                                                                      */
/*               Copyright 2007-2014 by Benjamin Seppke                 */
/*                                                                      */
/*    This file is part of the VIGRA computer vision library.           */
/*    The VIGRA Website is                                              */
/*        http://hci.iwr.uni-heidelberg.de/vigra/                       */
/*    Please direct questions, bug reports, and contributions to        */
/*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
/*        vigra@informatik.uni-hamburg.de                               */
/*                                                                      */
/*    Permission is hereby granted, free of charge, to any person       */
/*    obtaining a copy of this software and associated documentation    */
/*    files (the "Software"), to deal in the Software without           */
/*    restriction, including without limitation the rights to use,      */
/*    copy, modify, merge, publish, distribute, sublicense, and/or      */
/*    sell copies of the Software, and to permit persons to whom the    */
/*    Software is furnished to do so, subject to the following          */
/*    conditions:                                                       */
/*                                                                      */
/*    The above copyright notice and this permission notice shall be    */
/*    included in all copies or substantial portions of the             */
/*    Software.                                                         */
/*                                                                      */
/*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
/*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
/*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
/*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
/*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
/*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
/*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
/*    OTHER DEALINGS IN THE SOFTWARE.                                   */
/*                                                                      */
/************************************************************************/

#ifndef VIGRA_CORRELATION_HXX
#define VIGRA_CORRELATION_HXX

#include "stdimage.hxx"
#include "inspectimage.hxx"
#include "functorexpression.hxx"
#include "multi_math.hxx"
#include "multi_fft.hxx"
#include "integral_image.hxx"

// "slow" correlation algorithms are performed using the windowing filter env.
#include "applywindowfunction.hxx"

namespace vigra
{

/** \addtogroup Correlation Image Correlation

    Fast (FFT-based) and slow algorithms to estimate the correlation between images.
*/
//@{

/********************************************************/
/*                                                      */
/*    Fast cross correlation of an image w.r.t a mask   */
/*                                                      */
/********************************************************/

/** \brief This function performes a fast cross-correlation

 This function performes a fast cross-correlation using the Fast Fourier Transform and
 the dependency of the convolution and the correlation in Fourier space.

 The input pixel type <tt>T1</tt> must be a \ref LinearSpace "linear space" over
 the window functions' value_type <tt>T</tt>, i.e. addition of source values, multiplication with functions' values,
 and NumericTraits must be defined. The mask's value_type must be an \ref AlgebraicField "algebraic field",
 i.e. the arithmetic operations (+, -, *, /) and NumericTraits must be defined.

 By default, the borders are filled with zeros. Use the clearBorders switch to change that behavior if you need to.

 <b> Declarations:</b>

 pass 2D array views:
 \code
 namespace vigra {
   template <class T1, class S1,
            class T2, class S2,
            class T3, class S3,
            unsigned int N>
   void
   fastCrossCorrelation(MultiArrayView<N, T1, S1> const & in,
                        MultiArrayView<N, T2, S2> const & mask,
                        MultiArrayView<N, T3, S3> out,
                        bool clearBorders=true);

 }
 \endcode


 <b> Usage:</b>

 <b>\#include</b> \<vigra/correlation.hxx\><br/>
 Namespace: vigra

 \code
 unsigned int m_w=51, m_h=51;
 unsigned int w=1000, h=1000;
 MultiArray<2, float> mask(m_w,m_h), src(w,h), dest(w,h);
 ...

 //compute fast cross correlation of mask and image -> dest
 fastCrossCorrelation(mask, src, dest);
 \endcode

 <b> Preconditions:</b>

 The image must be larger than the size of the mask.
 */
doxygen_overloaded_function(template <...> void fastCrossCorrelation)

template <class T1, class S1,
class T2, class S2,
class T3, class S3,
unsigned int N>
inline void fastCrossCorrelation(MultiArrayView<N, T1, S1> const & in,
                                 MultiArrayView<N, T2, S2> const & mask,
                                 MultiArrayView<N, T3, S3> out,
                                 bool clearBorders=true)
{
    vigra_precondition(in.shape() == out.shape(),
                       "vigra::fastCrossCorrelation(): shape mismatch between input and output.");
    correlateFFT(in, mask, out);

    if(clearBorders)
    {
        typedef typename MultiArrayShape<N>::type Shape;
        Shape maskRadius(floor(mask.shape()/2));
        initMultiArrayBorder(out, maskRadius, maskRadius, T3());
    }
}

namespace detail {

template<class T1, class S1>
inline double integralMultiArrayWindowMean(MultiArrayView<1, T1, S1> const & in,
                                           typename MultiArrayView<1, T1, S1>::difference_type const & left,
                                           typename MultiArrayView<1, T1, S1>::difference_type const & right)
{
    return in[right]-in[left];
}

template<class T1, class S1>
inline double integralMultiArrayWindowMean(MultiArrayView<2, T1, S1> const & in,
                                           typename MultiArrayView<2, T1, S1>::difference_type const & ul,
                                           typename MultiArrayView<2, T1, S1>::difference_type const & lr)
{
    return in[lr] - in(lr[0],ul[1]) - in(ul[0],lr[1]) + in[ul];
}

template<class T1, class S1>
inline double integralMultiArrayWindowMean(MultiArrayView<3, T1, S1> const & in,
                                           typename MultiArrayView<3, T1, S1>::difference_type const & ul,
                                           typename MultiArrayView<3, T1, S1>::difference_type const & lr)
{
    return (in[lr] - in(lr[0],ul[1],lr[2]) - in(ul[0],lr[1],lr[2]) + in(ul[0],ul[1],lr[2]))
         - (in(lr[0],lr[1],ul[2]) - in(lr[0],ul[1],ul[2]) - in(ul[0],lr[1],ul[2]) + in[ul]);
}

} // namespace detail

/********************************************************/
/*                                                      */
/*  Fast normalized cross correlation of mask to image  */
/*                                                      */
/********************************************************/

/** \brief This function performes a fast normalized cross-correlation

    To compute the normalized cross correlation in a fast way, it is using the Fast Fourier Transform     and sum-image look-up-tables as it is suggested by J.P.Lewis (1995):
    <i>"Fast Normalized Cross-Correlation"</i>.

    The input pixel type <tt>T1</tt> must be a \ref LinearSpace "linear space" over
    the window functions' value_type <tt>T</tt>, i.e. addition of source values, multiplication with functions' values,
    and NumericTraits must be defined. The mask's value_type must be an \ref AlgebraicField "algebraic field",
    i.e. the arithmetic operations (+, -, *, /) and NumericTraits must be defined.

    By default, the borders are filled with zeros. Use the clearBorders switch to change that behavior if you need to.

    <b> Declarations:</b>

    pass 2D array views:
    \code
    namespace vigra {
        template <class T1, class S1,
                  class T2, class S2,
                  class T3, class S3>
        void
        fastNormalizedCrossCorrelation(MultiArrayView<2, T1, S1> const & in,
                                       MultiArrayView<2, T2, S2> const & mask,
                                       MultiArrayView<2, T3, S3> out,
                                       bool clearBorders=true);

    }
    \endcode


    <b> Usage:</b>

    <b>\#include</b> \<vigra/correlation.hxx\><br/>
    Namespace: vigra

    \code
    unsigned int m_w=51, m_h=51;
    unsigned int w=1000, h=1000;
    MultiArray<2, float> mask(m_w,m_h), src(w,h), dest(w,h);
    ...

    //compute normalized cross correlation of mask and image -> dest
    fastNormalizedCrossCorrelation(mask, src, dest);
    \endcode

    <b> Preconditions:</b>

    The image must be larger than the size of the mask.
*/
doxygen_overloaded_function(template <...> void fastNormalizedCrossCorrelation)

template <class T1, class S1,
          class T2, class S2,
          class T3, class S3,
          unsigned int N>
inline void fastNormalizedCrossCorrelation(MultiArrayView<N, T1, S1> const & in,
                                           MultiArrayView<N, T2, S2> const & mask,
                                           MultiArrayView<N, T3, S3> out,
                                           bool clearBorders=true)
{
    using namespace vigra::multi_math;
    typedef typename MultiArrayShape<N>::type Shape;

    vigra_precondition(in.shape() == out.shape(),
                       "vigra::fastNormalizedCrossCorrelation(): shape mismatch between input and output.");

    vigra_precondition(N>0 && N<=3,
                       "vigra::fastNormalizedCrossCorrelation(): only implemented for arrays of 1, 2 or 3 dimensions.");

    for(unsigned int dim=0; dim<N; dim++)
    {
        vigra_precondition(mask.shape()[dim] % 2 == 1, "vigra::fastNormalizedCrossCorrelation(): Mask width has to be of odd size!");
        vigra_precondition(in.shape()[dim] >= mask.shape()[dim] , "vigra::fastNormalizedCrossCorrelation(): Mask is larger than image!");
    }

    //find mask mean and variance
    double mask_mean = 0.0,
           mask_var  = 0.0,
           mask_size = prod(mask.shape());
    mask.meanVariance(&mask_mean, &mask_var);

    //calculate the fix part of the denumerator a.k.a. the mask std. deviation
    double fix_denumerator = mask_size*sqrt(mask_var);

    if(fix_denumerator == 0)
    {
        out = 0;
    }
    else
    {
        //pre-normalize the mask
        MultiArray<N, double> norm_mask(mask.shape());
        norm_mask = mask;
        norm_mask -= mask_mean;

        //calculate (semi-normalized) numerator:
        MultiArray<N, double> corr_result(in.shape());

        corr_result=in;
        fastCrossCorrelation(corr_result, norm_mask, corr_result, clearBorders);


        //Create fast sum tables for the variable denumerator
        MultiArray<N, double> sum_table(in.shape()+1),
                              sum_table2(in.shape()+1);

        typename MultiArray<N, double>::difference_type zero_diff;

        // now finally fill the sum tables
        // keep a zero line/coloum at the beginning to avoid border computations and conditionals
        integralMultiArray(in,sum_table.subarray(zero_diff+1, in.shape()+1));
        integralMultiArraySquared(in, sum_table2.subarray(zero_diff+1, in.shape()+1));

        MultiCoordinateIterator<N> i(in.shape()-mask.shape()+1), end = i.getEndIterator();

        Shape maskRadius(floor(mask.shape()/2));
        for(; i != end; ++i)
        {
            //calculate e(window) and e(window^2)
            double window_mean         = detail::integralMultiArrayWindowMean(sum_table,  *i, *i+mask.shape()),
                   window_squared_mean = detail::integralMultiArrayWindowMean(sum_table2, *i, *i+mask.shape()),
                   var_denumerator = sqrt(mask_size*window_squared_mean - window_mean*window_mean);

            //calculate overall result
            if(var_denumerator == 0)
            {
                out[*i+maskRadius] = 0;
            }
            else
            {
                out[*i+maskRadius] = mask_size*corr_result[*i+maskRadius]/(var_denumerator*fix_denumerator);
            }
        }
    }
}

template<class MaskIterator, class MaskAccessor>
class CorrelationFunctor
{
public:
    CorrelationFunctor(MaskIterator m_ul, MaskIterator m_lr, MaskAccessor m_acc)
    : m_mask_ul(m_ul),
      m_mask_lr(m_lr),
      m_mask_acc(m_acc)
    {
    }

    CorrelationFunctor(triple<MaskIterator,MaskIterator,MaskAccessor> m)
    : m_mask_ul(m.first),
      m_mask_lr(m.second),
      m_mask_acc(m.third)
    {
    }

    template <class SrcIterator,  class SrcAccessor, class DestIterator,  class DestAccessor>
    void operator()(SrcIterator s, SrcAccessor s_acc, DestIterator d, DestAccessor d_acc) const
    {
        using namespace vigra;

        SrcIterator s_ul = s - windowShape()/2,
                    s_lr = s + windowShape()/2+Diff2D(1,1);

        //find img2 mean
        FindAverage<double> average;
        inspectImage(srcIterRange(s_ul, s_lr, s_acc), average);

        SrcIterator ys = s_ul;
        SrcIterator xs = ys;

        MaskIterator ym = m_mask_ul;
        MaskIterator xm = ym;

        double  res=0;

        for( ; ys.y != s_lr.y; ys.y++, ym.y++)
        {
            for(xs = ys, xm = ym; xs.x != s_lr.x; xs.x++, xm.x++)
            {
                res += m_mask_acc(xm)*s_acc(xs);
            }
        }
        d_acc.set(res,d);
    }

    Diff2D windowShape() const
    {
        return m_mask_lr - m_mask_ul;
    }

private:
    MaskIterator m_mask_ul;
    MaskIterator m_mask_lr;
    MaskAccessor m_mask_acc;
};

/********************************************************/
/*                                                      */
/*          Cross correlation of mask to image          */
/*                                                      */
/********************************************************/

/** \brief This function performes a (slow) cross-correlation

    This function performes a (slow) cross-correlation using the window function environment
    and comparison of the mask with the underlying image part for each pixel. This may
    however be faster for very few comparisons.

    The input pixel type <tt>T1</tt> must be a \ref LinearSpace "linear space" over
    the window functions' value_type <tt>T</tt>, i.e. addition of source values, multiplication with functions' values,
    and NumericTraits must be defined. The mask's value_type must be an \ref AlgebraicField "algebraic field",
    i.e. the arithmetic operations (+, -, *, /) and NumericTraits must be defined.

    <b> Declarations:</b>

    pass 2D array views:
    \code
    namespace vigra {
        template <class T1, class S1,
                  class T2, class S2,
                  class T3, class S3>
        void
        crossCorrelation(MultiArrayView<2, T1, S1> const & in,
                         MultiArrayView<2, T2, S2> const & mask,
                         MultiArrayView<2, T3, S3> out);

    }
    \endcode

    \deprecatedAPI{crossCorrelation}
    pass \ref ImageIterators and \ref DataAccessors :
    \code
    namespace vigra {
        template <class SrcIterator, class SrcAccessor,
                  class MaskIterator, class MaskAccessor,
                  class DestIterator, class DestAccessor>
        void crossCorrelation(SrcIterator s_ul, SrcIterator s_lr, SrcAccessor s_acc,
                              MaskIterator m_ul, MaskIterator m_lr, MaskAccessor m_acc,
                              DestIterator d_ul, DestAccessor d_acc);
    }
    \endcode
    use argument objects in conjunction with \ref ArgumentObjectFactories :
    \code
    namespace vigra {
        template <class SrcIterator, class SrcAccessor,
                  class MaskIterator, class MaskAccessor,
                  class DestIterator, class DestAccessor>
        void
        crossCorrelation(triple<MaskIterator, MaskIterator, MaskAccessor> src,
                         triple<SrcIterator, SrcIterator, SrcAccessor> mask,
                         pair<DestIterator, DestAccessor> dest);
    }
    \endcode
    \deprecatedEnd

    <b> Usage:</b>

    <b>\#include</b> \<vigra/correlation.hxx\><br/>
    Namespace: vigra

    \code
    unsigned int m_w=51, m_h=51;
    unsigned int w=1000, h=1000;
    MultiArray<2, float> mask(m_w,m_h), src(w,h), dest(w,h);
    ...

    //compute (slow) cross correlation of mask and image -> dest
    crossCorrelation(mask, src, dest);
    \endcode

    <b> Preconditions:</b>

    The image must be larger than the size of the mask.
*/
doxygen_overloaded_function(template <...> void crossCorrelation)

template <class SrcIterator, class SrcAccessor,
          class MaskIterator, class MaskAccessor,
          class DestIterator, class DestAccessor>
inline void crossCorrelation(SrcIterator s_ul,  SrcIterator s_lr,   SrcAccessor s_acc,
                             MaskIterator m_ul,  MaskIterator m_lr,   MaskAccessor m_acc,
                             DestIterator d_ul, DestAccessor d_acc,
                             BorderTreatmentMode border = BORDER_TREATMENT_AVOID)
{
    CorrelationFunctor<MaskIterator, MaskAccessor> func(m_ul, m_lr, m_acc);
    applyWindowFunction(s_ul, s_lr, s_acc, d_ul, d_acc, func, border);
}

template <class SrcIterator, class SrcAccessor,
          class MaskIterator, class MaskAccessor,
          class DestIterator, class DestAccessor>
inline void crossCorrelation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
                             triple<MaskIterator, MaskIterator, MaskAccessor> mask,
                             pair<DestIterator, DestAccessor> dest,
                             BorderTreatmentMode border = BORDER_TREATMENT_AVOID)
{
    crossCorrelation(src.first, src.second, src.third,
                     mask.first, mask.second, mask.third,
                     dest.first, dest.second,
                     border);
}

template <class T1, class S1,
          class T2, class S2,
          class T3, class S3>
inline void crossCorrelation(MultiArrayView<2, T1, S1> const & in,
                             MultiArrayView<2, T2, S2> const & mask,
                             MultiArrayView<2, T3, S3> out)
{
    vigra_precondition(in.shape() == out.shape(),
                        "vigra::crossCorrelation(): shape mismatch between input and output.");
    crossCorrelation(srcImageRange(in),
                     srcImageRange(mask),
                     destImage(out));
}

template<class MaskIterator, class MaskAccessor>
class NormalizedCorrelationFunctor
{
public:

    NormalizedCorrelationFunctor(MaskIterator m_ul, MaskIterator m_lr, MaskAccessor m_acc)
    : m_mask_ul(m_ul),
      m_mask_lr(m_lr),
      m_mask_acc(m_acc),
      m_s11(0.0),
      m_avg1(0.0)
    {
        init_s11();
    }

    NormalizedCorrelationFunctor(triple<MaskIterator,MaskIterator,MaskAccessor> mask)
    : m_mask_ul(mask.first),
      m_mask_lr(mask.second),
      m_mask_acc(mask.third),
      m_s11(0.0),
      m_avg1(0.0)
    {
        init_s11();
    }

    template <class SrcIterator,  class SrcAccessor, class DestIterator,  class DestAccessor>
    void operator()(SrcIterator s, SrcAccessor s_acc, DestIterator d, DestAccessor d_acc) const
    {
        using namespace vigra;

        SrcIterator s_ul = s - windowShape()/2,
        s_lr = s + windowShape()/2+Diff2D(1,1);

        if(m_s11 == 0.0)
        {
            d_acc.set(0,d);
        }
        else
        {
            //find img2 mean
            FindAverage<double> average;
            inspectImage(srcIterRange(s_ul, s_lr, s_acc), average);

            SrcIterator ys = s_ul;
            SrcIterator xs = ys;

            MaskIterator ym = m_mask_ul;
            MaskIterator xm = ym;

            double  s1=0,s2=0, s12=0, s22=0;

            for( ; ys.y != s_lr.y; ys.y++, ym.y++)
            {
                for(xs = ys, xm = ym; xs.x != s_lr.x; xs.x++, xm.x++)
                {
                    s1 = m_mask_acc(xm);
                    s2 = s_acc(xs);
                    s12 += (s1-m_avg1)*(s2-average());
                    s22 += (s2-average())*(s2-average());
                }
            }
            if(s22 == 0.0)
            {
                d_acc.set(0,d);
            }
            else
            {
                d_acc.set(s12/sqrt(m_s11*s22),d);
            }
        }
    }

    Diff2D windowShape() const
    {
        return m_mask_lr - m_mask_ul;
    }

private:
    void init_s11()
    {
        //find mask mean
        FindAverage<double> average;
        inspectImage(srcIterRange(m_mask_ul, m_mask_lr, m_mask_acc), average);

        MaskIterator ym = m_mask_ul;
        MaskIterator xm = ym;

        m_avg1 = average();

        for( ; ym.y != m_mask_lr.y; ym.y++)
        {
            for(xm = ym; xm.x != m_mask_lr.x; xm.x++)
            {
                m_s11 += (m_mask_acc(xm)-m_avg1)*(m_mask_acc(xm)-m_avg1);
            }
        }
    }

    MaskIterator m_mask_ul;
    MaskIterator m_mask_lr;
    MaskAccessor m_mask_acc;

    double m_s11;
    double m_avg1;
};

/********************************************************/
/*                                                      */
/*     Normalized Cross correlation of mask to image    */
/*                                                      */
/********************************************************/

/** \brief This function performes a (slow) normalized cross-correlation

    This function performes a (slow) normalized cross-correlation using the window function
    environment and comparison of the mask with the underlying image part for each pixel.
    This may however be faster for very few comparisons.

    The input pixel type <tt>T1</tt> must be a \ref LinearSpace "linear space" over
    the window functions' value_type <tt>T</tt>, i.e. addition of source values, multiplication with functions' values,
    and NumericTraits must be defined. The mask's value_type must be an \ref AlgebraicField "algebraic field",
    i.e. the arithmetic operations (+, -, *, /) and NumericTraits must be defined.

    <b> Declarations:</b>

    pass 2D array views:
    \code
    namespace vigra {
        template <class T1, class S1,
                  class T2, class S2,
                  class T3, class S3>
        void
        normalizedCrossCorrelation(MultiArrayView<2, T1, S1> const & in,
                                   MultiArrayView<2, T2, S2> const & mask,
                                   MultiArrayView<2, T3, S3> out);

    }
    \endcode

    \deprecatedAPI{normalizedCrossCorrelation}
    pass \ref ImageIterators and \ref DataAccessors :
    \code
    namespace vigra {
        template <class SrcIterator, class SrcAccessor,
                  class MaskIterator, class MaskAccessor,
                  class DestIterator, class DestAccessor>
        void normalizedCrossCorrelation(SrcIterator s_ul, SrcIterator s_lr, SrcAccessor s_acc,
                                        MaskIterator m_ul, MaskIterator m_lr, MaskAccessor m_acc,
                                        DestIterator d_ul, DestAccessor d_acc);
    }
    \endcode
    use argument objects in conjunction with \ref ArgumentObjectFactories :
    \code
    namespace vigra {
        template <class SrcIterator, class SrcAccessor,
                  class MaskIterator, class MaskAccessor,
                  class DestIterator, class DestAccessor>
        void
        normalizedCrossCorrelation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
                                   triple<MaskIterator, MaskIterator, MaskAccessor> mask,
                                   pair<DestIterator, DestAccessor> dest);
    }
    \endcode
    \deprecatedEnd

    <b> Usage:</b>

    <b>\#include</b> \<vigra/correlation.hxx\><br/>
    Namespace: vigra

    \code
    unsigned int m_w=51, m_h=51;
    unsigned int w=1000, h=1000;
    MultiArray<2, float> mask(m_w,m_h), src(w,h), dest(w,h);
    ...

    //compute (slow) normalized cross correlation of mask and image -> dest
    normalizedCrossCorrelation(mask, src, dest);
    \endcode

    <b> Preconditions:</b>

    The image must be larger than the size of the mask.
*/
doxygen_overloaded_function(template <...> void normalizedCrossCorrelation)


template <class SrcIterator, class SrcAccessor,
          class MaskIterator, class MaskAccessor,
          class DestIterator, class DestAccessor>
inline void normalizedCrossCorrelation(SrcIterator s_ul,  SrcIterator s_lr,   SrcAccessor s_acc,
                                       MaskIterator m_ul,  MaskIterator m_lr,   MaskAccessor m_acc,
                                       DestIterator d_ul, DestAccessor d_acc,
                                       BorderTreatmentMode border = BORDER_TREATMENT_AVOID)
{
    NormalizedCorrelationFunctor<MaskIterator, MaskAccessor> func(m_ul, m_lr, m_acc);
    applyWindowFunction(s_ul, s_lr, s_acc, d_ul, d_acc, func, border);
}

template <class SrcIterator, class SrcAccessor,
          class MaskIterator, class MaskAccessor,
          class DestIterator, class DestAccessor>
inline void normalizedCrossCorrelation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
                                       triple<MaskIterator, MaskIterator, MaskAccessor> mask,
                                       pair<DestIterator, DestAccessor> dest,
                                       BorderTreatmentMode border = BORDER_TREATMENT_AVOID)
{
    normalizedCrossCorrelation(src.first, src.second, src.third,
                               mask.first, mask.second, mask.third,
                               dest.first, dest.second,
                               border);
}

template <class T1, class S1,
          class T2, class S2,
          class T3, class S3>
inline void normalizedCrossCorrelation(MultiArrayView<2, T1, S1> const & in,
                                       MultiArrayView<2, T2, S2> const & mask,
                                       MultiArrayView<2, T3, S3> out)
{
    vigra_precondition(in.shape() == out.shape(),
                        "vigra::normalizedCrossCorrelation(): shape mismatch between input and output.");
    normalizedCrossCorrelation(srcImageRange(in),
                               srcImageRange(mask),
                               destImage(out));
}

//@}

} //end of namespace vigra

#endif //VIGRA_CORRELATION_HXX