-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·59 lines (48 loc) · 2.14 KB
/
Copy pathmain.cpp
File metadata and controls
executable file
·59 lines (48 loc) · 2.14 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
#include <cmath>
#include "glcm.h"
#include "CVMatlabInterface.h"
#include <chrono>
#define WINDOW_SIZE 10
#define defaultNumLevels 256
int main(int argc, char* argv[]){
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
//Reading image
Mat img = imread(argv[1]);
if(img.empty()){
cout << "No image!";
return 0;
}
//Change to gray scale image
cvtColor(img, img, COLOR_BGR2GRAY);
//Getting number of levels
int numLevels = defaultNumLevels;
if (argc > 2) numLevels = atoi(argv[2]);
// Normalizing
float slope = float(numLevels) / 256; // we calculate the inverse of the number of points that should correspond to each new quantization level
for(int i = 0; i < img.rows; i++){
for(int j = 0; j < img.cols; j++){
float new_level = slope * img.at<uint8_t>(i,j);
img.at<uint8_t>(i,j) = floor(new_level);
}
}
//Getting dimensions of texture images
int numberOfWindowsX = img.cols - WINDOW_SIZE + 1;//Without padding and with stride 1
int numberOfWindowsY = img.rows - WINDOW_SIZE + 1;
//Initialization of the texture images
int sizeOfImgResult = numberOfFeaturesToBeUsed * numberOfWindowsY * numberOfWindowsX;
double imgResult[sizeOfImgResult];
int dimImgResult[3] = {numberOfFeaturesToBeUsed, numberOfWindowsY, numberOfWindowsX};
for (int j=0; j<numberOfWindowsY; j++){
for (int i=0; i<numberOfWindowsX; i++){
Mat ROI = img(Range(j, j+WINDOW_SIZE), Range(i, i+WINDOW_SIZE));
glcm(ROI, numLevels, j, i, imgResult, dimImgResult);
}
}
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> diffTime = end - start;
std::cout << "The running time of this script is: "<<diffTime.count() << " milliseconds."<<endl;
double average_time_per_win = diffTime.count()*1000/(numberOfWindowsX*numberOfWindowsY);
std::cout << "The processing speed of this script is: "<<average_time_per_win << " microseconds."<<endl;
saveFloatImageAsMatFile(imgResult, numberOfFeaturesToBeUsed, numberOfWindowsY, numberOfWindowsX);
return 0;
}