InterestPoints.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 #ifndef VIGRA_EXT_INTEREST_POINTS
00028 #define VIGRA_EXT_INTEREST_POINTS
00029 
00030 #include <vector>
00031 #include <map>
00032 
00033 #include <vigra/error.hxx>
00034 #include <vigra/impex.hxx>
00035 #include <vigra/cornerdetection.hxx>
00036 #include <vigra/localminmax.hxx>
00037 #include <vigra/diff2d.hxx>
00038 
00039 namespace vigra_ext
00040 {
00041 
00042 template <class ImageIter, class ImageAcc>
00043 void findInterestPointsPartial(vigra::triple<ImageIter, ImageIter, ImageAcc> img, const vigra::Rect2D& rect, double scale,
00044     unsigned nPoints, std::multimap<double, vigra::Diff2D> &points
00045     )
00046 {
00048     // find interesting corners using harris corner detector
00049     // working only in given rectangle
00050 
00051     // select the nPoints with the highest response
00052     // some distribution criteria might be useful, too
00053     // to avoid clustering all points on a single object.
00054     vigra::BImage leftCorners(rect.size(), vigra::UInt8(0));
00055     vigra::FImage leftCornerResponse(rect.size());
00056 
00057     DEBUG_DEBUG("running corner detector. nPoints: " << nPoints << ",  scale: " << scale);
00058     // find corner response at scale scale
00059     vigra::cornerResponseFunction(srcIterRange(img.first + rect.upperLeft(), img.first + rect.lowerRight(), img.third),
00060         vigra::destImage(leftCornerResponse), scale);
00061 
00062     // find local maxima of corner response, mark with 1
00063     vigra::localMaxima(vigra::srcImageRange(leftCornerResponse), vigra::destImage(leftCorners), 255);
00064 
00065     double minResponse = 0;
00066     points.clear();
00067     // sample grid on img1 and try to add ctrl points
00068     for (int y = 0; y < rect.height(); y++)
00069     {
00070         for (int x = 0; x < rect.width(); x++)
00071         {
00072             if (leftCorners(x, y) == 0)
00073             {
00074                 continue;
00075             }
00076             double resp = leftCornerResponse(x, y);
00077             if (resp > minResponse)
00078             {
00079                 // add to point map
00080                 points.insert(std::make_pair(resp, vigra::Diff2D(x, y) + rect.upperLeft()));
00081                 // if we have reached the maximum
00082                 // number of points, increase the threshold, to avoid
00083                 // growing the points map too much.
00084                 // extract more than nPoints, because some might be bad
00085                 // and cannot be matched with the other image.
00086                 if (points.size() > nPoints)
00087                 {
00088                     // remove the point with the lowest corner response.
00089                     points.erase(points.begin());
00090                     // use new threshold for next selection.
00091                     minResponse = points.begin()->first;
00092                 }
00093             }
00094         }
00095     }
00096 }
00097 
00098 } // namespace
00099 
00100 #endif

Generated on 28 Aug 2015 for Hugintrunk by  doxygen 1.4.7