-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
134 lines (105 loc) · 5.33 KB
/
main.cpp
File metadata and controls
134 lines (105 loc) · 5.33 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
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>
#include <windows.h>
#include <math.h>
#include "omp.h"
#include <chrono>
#include "filter.h"
#define THREAD_COUNT 8 // You can change the number of thread to see the differences between them !!!
using namespace std;
void serialMeanFilter(const LPCTSTR input, const LPCTSTR output, const short maskSize);
void paralelMeanFilter(const LPCTSTR input, const LPCTSTR output, const short maskSize);
void serialEdgeDetection(const LPCTSTR input, const LPCTSTR output);
void paralelEdgeDetection(const LPCTSTR input, const LPCTSTR output);
int _tmain(int argc, _TCHAR* argv[]){
LPCTSTR inputImage, outputImage;
omp_set_num_threads(THREAD_COUNT);
omp_set_nested(1);
// You must change the paths to your directory !!!
inputImage = L"C://Users/Enes/Desktop/IMAGE_PROCESS/babamlar.bmp";
outputImage = L"C://Users/Enes/Desktop/IMAGE_PROCESS/babamSmoothParalel.bmp";
////*****************************************////
const short maskSize = 7; // You can change the mask size which must be odd numbers.
paralelMeanFilter(inputImage, outputImage, maskSize);
paralelEdgeDetection(outputImage, outputImage);
getchar();
return 0;
}
void serialMeanFilter(const LPCTSTR input, const LPCTSTR output, const short maskSize){
int width = 0, height = 0;
long Size, new_size;
BYTE* buffer = LoadBMP(&width, &height, &Size, input);
BYTE* rawIntensity = ConvertBMPToIntensity(buffer, width, height);
delete []buffer;
auto starTimer = chrono::high_resolution_clock::now();
BYTE * serialFilter = smoothingSerial(rawIntensity, maskSize, width, height);
auto finishTimer = std::chrono::high_resolution_clock::now();
auto elapsedTime = finishTimer - starTimer;
printf("Elapsed Time for Serial Smoothing %5d milliseconds\n", chrono::duration_cast<std::chrono::milliseconds>(elapsedTime).count());
BYTE* serialResult = ConvertIntensityToBMP(serialFilter, width, height, &new_size);
delete[] serialFilter;
if (SaveBMP(serialResult, width, height, new_size, output))
cout << " Output Image was successfully saved" << endl;
else cout << "Error on saving image" << endl;
delete[] serialResult;
}
void paralelMeanFilter(const LPCTSTR input, const LPCTSTR output, const short maskSize){
int width = 0, height = 0;
long Size, new_size;
BYTE* buffer = LoadBMP(&width, &height, &Size, input);
BYTE* rawIntensity = ConvertBMPToIntensity(buffer, width, height);
delete[] buffer;
auto starTimer = chrono::high_resolution_clock::now();
BYTE * paralelFilter = smoothingParalel(rawIntensity, maskSize, width, height);
auto finishTimer = std::chrono::high_resolution_clock::now();
auto elapsedTime = finishTimer - starTimer;
printf("Elapsed Time for Parallel Smothing %5d milliseconds\n", chrono::duration_cast<std::chrono::milliseconds>(elapsedTime).count());
delete[] rawIntensity;
BYTE* paralelResult = ConvertIntensityToBMP(paralelFilter, width, height, &new_size);
if (SaveBMP(paralelResult, width, height, new_size, output))
cout << " Output Image was successfully saved" << endl;
else cout << "Error on saving image" << endl;
delete[] paralelFilter;
delete[] paralelResult;
}
void serialEdgeDetection(const LPCTSTR input, const LPCTSTR output){
int width = 0, height = 0;
long Size, new_size;
BYTE* buffer = LoadBMP(&width, &height, &Size, input);
BYTE* rawIntensity = ConvertBMPToIntensity(buffer, width, height);
delete[]buffer;
float *angles = new float[width*height]; // Gradient Angles If you wanna use
auto starTimer = chrono::high_resolution_clock::now();
BYTE *gradientSerial = edgeDetectionSerial(rawIntensity, width, height, angles);
auto finishTimer = std::chrono::high_resolution_clock::now();
auto elapsedTime = finishTimer - starTimer;
printf("Elapsed Time for Serial Edge Detection %5d milliseconds\n", chrono::duration_cast<std::chrono::milliseconds>(elapsedTime).count());
delete[] rawIntensity;
BYTE* gradientResultS = ConvertIntensityToBMP(gradientSerial, width, height, &new_size);
if (SaveBMP(gradientSerial, width, height, new_size, output))
cout << " Gradient Image Serial was successfully saved" << endl;
else cout << "Error on saving image" << endl;
delete[] gradientSerial;
delete[] gradientResultS;
delete[] angles;
}
void paralelEdgeDetection(const LPCTSTR input, const LPCTSTR output){
int width = 0, height = 0;
long Size, new_size;
BYTE* buffer = LoadBMP(&width, &height, &Size, input);
BYTE* rawIntensity = ConvertBMPToIntensity(buffer, width, height);
delete[]buffer;
float *angles = new float[width*height]; // Gradient Angles If you wanna use
auto starTimer = chrono::high_resolution_clock::now();
BYTE *gradientParalel = edgeDetectionParalel(rawIntensity, width, height, angles);
auto finishTimer = std::chrono::high_resolution_clock::now();
auto elapsedTime = finishTimer - starTimer;
printf("Elapsed Time for Paralel Edge Detection %5d milliseconds\n", chrono::duration_cast<std::chrono::milliseconds>(elapsedTime).count());
delete[] rawIntensity;
BYTE* gradientResultP = ConvertIntensityToBMP(gradientParalel, width, height, &new_size);
if (SaveBMP(gradientResultP, width, height, new_size, output))
cout << " Gradient Image Parallel was successfully saved" << endl;
else cout << "Error on saving image" << endl;
delete[] gradientParalel;
delete[] gradientResultP;
delete[] angles;
}