-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomPointsRepresentationMultiDimensionalHistogram.cpp
89 lines (73 loc) · 2.84 KB
/
RandomPointsRepresentationMultiDimensionalHistogram.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "RandomPointsRepresentationMultiDimensionalHistogram.h"
RandomPointsRepresentationMultiDimensionalHistogram::RandomPointsRepresentationMultiDimensionalHistogram()
{
}
RandomPointsRepresentationMultiDimensionalHistogram::RandomPointsRepresentationMultiDimensionalHistogram(Mat ImagetoBeRepresented, Mat depthMap, int numberOfColourBins, int numberOfDepthBins, Mat XYPoints, int sizeOfWindow)
{
image = ImagetoBeRepresented;
depthImage = depthMap;
bins = numberOfColourBins;
depthBins = numberOfDepthBins;
points = XYPoints;
windowSize = sizeOfWindow;
representationLength = pow(bins, image.channels()) * depthBins * points.rows;
representation = new float[representationLength];
}
RandomPointsRepresentationMultiDimensionalHistogram::~RandomPointsRepresentationMultiDimensionalHistogram()
{
}
void RandomPointsRepresentationMultiDimensionalHistogram::computeRepresentation()
{
if ((image.empty()) || (image.depth() != CV_8U) || (depthImage.empty()) || (depthImage.depth() != CV_8U))
{
cout << "Empty/Invalid Image. Image should be of type CV_8U and within range 0-255 \n";
representationLength = 0;
return;
}
if ((depthImage.rows != image.rows) || (depthImage.cols != image.cols))
{
cout << "Size of dpeth and colour image must match \n";
representationLength = 0;
return;
}
rectifyPointsBounds();
int numChannels = image.channels();
Mat colourIndexArray = createColorIndexArray(pow(bins, numChannels), numChannels);
Mat LookUpTable = createBinaryLookupTable(bins);
Mat depthLookUpTable = createBinaryLookupTable(depthBins);
Mat* binaryDepthMasks = new Mat[depthBins];
for (int i = 0; i < depthBins; ++i)
{
// create mask from depthlookuptable
Mat ithDepthTable(1, 256, CV_8U, depthLookUpTable.ptr<uchar>(i));
binaryDepthMasks[i] = Mat(image.rows, image.cols, CV_8UC1);
LUT(depthImage, ithDepthTable, binaryDepthMasks[i]);
}
int ind = 0;
float* p;
for (int i = 0; i < points.rows; i++)
{
// For each pair of point, create an colourhistogram object, compute representations belonging to different depth masks
// and concatenate resulting representations
p = points.ptr<float>(i);
Rect r = Rect(p[0], p[1], windowSize, windowSize);
Mat ROI = image(r);
colourHistogram * colourHistogramRepresentation = new colourHistogram(ROI, bins);
for (int j = 0; j < depthBins; ++j)
{
Mat ROIMask = binaryDepthMasks[j](r);
colourHistogramRepresentation->computeRepresentation(colourIndexArray, LookUpTable, ROIMask);
int leng;
const float * vect = colourHistogramRepresentation->getRepresentation(leng);
for (int k = 0; k < leng; k++)
{
representation[ind] = vect[k];
ind++;
}
}
delete colourHistogramRepresentation;
}
for (int i = 0; i < depthBins; ++i)
binaryDepthMasks[i].release();
delete[] binaryDepthMasks;
}