Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InterestPoints.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
27 #ifndef VIGRA_EXT_INTEREST_POINTS
28 #define VIGRA_EXT_INTEREST_POINTS
29 
30 #include <vector>
31 #include <map>
32 
33 #include <vigra/error.hxx>
34 #include <vigra/impex.hxx>
35 #include <vigra/cornerdetection.hxx>
36 #include <vigra/localminmax.hxx>
37 #include <vigra/diff2d.hxx>
38 
39 namespace vigra_ext
40 {
41 
42 template <class ImageIter, class ImageAcc>
43 void findInterestPointsPartial(vigra::triple<ImageIter, ImageIter, ImageAcc> img, const vigra::Rect2D& rect, double scale,
44  unsigned nPoints, std::multimap<double, vigra::Diff2D> &points
45  )
46 {
48  // find interesting corners using harris corner detector
49  // working only in given rectangle
50 
51  // select the nPoints with the highest response
52  // some distribution criteria might be useful, too
53  // to avoid clustering all points on a single object.
54  vigra::BImage leftCorners(rect.size(), vigra::UInt8(0));
55  vigra::FImage leftCornerResponse(rect.size());
56 
57  DEBUG_DEBUG("running corner detector. nPoints: " << nPoints << ", scale: " << scale);
58  // find corner response at scale scale
59  vigra::cornerResponseFunction(srcIterRange(img.first + rect.upperLeft(), img.first + rect.lowerRight(), img.third),
60  vigra::destImage(leftCornerResponse), scale);
61 
62  // find local maxima of corner response, mark with 1
63  vigra::localMaxima(vigra::srcImageRange(leftCornerResponse), vigra::destImage(leftCorners), 255);
64 
65  double minResponse = 0;
66  points.clear();
67  // sample grid on img1 and try to add ctrl points
68  for (int y = 0; y < rect.height(); y++)
69  {
70  for (int x = 0; x < rect.width(); x++)
71  {
72  if (leftCorners(x, y) == 0)
73  {
74  continue;
75  }
76  double resp = leftCornerResponse(x, y);
77  if (resp > minResponse)
78  {
79  // add to point map
80  points.insert(std::make_pair(resp, vigra::Diff2D(x, y) + rect.upperLeft()));
81  // if we have reached the maximum
82  // number of points, increase the threshold, to avoid
83  // growing the points map too much.
84  // extract more than nPoints, because some might be bad
85  // and cannot be matched with the other image.
86  if (points.size() > nPoints)
87  {
88  // remove the point with the lowest corner response.
89  points.erase(points.begin());
90  // use new threshold for next selection.
91  minResponse = points.begin()->first;
92  }
93  }
94  }
95  }
96 }
97 
98 } // namespace
99 
100 #endif
void findInterestPointsPartial(vigra::triple< ImageIter, ImageIter, ImageAcc > img, const vigra::Rect2D &rect, double scale, unsigned nPoints, std::multimap< double, vigra::Diff2D > &points)
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
Definition: ROIImage.h:324
vigra::triple< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImageRange(const ROIImage< Image, Mask > &img)
helper function for ROIImages
Definition: ROIImage.h:287
#define DEBUG_DEBUG(msg)
Definition: utils.h:68