Engauge Digitizer  2
PointMatchAlgorithm.h
1 #ifndef POINT_MATCH_ALGORITHM_H
2 #define POINT_MATCH_ALGORITHM_H
3 
4 #include "fftw3.h"
5 #include "Point.h"
6 #include "PointMatchPixel.h"
7 #include "PointMatchTriplet.h"
8 #include "Points.h"
9 #include <QList>
10 #include <QPoint>
11 
13 class QImage;
14 class QPixmap;
15 
16 typedef QList<PointMatchTriplet> PointMatchList;
17 
21 {
22  public:
24  PointMatchAlgorithm(bool isGnuplot);
25 
27  QList<QPoint> findPoints (const QList<PointMatchPixel> &samplePointPixels,
28  const QImage &imageProcessed,
29  const DocumentModelPointMatch &modelPointMatch,
30  const Points &pointsExisting);
31 
32  private:
33 
34  // Allocate memory for an image array and phase array pair before calculations
35  void allocateMemory(double** array,
36  fftw_complex** arrayPrime,
37  int width,
38  int height);
39 
40  // Find each local maxima that is the largest value in a region that is:
41  // 1. as big as the the sample
42  // 2. centered about that local maxima
43  void assembleLocalMaxima(double* convolution,
44  PointMatchList& listCreated,
45  int width,
46  int height,
47  int sampleXCenter,
48  int sampleYCenter);
49 
50  // Compute convolution in image space from phase space image and sample arrays
51  void computeConvolution(fftw_complex* imagePrime,
52  fftw_complex* samplePrime,
53  int width,
54  int height,
55  double** convolution);
56 
57  // In-place replacement of matrix by its complex conjugate
58  void conjugateMatrix(int width,
59  int height,
60  fftw_complex* matrix);
61 
62  // Dump to file for 3d plotting by gnuplot
63  void dumpToGnuplot (double* convolution,
64  int width,
65  int height,
66  const QString &filename) const;
67 
68  // Load image and imagePrime arrays
69  void loadImage(const QImage &imageProcessed,
70  const DocumentModelPointMatch &modelPointMatch,
71  const Points &pointsExisting,
72  int width,
73  int height,
74  double** image,
75  fftw_complex** imagePrime);
76 
77  // Load sample and samplePrime arrays, and compute center location and extent
78  void loadSample(const QList<PointMatchPixel> &samplePointPixels,
79  int width,
80  int height,
81  double** sample,
82  fftw_complex** samplePrime,
83  int* sampleXCenter,
84  int* sampleYCenter,
85  int* sampleXExtent,
86  int* sampleYExtent);
87 
88  // Multiply corresponding elements of two matrices into a third matrix
89  void multiplyMatrices(int width,
90  int height,
91  fftw_complex* in1,
92  fftw_complex* in2,
93  fftw_complex* out);
94 
95  // Given an original array length, this method returns an array length that includes enough padding so that the
96  // array length equals 2^a * 3^b * 5^c * 7^d, which optimizes the fft performance. Typical memory penalties are
97  // less than 6% to get a cpu performance increase of 0% to roughly 100% or 200%
98  int optimizeLengthForFft(int originalLength);
99 
100  // Populate image array with processed image
101  void populateImageArray(const QImage &imageProcessed,
102  int width, int height,
103  double** image);
104 
105  // Populate sample array with sample image
106  void populateSampleArray(const QList<PointMatchPixel> &samplePointPixels,
107  int width,
108  int height,
109  double** sample,
110  int* sampleXCenter,
111  int* sampleYCenter,
112  int* sampleXExtent,
113  int* sampleYExtent);
114 
115  // Release memory for one array after finishing calculations
116  void releaseImageArray(double* array);
117  void releasePhaseArray(fftw_complex* array);
118 
119  // Prevent duplication of existing points. this function returns the number of pixels removed
120  void removePixelsNearExistingPoints(double* image,
121  int imageWidth,
122  int imageHeight,
123  const Points &pointsExisting,
124  int pointSeparation);
125 
126  // Correlate the sample point with the image, returning points in list that is sorted by correlation
127  void scanImage(bool* sampleMaskArray,
128  int sampleMaskWidth,
129  int sampleMaskHeight,
130  int sampleXCenter,
131  int sampleYCenter,
132  const DocumentModelPointMatch &modelPointMatch,
133  int* imageArray,
134  int imageWidth,
135  int imageHeight,
136  PointMatchList* pointsCreated);
137 
138  bool m_isGnuplot;
139 };
140 
141 #endif // POINT_MATCH_ALGORITHM_H
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
Algorithm returning a list of points that match the specified point.
QList< QPoint > findPoints(const QList< PointMatchPixel > &samplePointPixels, const QImage &imageProcessed, const DocumentModelPointMatch &modelPointMatch, const Points &pointsExisting)
Find points that match the specified sample point pixels. They are sorted by best-to-worst match...
PointMatchAlgorithm(bool isGnuplot)
Single constructor.