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
106 double operator[](int nIndex) const;
107
109 static const int DESC_SIZE = 64;
110
116 int GetX() const;
117
123 void SetX(int nX);
124
130 int GetY() const;
131
137 void SetY(int nY);
138
144 int GetScale() const;
145
151 void SetScale(int nScale);
152
158 int GetRadius() const;
159
165 void SetRadius(int nRadius);
166
172 int GetSign() const;
173
179 void SetSign(int nSign);
180
181 private:
182 // Coordinates of point in image
183 int nX;
184 int nY;
185 // --------------------
186 int nScale;
187 int nRadius;
188 int nSign;
189 // Descriptor array
190 double *padfDescriptor;
191};
192
202 class GDALIntegralImage
203{
204 CPL_DISALLOW_COPY_ASSIGN(GDALIntegralImage)
205
206 public:
207 GDALIntegralImage();
208 virtual ~GDALIntegralImage();
209
217 void Initialize(const double **padfImg, int nHeight, int nWidth);
218
228 double GetValue(int nRow, int nCol);
229
241 double GetRectangleSum(int nRow, int nCol, int nWidth, int nHeight);
242
252 double HaarWavelet_X(int nRow, int nCol, int nSize);
253
263 double HaarWavelet_Y(int nRow, int nCol, int nSize);
264
270 int GetHeight();
271
277 int GetWidth();
278
279 private:
280 double **pMatrix = nullptr;
281 int nWidth = 0;
282 int nHeight = 0;
283};
284
294 class GDALOctaveLayer
295{
296 CPL_DISALLOW_COPY_ASSIGN(GDALOctaveLayer)
297
298 public:
299 GDALOctaveLayer();
300
309 GDALOctaveLayer(int nOctave, int nInterval);
310 virtual ~GDALOctaveLayer();
311
321 void ComputeLayer(GDALIntegralImage *poImg);
322
326 int octaveNum;
330 int filterSize;
334 int radius;
338 int scale;
342 int width;
346 int height;
350 double **detHessians;
354 int **signs;
355};
356
364 class GDALOctaveMap
365{
366 CPL_DISALLOW_COPY_ASSIGN(GDALOctaveMap)
367
368 public:
377 GDALOctaveMap(int nOctaveStart, int nOctaveEnd);
378 virtual ~GDALOctaveMap();
379
386 void ComputeMap(GDALIntegralImage *poImg);
387
407 static bool PointIsExtremum(int row, int col, GDALOctaveLayer *bot,
408 GDALOctaveLayer *mid, GDALOctaveLayer *top,
409 double threshold);
410
414 GDALOctaveLayer ***pMap;
415
419 static const int INTERVALS = 4;
420
424 int octaveStart;
425
429 int octaveEnd;
430};
431
444 class GDALSimpleSURF
445{
446 private:
451 class MatchedPointPairInfo
452 {
453 public:
454 MatchedPointPairInfo(int nInd_1, int nInd_2, double dfDist)
455 : ind_1(nInd_1), ind_2(nInd_2), euclideanDist(dfDist)
456 {
457 }
458
459 int ind_1;
460 int ind_2;
461 double euclideanDist;
462 };
463
464 CPL_DISALLOW_COPY_ASSIGN(GDALSimpleSURF)
465
466 public:
491 GDALSimpleSURF(int nOctaveStart, int nOctaveEnd);
492 virtual ~GDALSimpleSURF();
493
510 static CPLErr ConvertRGBToLuminosity(GDALRasterBand *red,
511 GDALRasterBand *green,
512 GDALRasterBand *blue, int nXSize,
513 int nYSize, double **padfImg,
514 int nHeight, int nWidth);
515
531 std::vector<GDALFeaturePoint> *
532 ExtractFeaturePoints(GDALIntegralImage *poImg, double dfThreshold);
533
554 static CPLErr
555 MatchFeaturePoints(std::vector<GDALFeaturePoint *> *poMatchPairs,
556 std::vector<GDALFeaturePoint> *poFirstCollect,
557 std::vector<GDALFeaturePoint> *poSecondCollect,
558 double dfThreshold);
559
560 private:
570 static double GetEuclideanDistance(const GDALFeaturePoint &firstPoint,
571 const GDALFeaturePoint &secondPoint);
572
578 static void NormalizeDistances(std::list<MatchedPointPairInfo> *poList);
579
586 static void SetDescriptor(GDALFeaturePoint *poPoint,
587 GDALIntegralImage *poImg);
588
589 private:
590 int octaveStart;
591 int octaveEnd;
592 GDALOctaveMap *poOctMap;
593};
594
595#endif /* GDALSIMPLESURF_H_ */
GDALFeaturePoint
Class of "feature point" in raster.
Definition: gdal_simplesurf.h:52
GDALFeaturePoint::GDALFeaturePoint
GDALFeaturePoint()
Standard constructor.
Definition: gdal_simplesurf.cpp:38
GDALFeaturePoint::SetY
void SetY(int nY)
Set Y coordinate of point.
Definition: gdal_simplesurf.cpp:96
GDALFeaturePoint::operator=
GDALFeaturePoint & operator=(const GDALFeaturePoint &point)
Assignment operator.
Definition: gdal_simplesurf.cpp:59
GDALFeaturePoint::GetSign
int GetSign() const
Fetch sign of Hessian determinant of point.
Definition: gdal_simplesurf.cpp:121
GDALFeaturePoint::SetX
void SetX(int nX)
Set X coordinate of point.
Definition: gdal_simplesurf.cpp:86
GDALFeaturePoint::DESC_SIZE
static const int DESC_SIZE
Descriptor length.
Definition: gdal_simplesurf.h:109
GDALFeaturePoint::GetY
int GetY() const
Fetch Y-coordinate (line) of point.
Definition: gdal_simplesurf.cpp:91
GDALFeaturePoint::GetRadius
int GetRadius() const
Fetch radius of point.
Definition: gdal_simplesurf.cpp:111
GDALFeaturePoint::GetScale
int GetScale() const
Fetch scale of point.
Definition: gdal_simplesurf.cpp:101
GDALFeaturePoint::GetX
int GetX() const
Fetch X-coordinate (pixel) of point.
Definition: gdal_simplesurf.cpp:81
GDALFeaturePoint::SetScale
void SetScale(int nScale)
Set scale of point.
Definition: gdal_simplesurf.cpp:106
GDALFeaturePoint::SetRadius
void SetRadius(int nRadius)
Set radius of point.
Definition: gdal_simplesurf.cpp:116
GDALFeaturePoint::SetSign
void SetSign(int nSign)
Set sign of point.
Definition: gdal_simplesurf.cpp:126
GDALFeaturePoint::operator[]
double & operator[](int nIndex)
Provide access to point's descriptor.
Definition: gdal_simplesurf.cpp:131
GDALIntegralImage
Integral image class (summed area table).
Definition: gdal_simplesurf.h:203
GDALIntegralImage::GetHeight
int GetHeight()
Fetch height of integral image.
Definition: gdal_octave.cpp:38
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:143
GDALIntegralImage::GetValue
double GetValue(int nRow, int nCol)
Fetch value of specified position in integral image.
Definition: gdal_octave.cpp:90
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:137
GDALIntegralImage::Initialize
void Initialize(const double **padfImg, int nHeight, int nWidth)
Compute integral image for specified array.
Definition: gdal_octave.cpp:48
GDALIntegralImage::GetRectangleSum
double GetRectangleSum(int nRow, int nCol, int nWidth, int nHeight)
Get sum of values in specified rectangular grid.
Definition: gdal_octave.cpp:98
GDALIntegralImage::GetWidth
int GetWidth()
Fetch width of integral image.
Definition: gdal_octave.cpp:43
GDALOctaveLayer
Class for computation and storage of Hessian values in SURF-based algorithm.
Definition: gdal_simplesurf.h:295
GDALOctaveLayer::height
int height
Image height in pixels.
Definition: gdal_simplesurf.h:346
GDALOctaveLayer::signs
int ** signs
Hessian signs for speeded matching.
Definition: gdal_simplesurf.h:354
GDALOctaveLayer::detHessians
double ** detHessians
Hessian values for image pixels.
Definition: gdal_simplesurf.h:350
GDALOctaveLayer::filterSize
int filterSize
Length of the side of filter.
Definition: gdal_simplesurf.h:330
GDALOctaveLayer::radius
int radius
Length of the border.
Definition: gdal_simplesurf.h:334
GDALOctaveLayer::octaveNum
int octaveNum
Octave which contains this layer (1,2,3...)
Definition: gdal_simplesurf.h:326
GDALOctaveLayer::width
int width
Image width in pixels.
Definition: gdal_simplesurf.h:342
GDALOctaveLayer::scale
int scale
Scale for this layer.
Definition: gdal_simplesurf.h:338
GDALOctaveLayer::ComputeLayer
void ComputeLayer(GDALIntegralImage *poImg)
Perform calculation of Hessian determinants and their signs for specified integral image.
Definition: gdal_octave.cpp:172
GDALOctaveMap
Class for handling octave layers in SURF-based algorithm.
Definition: gdal_simplesurf.h:365
GDALOctaveMap::INTERVALS
static const int INTERVALS
Value for constructing internal octave space.
Definition: gdal_simplesurf.h:419
GDALOctaveMap::octaveStart
int octaveStart
Number of bottom octave.
Definition: gdal_simplesurf.h:424
GDALOctaveMap::pMap
GDALOctaveLayer *** pMap
2-dimensional array of octave layers
Definition: gdal_simplesurf.h:414
GDALOctaveMap::GDALOctaveMap
GDALOctaveMap(int nOctaveStart, int nOctaveEnd)
Create octave space.
Definition: gdal_octave.cpp:244
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:256
GDALOctaveMap::octaveEnd
int octaveEnd
Number of top octave.
Definition: gdal_simplesurf.h:429
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:263
GDALRasterBand
A single raster band (or channel).
Definition: gdal_priv.h:1468
GDALSimpleSURF
Class for searching corresponding points on images.
Definition: gdal_simplesurf.h:445
GDALSimpleSURF::ExtractFeaturePoints
std::vector< GDALFeaturePoint > * ExtractFeaturePoints(GDALIntegralImage *poImg, double dfThreshold)
Find feature points using specified integral image.
Definition: gdal_simplesurf.cpp:254
GDALSimpleSURF::GDALSimpleSURF
GDALSimpleSURF(int nOctaveStart, int nOctaveEnd)
Prepare class according to specified parameters.
Definition: gdal_simplesurf.cpp:164
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:385
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:172
cpl_conv.h
Various convenience functions for CPL.
CPLErr
CPLErr
Error category.
Definition: cpl_error.h:53
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
gdal_priv.h
C++ GDAL entry points.