forked from satu0king/ImageProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.cpp
More file actions
213 lines (193 loc) · 6.22 KB
/
tasks.cpp
File metadata and controls
213 lines (193 loc) · 6.22 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
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
#include "Color.h"
#include "Histogram.h"
#include "Image.h"
#include "Image_64.h"
#include "MirrorImage.h"
#include "Pixel.h"
#include "PrimitiveSquareImage.h"
#include "ScaledImage.h"
#include "SpecialImage.h"
#include "connected_components.h"
#include "noise.h"
#include <cmath>
#include <fstream>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
void IMT2016124(char const *file) {
cout << "IMT2016124: Running task 8 " << endl;
Image k(file);
noise *np = new noise(k.width(), k.height());
np->write("noising.ppm");
np->compositemage(k, 0.2);
np->write("composit.ppm");
Histogram h(k, 3, 10);
h.renderHistogram("mama.ppm");
int height = np->height();
int width = np->width();
vector<int> v = h.findThresholds();
Image C =
SpecialImage(k).binarize(v[1], Color(0, 0, 0), Color(255, 255, 255));
C.write("binarymama.ppm");
Connected_Components connected_components(width, height);
connected_components.identify_labels(C,"output_task<8>_imt<2016124>.ppm");
cout << "IMT2016124: Completed task 8 " << endl << endl;
}
void IMT2016037(char const *file) {
cout << "IMT2016037: Running task 6 " << endl;
Image I037(file);
Histogram h(I037, 3, 10);
h.renderHistogram("IMT2016037-histogram.ppm");
vector<int> v = h.findThresholds();
int height = I037.height();
int width = I037.width();
int median_threshold;
if (v.size() % 2 == 0) {
median_threshold = (v[(v.size() / 2)] + v[(v.size() / 2) - 1]) / 2;
} else {
median_threshold = (v[(v.size() / 2) + 1]) / 2;
}
Image C = SpecialImage(I037).binarize(median_threshold, Color(0, 0, 0),
Color(255, 255, 255));
C.write("IMT2016037(binarized-image)-C.ppm");
Connected_Components connected_components(width, height);
connected_components.identify_labels(C,"output_task<6>_imt<2016037>.ppm");
cout << "IMT2016037: Completed task 6 " << endl << endl;
}
void IMT2016085(char const *file) {
cout << "IMT2016085: Running task 7 \n";
Image im(file);
ScaledImage sim(im);
sim.write("IMT2016085-1st.ppm");
MirrorImage msimx(im);
MirrorImage msimy(msimx);
msimx.MirrorX(sim);
msimy.MirrorY(msimx);
PrimitiveSquareImage pima(msimy);
msimx.write("IMT2016085-2nd.ppm");
msimy.write("IMT2016085-3nd.ppm");
pima.write("output_task<7>_imt<2016085>.ppm");
cout << "IMT2016085: Completed task 7\n\n";
}
void IMT2016105(char const *file) {
cout << "IMT2016105: Running task 1 " << endl;
Image I1051(file);
Image I1052(file);
int width = I1051.width();
int height = I1051.height();
// creating hole1//e min(floor(image_width*0.125), floor(image_height*0.125))
float cx1 = width / 4;
float cy1 = height / 4;
float cx2 = (width / 4) * 3;
float cy2 = height / 4;
float cx3 = width / 4;
float cy3 = (height / 4) * 3;
float cx4 = (width / 4) * 3;
float cy4 = (height / 4) * 3;
float r = min((width * 0.125), (height * 0.125));
Color w(255, 255, 255);
// clipping
for (int i = 0; i < height / 2; i++) {
for (int j = 0; j < width / 2; j++) {
if (pow(pow(i - cy1, 2) + pow(j - cx1, 2), 0.5) > r) {
I1051.set_color(i, j, w);
}
}
}
for (int i = 0; i < height / 2; i++) {
for (int j = width / 2; j < width; j++) {
if (pow(pow(i - cy2, 2) + pow(j - cx2, 2), 0.5) > r) {
I1051.set_color(i, j, w);
}
}
}
for (int i = height / 2; i < height; i++) {
for (int j = 0; j < width / 2; j++) {
if (pow(pow(i - cy3, 2) + pow(j - cx3, 2), 0.5) > r) {
I1051.set_color(i, j, w);
}
}
}
for (int i = height / 2; i < height; i++) {
for (int j = width / 2; j < width; j++) {
if (pow(pow(i - cy4, 2) + pow(j - cx4, 2), 0.5) > r) {
I1051.set_color(i, j, w);
}
}
}
I1051.write("IMT2016105-C.ppm");
I1052 = SpecialImage(I1052).reflectHorizontal();
// stenciling
for (int i = 0; i < height / 2; i++) {
for (int j = 0; j < width / 2; j++) {
if (pow(pow(i - cy1, 2) + pow(j - cx1, 2), 0.5) < r) {
I1052.set_color(i, j, w);
}
}
}
for (int i = 0; i < height / 2; i++) {
for (int j = width / 2; j < width; j++) {
if (pow(pow(i - cy2, 2) + pow(j - cx2, 2), 0.5) < r) {
I1052.set_color(i, j, w);
}
}
}
for (int i = height / 2; i < height; i++) {
for (int j = 0; j < width / 2; j++) {
if (pow(pow(i - cy3, 2) + pow(j - cx3, 2), 0.5) < r) {
I1052.set_color(i, j, w);
}
}
}
for (int i = height / 2; i < height; i++) {
for (int j = width / 2; j < width; j++) {
if (pow(pow(i - cy4, 2) + pow(j - cx4, 2), 0.5) < r) {
I1052.set_color(i, j, w);
}
}
}
I1052.write("IMT2016105-D.ppm");
// clubbing two images
Image composite = (I1051 * 0.5) + (I1052 * 0.5);
composite.write("output_task<1>_imt<2016105>.ppm");
cout << "IMT2016105: Completed task 1\n\n";
}
void IMT2016064(char const *file) {
cout << "IMT2016064: Running task 2 \n";
Image im(file);
Image inv = SpecialImage(im).reflectHorizontal();
inv.write("IMT2016064-A.ppm");
vector<Index_t> min_px = Image_64(inv).min_pix_arr();
// cout << "Size = " << min_px.size() << endl;
Image_64 im_24 = Image_64(inv).image_24(min_px);
im_24.write("IMT2016064-B.ppm");
Image im_gsf = im_24.gaussian_filter(min_px);
im_gsf.write("IMT2016064-C.ppm");
Image result = SpecialImage(im_gsf, inv, 0.75);
result.write("output_task<2>_imt<2016064>.ppm");
cout << "IMT2016064: Completed task 2\n\n";
}
void IMT2016008(char const *file) {
cout << "IMT2016008: Running task 5 " << endl;
Image I1(file);
Histogram h(I1, 3, 10);
h.renderHistogram("IMT2016008-histogram.ppm");
vector<int> v = h.findThresholds();
if (v.size() >= 2) {
Image C = SpecialImage(I1).binarize(v[0], Color(0, 0, 255));
Image D = SpecialImage(I1).binarize(v[1], Color(0, 255, 255));
C.write("IMT2016008-C.ppm");
D.write("IMT2016008-D.ppm");
SpecialImage result(D, C, 0.2);
result.write("output_task<5>_imt<2016008>.ppm");
} else {
Image C = SpecialImage(I1).reflectVertical();
Image D = SpecialImage(I1).reflectHorizontal();
C.write("IMT2016008-C.ppm");
D.write("IMT2016008-D.ppm");
SpecialImage result(D, C, 0.2);
result.write("IMT2016008.ppm");
}
cout << "IMT2016008: Completed task 5 " << endl << endl;
}