[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin1/hugin/ImageProcessing.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00026 #ifndef _IMAGEPROCESSING_H
00027 #define _IMAGEPROCESSING_H
00028 
00029 #include "hugin/ImageCache.h"
00030 
00031 class wxImage;
00032 
00033 #if 0
00034 
00044 template <class SrcIterator, class SrcAccessor,
00045           class DestIterator, class DestAccessor,
00046           class KernelIterator, class KernelAccessor>
00047 CorrelationResult correlateImage_new(SrcIterator sul, SrcIterator slr, SrcAccessor as,
00048                                      DestIterator dul, DestAccessor ad,
00049                                      KernelIterator ki, KernelAccessor ak,
00050                                      vigra::Diff2D kul, vigra::Diff2D klr,
00051                                      double threshold = 0.7
00052                                     )
00053 {
00054     vigra_precondition(kul.x <= 0 && kul.y <= 0,
00055                  "convolveImage(): coordinates of "
00056                  "kernel's upper left must be <= 0.");
00057     vigra_precondition(klr.x >= 0 && klr.y >= 0,
00058                  "convolveImage(): coordinates of "
00059                  "kernel's lower right must be >= 0.");
00060 
00061     // use traits to determine SumType as to prevent possible overflow
00062     typedef typename
00063         vigra::NumericTraits<typename SrcAccessor::value_type>::RealPromote SumType;
00064     typedef typename
00065         vigra::NumericTraits<typename KernelAccessor::value_type>::RealPromote KSumType;
00066     typedef
00067         vigra::NumericTraits<typename DestAccessor::value_type> DestTraits;
00068 
00069     // calculate width and height of the source and kernel
00070     int w = slr.x - sul.x;
00071     int h = slr.y - sul.y;
00072     int wk = klr.x - kul.x +1;
00073     int hk = klr.y - kul.y +1;
00074 
00075     DEBUG_DEBUG("correlate Image srcSize " << (slr - sul).x << "," << (slr - sul).y
00076                 << " tmpl size: " << wk << "," << hk)
00077 
00078     vigra_precondition(w >= wk && h >= hk,
00079                  "convolveImage(): kernel larger than image.");
00080 
00081     int ystart = -kul.y;
00082     int yend   = h-klr.y;
00083     int xstart = -kul.x;
00084     int xend   = w-klr.x;
00085 
00086     // calculate template mean
00087     vigra::FindAverage<typename KernelAccessor::value_type> average;
00088     vigra::inspectImage(ki + kul, ki + klr,
00089                         ak,
00090                         average);
00091     KSumType kmean = average();
00092 
00093     CorrelationResult res;
00094 
00095 
00096     // create the correlation center iterators
00097     DestIterator centerDest = dul + vigra::Diff2D(xstart, ystart);
00098     SrcIterator centerSrc = sul + vigra::Diff2D(xstart, ystart);
00099 
00100 
00101     DEBUG_DEBUG("size: " << w << "," <<  h << " ystart: " << ystart <<", yend: " << yend);
00102     for(centerDest.y = DestIterator::MoveY(0),
00103          centerSrc.y = SrcIterator::MoveY(0);
00104         centerDest.y < yend;
00105         ++centerDest.y, ++centerSrc.y)
00106     {
00107         std::cerr << centerDest.y << " " << std::flush;
00108 
00109         for(centerDest.x = DestIterator::MoveX(0),
00110              centerSrc.x = SrcIterator::MoveX(0);
00111             centerDest.x < xend;
00112             ++centerDest.x, ++centerSrc.x)
00113         {
00114             // inner loop, calculate correlation
00115             SumType numerator = 0;
00116             SumType div1 = 0;
00117             SumType div2 = 0;
00118             SumType spixel = 0;
00119             KSumType kpixel = 0;
00120 
00121             // create inner iterators
00122             // access to the source image
00123             SrcIterator src(centerSrc - kul);
00124             int sxstart = src.x;
00125             int systart = src.y;
00126             int sxend = sxstart + wk;
00127             int syend = systart + wk;
00128 
00129             // access to the kernel image
00130             KernelIterator kernel(ki - kul);
00131             int kxstart = kernel.x;
00132             int kystart = kernel.y;
00133 
00134             for(src.y = systart, kernel.y = kystart;
00135                 src.y < syend;
00136                 src.y++, kernel.y++)
00137             {
00138                 for (src.x = sxstart, kernel.x = kxstart;
00139                      src.x < sxend;
00140                      src.x++, kernel.x++)
00141                 {
00142                     spixel = as(src) - mean;
00143                     kpixel = ak(kernel) - kmean;
00144                     numerator += kpixel * spixel;
00145                     div1 += kpixel * kpixel;
00146                     div2 += spixel * spixel;
00147                 }
00148             }
00149             numerator = (numerator/sqrt(div1 * div2));
00150             if (numerator > res.max) {
00151                 res.max = numerator;
00152                 res.pos.x = x;
00153                 res.pos.y = y;
00154             }
00155             numerator = numerator;
00156             // store correlation in destination pixel
00157             ad.set(DestTraits::fromRealPromote(numerator), centerDest);
00158         }
00159     }
00160     return res;
00161 }
00162 
00163 #endif
00164 
00178 #if 0
00179 
00180 // a subpixel correlation result
00181 struct SubPixelCorrelationResult
00182 {
00183     SubPixelCorrelationResult()
00184         : maxi(-1),pos(-1,-1)
00185         { }
00186     double maxi;
00187     FDiff2D pos;
00188 };
00189 
00190 
00191     return r;
00192 }
00193 
00194 #endif
00195 
00196 
00197 
00198 #endif // _IMAGEPROCESSING_H

Generated on Mon Sep 20 01:01:25 2010 for Hugintrunk by doxygen 1.3.9.1