-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
148 lines (125 loc) · 4.75 KB
/
main.cpp
File metadata and controls
148 lines (125 loc) · 4.75 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "filters.h"
#include <iostream>
#include <windows.h>
#include <math.h>
using namespace std;
static void EdgeDetectionWithoutNonmaximum(const LPCTSTR , const LPCTSTR);
static void NonmaximumWithoutDoubleThresholding(const LPCTSTR , const LPCTSTR );
static void CannyEdgeDetection(const LPCTSTR , const LPCTSTR );
static void HoughTransform(const LPCTSTR , const LPCTSTR );
int _tmain(int argc, _TCHAR* argv[])
{
LPCTSTR input, output;
input = L"./input.bmp";
output = L"./output.bmp";
HoughTransform(input, output);
system("PAUSE");
return 0;
}
static void EdgeDetectionWithoutNonmaximum(const LPCTSTR input, const LPCTSTR output){
int width, height;
long Size, new_size;
/* EDGE DETECTION WITHOUT NONMAXIMUM*/
BYTE* buffer = LoadBMP(&width, &height, &Size, input);
BYTE* raw_intensity = ConvertBMPToIntensity(buffer, width, height);
delete[] buffer;
float * angles = new float[width*height];
for (int i = 0; i < width*height; i++) angles[i] = 0;
BYTE* edge = EdgeDetection(raw_intensity, width, height, angles);
delete[] raw_intensity;
char ch;
cout << "Sonucu diske kaydetsin mi? E/H:"; cin >> ch;
if ((ch == 'E') || (ch == 'e')) {
BYTE* display_imge = ConvertIntensityToBMP(edge, width, height, &new_size);
if (SaveBMP(display_imge, width, height, Size, output))
cout << " Output Image was successfully saved" << endl;
else cout << "Error on saving image" << endl;
delete[] display_imge;
}
delete[] edge;
delete[] angles;
}
static void NonmaximumWithoutDoubleThresholding(const LPCTSTR input, const LPCTSTR output){
int width, height;
long Size, new_size;
/*NONMAXIMUM WIHOUT THRESHOLDING*/
BYTE* buffer = LoadBMP(&width, &height, &Size, input);
BYTE* raw_intensity = ConvertBMPToIntensity(buffer, width, height);
delete[] buffer;
float * angles = new float[width*height];
for (int i = 0; i < width*height; i++) angles[i] = 0;
BYTE* edge = EdgeDetection(raw_intensity, width, height, angles);
delete[] raw_intensity;
BYTE * nonmax = NonMaximum(edge, angles, width, height);
delete[] edge;
delete[] angles;
char ch;
cout << "Sonucu diske kaydetsin mi? E/H:"; cin >> ch;
if ((ch == 'E') || (ch == 'e')) {
BYTE* display_imge = ConvertIntensityToBMP(nonmax, width, height, &new_size);
if (SaveBMP(display_imge, width, height, Size, output))
cout << " Output Image was successfully saved" << endl;
else cout << "Error on saving image" << endl;
delete[] display_imge;
}
delete[] nonmax;
delete[] angles;
}
static void CannyEdgeDetection(const LPCTSTR input, const LPCTSTR output){
int width, height;
long Size, new_size;
/*THRESHOLDING WITH CANNY EDGE DETECTION*/
BYTE* buffer = LoadBMP(&width, &height, &Size, input);
BYTE* raw_intensity = ConvertBMPToIntensity(buffer, width, height);
delete[] buffer;
float * angles = new float[width*height];
for (int i = 0; i < width*height; i++)
angles[i] = 0;
BYTE* edge = EdgeDetection(raw_intensity, width, height, angles);
delete[] raw_intensity;
BYTE * nonmax = NonMaximum(edge, angles, width, height);
delete[] edge;
DoubleThresholding(nonmax, width, height, angles, 20, 80);
delete[] angles;
char ch;
cout << "Sonucu diske kaydetsin mi? E/H:"; cin >> ch;
if ((ch == 'E') || (ch == 'e')) {
BYTE* display_imge = ConvertIntensityToBMP(nonmax, width, height, &new_size);
if (SaveBMP(display_imge, width, height, Size, output))
cout << " Output Image was successfully saved" << endl;
else cout << "Error on saving image" << endl;
delete[] display_imge;
}
delete[] nonmax;
}
static void HoughTransform(const LPCTSTR input, const LPCTSTR output){
int width, height;
long Size, new_size;
/* HOUGH TRANSFORM */
BYTE* buffer = LoadBMP(&width, &height, &Size, input);
BYTE* raw_intensity = ConvertBMPToIntensity(buffer, width, height);
delete[] buffer;
float * angles = new float[width*height];
for (int i = 0; i < width*height; i++)
angles[i] = 0;
BYTE* edge = EdgeDetection(raw_intensity, width, height, angles);
BYTE * nonmax = NonMaximum(edge, angles, width, height);
delete[] edge;
DoubleThresholding(nonmax, width, height, angles, 20, 80);
BYTE *hough = HoughTransformLine(nonmax, width, height, 25);
delete[] nonmax;
bool* coloredLines = Colorization(hough, width, height);
delete[] hough;
char ch;
cout << "Sonucu diske kaydetsin mi? E/H:"; cin >> ch;
if ((ch == 'E') || (ch == 'e')) {
BYTE* result = ConvertIntensityToBMP2(raw_intensity, coloredLines, width, height, &new_size);
if (SaveBMP(result, width, height, Size, output))
cout << " Output Image was successfully saved" << endl;
else cout << "Error on saving image" << endl;
delete[] result;
}
delete[]raw_intensity;
delete[]coloredLines;
delete[] angles;
}