/
Descriptor.cpp
65 lines (52 loc) · 1.83 KB
/
Descriptor.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
#include "Descriptor.h"
Descriptor::Descriptor(const IntrestingPoint &inputPoint):point(inputPoint)
{
std::fill(std::begin (histograms), std::end (histograms), 0);
}
double Descriptor::getHistValue(int histogramNumber, int basketNumber) const {
if(basketNumber >= binCount) basketNumber = 0;
if(basketNumber < 0) basketNumber = binCount - 1;
return histograms[basketNumber * histogramsCount + histogramNumber];
}
void Descriptor::addHistValue(int histogramNumber, int basketNumber, double value) {
double curValue = getHistValue(histogramNumber, basketNumber);
setHistValue(histogramNumber, basketNumber, value + curValue);
}
void Descriptor::setHistValue(int histogramNumber, int basketNumber, double value) {
if(basketNumber >= binCount) basketNumber = 0;
if(basketNumber < 0) basketNumber = binCount - 1;
histograms[basketNumber * histogramsCount + histogramNumber] = value;
}
void Descriptor::normalize()
{
//accumulate(begin, end)
double size = 0;
for (double x : histograms) size += pow(x,2);
size = sqrt(size);
for(int i = 0; i < histogramsCount * binCount; i++){
if(histograms[i] / size > 0.2) {
histograms[i] = 0.2;
} else {
histograms[i] = histograms[i]/size;
}
}
size = 0;
for (double x : histograms) size += pow(x,2);
size = sqrt(size);
for(int i = 0; i < histogramsCount * binCount; i++){
histograms[i] = histograms[i] / size;
}
}
double Descriptor::getDistance(const Descriptor &descriptor) const
{
double result = 0;
for(int i = 0; i < histogramsCount; i++){
for(int j = 0; j < binCount; j++){
result += pow((descriptor.getHistValue(i,j) - getHistValue(i,j)),2);
}
}
return sqrt(result);
}
IntrestingPoint Descriptor::getIntrestingPoint() {
return point;
}