-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageUtils.cpp
49 lines (44 loc) · 1.81 KB
/
ImageUtils.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
#include "ImageUtils.h"
Image ImageUtils::normalize(Image image) {
Image resultImage(image);
double currentBright = resultImage.getPixel(0,0);
double maxBright = currentBright;
double minBright = currentBright;
for(int x = 0; x < resultImage.getWidth(); x++){
for(int y = 0; y < resultImage.getHeight(); y++){
currentBright = resultImage.getPixel(x,y);
if(maxBright < currentBright) maxBright = currentBright;
if(minBright > currentBright) minBright = currentBright;
}
}
for(int x = 0; x < resultImage.getWidth(); x++){
for(int y = 0; y < resultImage.getHeight(); y++){
currentBright = resultImage.getPixel(x,y);
currentBright = ((currentBright - minBright) / (maxBright - minBright));
resultImage.setPixel(x,y,currentBright);
}
}
return resultImage;
}
std::vector<IntrestingPoint> ImageUtils::ANMS(std::vector<IntrestingPoint> points, int pointsCount){
printf("ANMS Start\n");
int currentRadius = 1;
while(points.size() > pointsCount) {
for(int x = 0; x < points.size(); x++){
for(int y = 0; y < points.size(); y++){
//double currentDistance = sqrt(pow((points.at(x).getX() - points.at(y).getX()),2) + pow((points.at(x).getY() - points.at(y).getY()),2));
if(x == y) continue;
if( points.at(x).getDistance(points.at(y)) < currentRadius && points.at(x).getValue() > points.at(y).getValue()) {
points.erase(points.begin() + x);
break;
}
}
}
currentRadius++;
}
printf("ANMS End\n");
return points;
}
double ImageUtils::getDistance(double x0, double x1, double y0, double y1){
return sqrt(pow((x1 - x0),2) + pow((y1 - y0),2));
}