-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathminutiaemarker.cpp
executable file
·247 lines (188 loc) · 9.64 KB
/
minutiaemarker.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include "minutiaemarker.h"
MinutiaeMarker::MinutiaeMarker()
{
this->setObjectName("marker");
this->outputPath = QDir::currentPath();
}
void MinutiaeMarker::run()
{
exec();
}
QString MinutiaeMarker::getInputPath() const
{
return inputPath;
}
void MinutiaeMarker::setInputPath(const QString &value)
{
inputPath = value;
}
QVector<std::tuple<QPoint, QString> > MinutiaeMarker::getMinutiae() const
{
return minutiae;
}
void MinutiaeMarker::removeMinutia(int lineNum)
{
if (lineNum < this->minutiae.size()) this->minutiae.removeAt(lineNum);
}
void MinutiaeMarker::removeAllBlocks()
{
this->images.clear();
this->minutiae.clear();
}
void MinutiaeMarker::setMinutiae(const QVector<std::tuple<QPoint, QString> > &value)
{
minutiae = value;
}
void MinutiaeMarker::pushMinutia(QPoint xy, QString type)
{
this->minutiae.push_back(std::make_tuple(xy, type));
emit updateMinutiaeMarkerSceneSignal("add");
}
void MinutiaeMarker::insertImage(QString imgName, QVector<std::tuple<QPoint, QString>> minutiae)
{
this->images.insert(imgName, minutiae);
}
QMap<QString, QVector<std::tuple<QPoint, QString> > > MinutiaeMarker::getImages() const
{
return images;
}
QString MinutiaeMarker::getOutputPath() const
{
return outputPath;
}
void MinutiaeMarker::setOutputPath(const QString &value)
{
outputPath = value;
}
void MinutiaeMarker::updataMinutiae(QString prevImgName, QString imgName)
{
if (this->minutiae.empty()) this->images.remove(prevImgName);
else this->images[prevImgName] = this->minutiae;
if (this->images.find(imgName) != this->images.end()) this->minutiae = this->images[imgName];
else this->minutiae.clear();
emit updateMinutiaeMarkerSceneSignal("remove");
}
QImage MinutiaeMarker::irisBlurBlock(QImage &qBlock, const double &blurValue, const double &irisBlurValue)
{
cv::Mat block = h.QImage2Mat(qBlock, CV_8UC1);
cv::Mat blockBlurred;
cv::Mat irisBlurredBlock = cv::Mat::zeros(block.size(), block.type());
int kernelSize = 9;
cv::GaussianBlur(block, blockBlurred, cv::Size(kernelSize, kernelSize), blurValue);;
cv::Mat mask = cv::Mat(block.rows, block.cols, CV_8UC1, cv::Scalar(255));
cv::circle(mask, cv::Point (block.cols / 2, block.rows / 2), block.rows / 2 * 0.75, cv::Scalar(0), -1);
cv::GaussianBlur(mask, mask, cv::Size(kernelSize, kernelSize), irisBlurValue);
//qDebug() << "Halo";
//cv::imshow("mask", mask);
for (int y = 0; y < irisBlurredBlock.rows; ++y)
for (int x = 0; x < irisBlurredBlock.cols; ++x)
{
uchar pixelOrig = block.at<uchar>(y, x);
uchar pixelBlur = blockBlurred.at<uchar>(y, x);
float blurVal = mask.at<unsigned char>(y, x)/255.0f;
uchar pixelOut = blurVal * pixelBlur + (1.0f - blurVal)* pixelOrig;
irisBlurredBlock.at<uchar>(y, x) = pixelOut;
}
return h.Mat2QImage(irisBlurredBlock, QImage::Format_Grayscale8);
}
QImage MinutiaeMarker::blurBlock(QImage &qBlock, const double &blurValue)
{
cv::Mat blurredImg = h.QImage2Mat(qBlock, CV_8UC1);
cv::GaussianBlur(blurredImg, blurredImg, cv::Size(3, 3), blurValue);
return this->h.Mat2QImage(blurredImg, QImage::Format_Grayscale8);
}
QImage MinutiaeMarker::sharpBlock(QImage &qBlock)
{
cv::Mat sharpenedImg = h.QImage2Mat(qBlock, CV_8UC1);
cv::GaussianBlur(sharpenedImg, sharpenedImg, cv::Size(0, 0), 3);
cv::addWeighted(sharpenedImg, 1.5, sharpenedImg, -0.5, 0, sharpenedImg);
return this->h.Mat2QImage(sharpenedImg, QImage::Format_Grayscale8);
}
QImage MinutiaeMarker::rotateBlock(QImage &qBlock, int angle)
{
QTransform imgRotate;
imgRotate.rotate(angle);
return qBlock.transformed(imgRotate);
}
int MinutiaeMarker::countOutputFiles()
{
int fileCnt = 0;
for (auto img = this->images.begin(); img != this->images.end(); img++) fileCnt += img.value().size();
return fileCnt;
}
void MinutiaeMarker::generateBlocks(int blockSize, int additionalBlocks, QString outputFormat, bool rotations, bool blur, double blurValue, bool irisBlur, double irisBlurValue, double irisRadiusValue)
{
QString leftOutputPath, rightOutputPath;
QString leftImgName, rightImgName;
QImage fpImg;
QImage blockOrig, blockBlur, blockIrisBlur;
QDir dir;
int allFile = this->countOutputFiles();
int currentFile = 0;
int saveProgress = 0;
if (this->outputPath[0] == ".") this->outputPath = QDir::currentPath() + this->outputPath.mid(1,this->outputPath.length()-1) + "/";
for (auto img = this->images.begin(); img != this->images.end(); img++) {
for (int actBlockSize = blockSize - additionalBlocks*2; actBlockSize <= blockSize + additionalBlocks*2; actBlockSize += 2) {
int fileNumbers[3] = {0,0,0}; //ending, bifurcation, nothing
leftOutputPath = this->outputPath + QString::number(actBlockSize) + "x" + QString::number(actBlockSize);
rightOutputPath = img.key().left(img.key().lastIndexOf("."));
dir.mkpath(leftOutputPath + "/orig/rot0/" + rightOutputPath);
dir.setPath(leftOutputPath + "/orig/rot0/" + rightOutputPath);
for (auto i : dir.entryList()) {
if (i.contains("end")) fileNumbers[0]++;
else if (i.contains("bif")) fileNumbers[1]++;
else if (i.contains("not")) fileNumbers[2]++;
}
for (auto block : img.value()) {
leftImgName = leftOutputPath + "/orig/rot0/" + rightOutputPath + "/" + QString::number(actBlockSize);
if (std::get<1>(block)[0].toLower() == 'e') rightImgName = img.key().left(img.key().lastIndexOf(".")) + "_" + std::get<1>(block).left(3).toLower() + "_" + QString::number(fileNumbers[0]++) + outputFormat.mid(1).toLower();
else if (std::get<1>(block)[0].toLower() == 'b') rightImgName = img.key().left(img.key().lastIndexOf(".")) + "_" + std::get<1>(block).left(3).toLower() + "_" + QString::number(fileNumbers[1]++) + outputFormat.mid(1).toLower();
else if (std::get<1>(block)[0].toLower() == 'n') rightImgName = img.key().left(img.key().lastIndexOf(".")) + "_" + std::get<1>(block).left(3).toLower() + "_" + QString::number(fileNumbers[2]++) + outputFormat.mid(1).toLower();
fpImg.load(this->inputPath + "/" + img.key());
fpImg = fpImg.convertToFormat(QImage::Format_Grayscale8);
blockOrig = fpImg.copy(QRect(std::get<0>(block).x() - actBlockSize/2, std::get<0>(block).y() - actBlockSize/2, actBlockSize, actBlockSize));
blockOrig.save(leftImgName + "_orig_rot0_" + rightImgName);
if (blur) {
dir.mkpath(leftOutputPath + "/blur/rot0/" + rightOutputPath);
leftImgName = leftOutputPath + "/blur/rot0/" + rightOutputPath + "/" + QString::number(actBlockSize);
blockBlur = this->blurBlock(blockOrig, blurValue);
blockBlur.save(leftImgName + "_blur_rot0_" + rightImgName);
}
if (irisBlur) {
dir.mkpath(leftOutputPath + "/irisblur/rot0/" + rightOutputPath);
leftImgName = leftOutputPath + "/irisblur/rot0/" + rightOutputPath + "/" + QString::number(actBlockSize);
blockIrisBlur = this->irisBlurBlock(blockOrig, irisBlurValue, irisRadiusValue);
blockIrisBlur.save(leftImgName + "_irisblur_rot0_" + rightImgName);
}
if (rotations) {
for (int rot = 90; rot < 360; rot += 90) {
leftImgName = leftOutputPath + "/orig/rot" + QString::number(rot) + "/" + rightOutputPath + "/" + QString::number(actBlockSize);
dir.mkpath(leftOutputPath + "/orig/rot" + QString::number(rot) + "/" + rightOutputPath);
rotateBlock(blockOrig, rot).save(leftImgName + "_orig_rot" + QString::number(rot) + "_" + rightImgName);
if (blur) {
leftImgName = leftOutputPath + "/blur/rot" + QString::number(rot) + "/" + rightOutputPath + "/" + QString::number(actBlockSize);
dir.mkpath(leftOutputPath + "/blur/rot" + QString::number(rot) + "/" + rightOutputPath);
rotateBlock(blockBlur, rot).save(leftImgName + "_blur_rot" + QString::number(rot) + "_" + rightImgName);
}
if (irisBlur) {
leftImgName = leftOutputPath + "/irisblur/rot" + QString::number(rot) + "/" + rightOutputPath + "/" + QString::number(actBlockSize);
dir.mkpath(leftOutputPath + "/irisblur/rot" + QString::number(rot) + "/" + rightOutputPath);
rotateBlock(blockIrisBlur, rot).save(leftImgName + "_irisblur_rot" + QString::number(rot) + "_" + rightImgName);
}
}
}
}
//Progress bar update
currentFile += img.value().size();
if ((int)(((currentFile*1.0) / (allFile*additionalBlocks*2)) * 100) > saveProgress) {
saveProgress = (int)(((currentFile*1.0) / (allFile*additionalBlocks*2)) * 100);
emit updateProgressBarSignal(this->objectName(), saveProgress);
}
}
}
emit updateProgressBarSignal(this->objectName(), 0);
emit blocksSaved();
this->minutiae.clear();
this->images.clear();
emit updateMinutiaeMarkerSceneSignal("remove");
}