-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimgapi.cpp
More file actions
122 lines (105 loc) · 3.31 KB
/
imgapi.cpp
File metadata and controls
122 lines (105 loc) · 3.31 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "imgapi.h"
#include "imagereader.h"
#include <math.h>
#include <QDebug>
#include "config.h"
imgapi::imgapi(ImageReader * imgReader) : imgReader(imgReader)
{
this->imgReader = imgReader;
this->kSize = Config::kSize;
}
imgapi::~imgapi() {
delete this->BvReader;
delete this->BhReader;
delete this->imgReader;
}
void imgapi::fillHorVector(int x0 , int y0, QVector<float> &tmp, ImageReader & imgReader)
{
for (int x = x0 - this->kSize/2; x < x0 + this->kSize/2; x++)
{
tmp.append(imgReader.get(x, y0));
}
}
void imgapi::fillVerVector(int x0 , int y0, QVector<float> & tmp, ImageReader & imgReader)
{
for (int x = x0 - this->kSize/2; x < x0 + this->kSize/2; x++)
{
tmp.append(imgReader.getT(x, y0));
}
}
float imgapi::sum(QVector<float> &vec)
{
float value = 0;
for (int i = 0; i < vec.size(); i++)
{
value += vec.at(i);
}
return value;
}
float imgapi::multSecMinusOneAndSum(QVector<float> &vec)
{
vec[1] *= -1;
return this->sum(vec);
}
void imgapi::countBvAndBh()
{
QVector<float> * tmp = new QVector<float>;
float * bvPtr = new float [this->imgReader->width * this->imgReader->height];
float * bhPtr = new float [this->imgReader->width * this->imgReader->height];
float value = 0;
for (int y = 0; y < this->imgReader->height; y++)
{
for (int x = 0; x < this->imgReader->width; x++)
{
this->fillHorVector(x, y, *tmp, *(this->imgReader));
value = this->sum(*tmp);
bvPtr[y*imgReader->width + x] = value;
tmp->clear();
this->fillVerVector(x, y, *tmp, *(this->imgReader));
value = this->sum(*tmp);
bhPtr[x*imgReader->height + y] = value;
tmp->clear();
}
}
this->BvReader = new ImageReader(imgReader->width, imgReader->height, bvPtr);
this->BhReader = new ImageReader(imgReader->width, imgReader->height, bhPtr);
delete tmp;
}
float imgapi::countQs()
{
this->kSize = 2; // [1 -1]
QVector<float> * tmp = new QVector<float>;
float sIv = 0;
float sIh = 0;
float sVv = 0;
float sVh = 0;
for (int y = 0; y < this->imgReader->height; y++)
{
for (int x = 0; x < this->imgReader->width; x++)
{
this->fillHorVector(x, y, *tmp, *(this->imgReader));
float valueIv = fabs(this->multSecMinusOneAndSum(*tmp));
sIv += valueIv;
tmp->clear();
this->fillVerVector(x, y, *tmp, *(this->imgReader));
float valueIh = fabs(this->multSecMinusOneAndSum(*tmp));
sIh += valueIh;
tmp->clear();
this->fillHorVector(x, y, *tmp, *(this->BvReader));
float valueBv = fabs(this->multSecMinusOneAndSum(*tmp));
sVv += std::max((float)0.0, (valueIv - valueBv));
tmp->clear();
// because we write transpose
this->fillHorVector(x, y, *tmp, *(this->BhReader));
float valueBh = fabs(this->multSecMinusOneAndSum(*tmp));
sVh += std::max((float)0.0, (valueIh - valueBh));
tmp->clear();
}
}
delete tmp;
qInfo() << "sIv: " << sIv;
qInfo() << "sVv: " << sVv;
qInfo() << "sIh: " << sIh;
qInfo() << "sVh: " << sVh;
return 1 - std::max((sIv - sVv) / sIv, (sIh - sVh) / sIh);
}