GDAL

gdal_simplesurf.h
Go to the documentation of this file.
1 /******************************************************************************
2 * $Id$
3 * Project: GDAL
4 * Purpose: Correlator
5 * Author: Andrew Migal, migal.drew@gmail.com
6 *
7 ******************************************************************************
8 * Copyright (c) 2012, Andrew Migal
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 ****************************************************************************/
28
35 #ifndef GDALSIMPLESURF_H_
36 #define GDALSIMPLESURF_H_
37
38 #include "gdal_priv.h"
39 #include "cpl_conv.h"
40 #include <list>
41
51 class GDALFeaturePoint
52 {
53 public:
58 GDALFeaturePoint();
59
64 GDALFeaturePoint(const GDALFeaturePoint &fp);
65
78 GDALFeaturePoint(int nX, int nY, int nScale, int nRadius, int nSign);
79 virtual ~GDALFeaturePoint();
80
82 GDALFeaturePoint &operator=(const GDALFeaturePoint &point);
83
94 double &operator[](int nIndex);
95
97 static const int DESC_SIZE = 64;
98
104 int GetX() const;
105
111 void SetX(int nX);
112
118 int GetY() const;
119
125 void SetY(int nY);
126
132 int GetScale() const;
133
139 void SetScale(int nScale);
140
146 int GetRadius() const;
147
153 void SetRadius(int nRadius);
154
160 int GetSign() const;
161
167 void SetSign(int nSign);
168
169 private:
170 // Coordinates of point in image
171 int nX;
172 int nY;
173 // --------------------
174 int nScale;
175 int nRadius;
176 int nSign;
177 // Descriptor array
178 double *padfDescriptor;
179 };
180
190 class GDALIntegralImage
191 {
192 CPL_DISALLOW_COPY_ASSIGN(GDALIntegralImage)
193
194 public:
195 GDALIntegralImage();
196 virtual ~GDALIntegralImage();
197
205 void Initialize(const double **padfImg, int nHeight, int nWidth);
206
216 double GetValue(int nRow, int nCol);
217
229 double GetRectangleSum(int nRow, int nCol, int nWidth, int nHeight);
230
240 double HaarWavelet_X(int nRow, int nCol, int nSize);
241
251 double HaarWavelet_Y(int nRow, int nCol, int nSize);
252
258 int GetHeight();
259
265 int GetWidth();
266
267 private:
268 double **pMatrix = nullptr;
269 int nWidth = 0;
270 int nHeight = 0;
271 };
272
282 class GDALOctaveLayer
283 {
284 CPL_DISALLOW_COPY_ASSIGN(GDALOctaveLayer)
285
286 public:
287 GDALOctaveLayer();
288
297 GDALOctaveLayer(int nOctave, int nInterval);
298 virtual ~GDALOctaveLayer();
299
309 void ComputeLayer(GDALIntegralImage *poImg);
310
314 int octaveNum;
318 int filterSize;
322 int radius;
326 int scale;
330 int width;
334 int height;
338 double **detHessians;
342 int **signs;
343 };
344
352 class GDALOctaveMap
353 {
354 CPL_DISALLOW_COPY_ASSIGN(GDALOctaveMap)
355
356 public:
365 GDALOctaveMap(int nOctaveStart, int nOctaveEnd);
366 virtual ~GDALOctaveMap();
367
374 void ComputeMap(GDALIntegralImage *poImg);
375
395 static bool PointIsExtremum(int row, int col, GDALOctaveLayer *bot,
396 GDALOctaveLayer *mid, GDALOctaveLayer *top,
397 double threshold);
398
402 GDALOctaveLayer ***pMap;
403
407 static const int INTERVALS = 4;
408
412 int octaveStart;
413
417 int octaveEnd;
418 };
419
432 class GDALSimpleSURF
433 {
434 private:
439 class MatchedPointPairInfo
440 {
441 public:
442 MatchedPointPairInfo(int nInd_1, int nInd_2, double dfDist)
443 : ind_1(nInd_1), ind_2(nInd_2), euclideanDist(dfDist)
444 {
445 }
446
447 int ind_1;
448 int ind_2;
449 double euclideanDist;
450 };
451
452 CPL_DISALLOW_COPY_ASSIGN(GDALSimpleSURF)
453
454 public:
479 GDALSimpleSURF(int nOctaveStart, int nOctaveEnd);
480 virtual ~GDALSimpleSURF();
481
498 static CPLErr ConvertRGBToLuminosity(GDALRasterBand *red,
499 GDALRasterBand *green,
500 GDALRasterBand *blue, int nXSize,
501 int nYSize, double **padfImg,
502 int nHeight, int nWidth);
503
519 std::vector<GDALFeaturePoint> *
520 ExtractFeaturePoints(GDALIntegralImage *poImg, double dfThreshold);
521
542 static CPLErr
543 MatchFeaturePoints(std::vector<GDALFeaturePoint *> *poMatchPairs,
544 std::vector<GDALFeaturePoint> *poFirstCollect,
545 std::vector<GDALFeaturePoint> *poSecondCollect,
546 double dfThreshold);
547
548 private:
558 static double GetEuclideanDistance(GDALFeaturePoint &firstPoint,
559 GDALFeaturePoint &secondPoint);
560
566 static void NormalizeDistances(std::list<MatchedPointPairInfo> *poList);
567
574 static void SetDescriptor(GDALFeaturePoint *poPoint,
575 GDALIntegralImage *poImg);
576
577 private:
578 int octaveStart;
579 int octaveEnd;
580 GDALOctaveMap *poOctMap;
581 };
582
583 #endif /* GDALSIMPLESURF_H_ */
GDALOctaveLayer::width
int width
Image width in pixels.
Definition: gdal_simplesurf.h:330
GDALFeaturePoint::SetY
void SetY(int nY)
Set Y coordinate of point.
Definition: gdal_simplesurf.cpp:96
GDALOctaveLayer::scale
int scale
Scale for this layer.
Definition: gdal_simplesurf.h:326
GDALFeaturePoint::SetRadius
void SetRadius(int nRadius)
Set radius of point.
Definition: gdal_simplesurf.cpp:114
GDALOctaveLayer::filterSize
int filterSize
Length of the side of filter.
Definition: gdal_simplesurf.h:318
GDALIntegralImage::HaarWavelet_X
double HaarWavelet_X(int nRow, int nCol, int nSize)
Get value of horizontal Haar wavelet in specified square grid.
Definition: gdal_octave.cpp:139
GDALFeaturePoint::operator[]
double & operator[](int nIndex)
Provide access to point's descriptor.
Definition: gdal_simplesurf.cpp:128
GDALOctaveMap::INTERVALS
static const int INTERVALS
Value for constructing internal octave space.
Definition: gdal_simplesurf.h:407
GDALFeaturePoint::DESC_SIZE
static const int DESC_SIZE
Descriptor length.
Definition: gdal_simplesurf.h:97
GDALRasterBand
A single raster band (or channel).
Definition: gdal_priv.h:1270
GDALIntegralImage::HaarWavelet_Y
double HaarWavelet_Y(int nRow, int nCol, int nSize)
Get value of vertical Haar wavelet in specified square grid.
Definition: gdal_octave.cpp:145
GDALIntegralImage::GetRectangleSum
double GetRectangleSum(int nRow, int nCol, int nWidth, int nHeight)
Get sum of values in specified rectangular grid.
Definition: gdal_octave.cpp:100
GDALOctaveMap::octaveEnd
int octaveEnd
Number of top octave.
Definition: gdal_simplesurf.h:417
GDALOctaveMap::PointIsExtremum
static bool PointIsExtremum(int row, int col, GDALOctaveLayer *bot, GDALOctaveLayer *mid, GDALOctaveLayer *top, double threshold)
Method makes decision that specified point in middle octave layer is maximum among all points from 3x...
Definition: gdal_octave.cpp:265
GDALFeaturePoint::GetSign
int GetSign() const
Fetch sign of Hessian determinant of point.
Definition: gdal_simplesurf.cpp:119
GDALFeaturePoint::SetX
void SetX(int nX)
Set X coordinate of point.
Definition: gdal_simplesurf.cpp:87
GDALOctaveLayer::detHessians
double ** detHessians
Hessian values for image pixels.
Definition: gdal_simplesurf.h:338
GDALFeaturePoint::GetRadius
int GetRadius() const
Fetch radius of point.
Definition: gdal_simplesurf.cpp:110
GDALSimpleSURF::ConvertRGBToLuminosity
static CPLErr ConvertRGBToLuminosity(GDALRasterBand *red, GDALRasterBand *green, GDALRasterBand *blue, int nXSize, int nYSize, double **padfImg, int nHeight, int nWidth)
Convert image with RGB channels to grayscale using "luminosity" method.
Definition: gdal_simplesurf.cpp:158
GDALIntegralImage::Initialize
void Initialize(const double **padfImg, int nHeight, int nWidth)
Compute integral image for specified array.
Definition: gdal_octave.cpp:50
GDALFeaturePoint::GetX
int GetX() const
Fetch X-coordinate (pixel) of point.
Definition: gdal_simplesurf.cpp:83
GDALFeaturePoint::SetScale
void SetScale(int nScale)
Set scale of point.
Definition: gdal_simplesurf.cpp:105
GDALFeaturePoint
Class of "feature point" in raster.
Definition: gdal_simplesurf.h:51
GDALIntegralImage::GetValue
double GetValue(int nRow, int nCol)
Fetch value of specified position in integral image.
Definition: gdal_octave.cpp:92
GDALOctaveLayer::radius
int radius
Length of the border.
Definition: gdal_simplesurf.h:322
GDALOctaveLayer::signs
int ** signs
Hessian signs for speeded matching.
Definition: gdal_simplesurf.h:342
cpl_conv.h
GDALSimpleSURF::MatchFeaturePoints
static CPLErr MatchFeaturePoints(std::vector< GDALFeaturePoint * > *poMatchPairs, std::vector< GDALFeaturePoint > *poFirstCollect, std::vector< GDALFeaturePoint > *poSecondCollect, double dfThreshold)
Find corresponding points (equal points in two collections).
Definition: gdal_simplesurf.cpp:364
GDALFeaturePoint::GDALFeaturePoint
GDALFeaturePoint()
Standard constructor.
Definition: gdal_simplesurf.cpp:40
GDALOctaveLayer::ComputeLayer
void ComputeLayer(GDALIntegralImage *poImg)
Perform calculation of Hessian determinants and their signs for specified integral image.
Definition: gdal_octave.cpp:174
GDALOctaveMap::GDALOctaveMap
GDALOctaveMap(int nOctaveStart, int nOctaveEnd)
Create octave space.
Definition: gdal_octave.cpp:246
GDALSimpleSURF
Class for searching corresponding points on images.
Definition: gdal_simplesurf.h:432
GDALIntegralImage::GetWidth
int GetWidth()
Fetch width of integral image.
Definition: gdal_octave.cpp:45
gdal_priv.h
GDALFeaturePoint::GetScale
int GetScale() const
Fetch scale of point.
Definition: gdal_simplesurf.cpp:101
GDALOctaveLayer
Class for computation and storage of Hessian values in SURF-based algorithm.
Definition: gdal_simplesurf.h:282
GDALFeaturePoint::SetSign
void SetSign(int nSign)
Set sign of point.
Definition: gdal_simplesurf.cpp:123
GDALFeaturePoint::GetY
int GetY() const
Fetch Y-coordinate (line) of point.
Definition: gdal_simplesurf.cpp:92
GDALSimpleSURF::GDALSimpleSURF
GDALSimpleSURF(int nOctaveStart, int nOctaveEnd)
Prepare class according to specified parameters.
Definition: gdal_simplesurf.cpp:150
GDALOctaveMap::octaveStart
int octaveStart
Number of bottom octave.
Definition: gdal_simplesurf.h:412
GDALIntegralImage
Integral image class (summed area table).
Definition: gdal_simplesurf.h:190
CPLErr
CPLErr
Error category.
Definition: cpl_error.h:52
GDALSimpleSURF::ExtractFeaturePoints
std::vector< GDALFeaturePoint > * ExtractFeaturePoints(GDALIntegralImage *poImg, double dfThreshold)
Find feature points using specified integral image.
Definition: gdal_simplesurf.cpp:233
GDALOctaveMap
Class for handling octave layers in SURF-based algorithm.
Definition: gdal_simplesurf.h:352
GDALFeaturePoint::operator=
GDALFeaturePoint & operator=(const GDALFeaturePoint &point)
Assignment operator.
Definition: gdal_simplesurf.cpp:61
GDALOctaveLayer::octaveNum
int octaveNum
Octave which contains this layer (1,2,3...)
Definition: gdal_simplesurf.h:314
GDALOctaveMap::pMap
GDALOctaveLayer *** pMap
2-dimensional array of octave layers
Definition: gdal_simplesurf.h:402
GDALOctaveLayer::height
int height
Image height in pixels.
Definition: gdal_simplesurf.h:334
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:1042
GDALIntegralImage::GetHeight
int GetHeight()
Fetch height of integral image.
Definition: gdal_octave.cpp:40
GDALOctaveMap::ComputeMap
void ComputeMap(GDALIntegralImage *poImg)
Calculate Hessian values for octave space (for all stored octave layers) using specified integral ima...
Definition: gdal_octave.cpp:258