-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
executable file
·191 lines (169 loc) · 4.51 KB
/
main.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
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include "Base/color.h"
#include "Base/pixel.h"
#include "Base/image.h"
#include "image_035.h"
#include "ScaledImage.h"
#include "CombinedImage.h"
#include "SquareClip.h"
#include "noise_image.h"
#include "composite_image.h"
#include "binary_image.h"
#include "cc_image.h"
#include "Histogram.h"
using namespace std;
void task2(string);
void task7(string);
void task4(string);
void task8(string);
int main(int argc, char const *argv[])
{
// ifstream file(argv[1]);
// ifstream f_ptr(argv[1]); // Added by VJ
// Image i; // Added by VJ
// f_ptr >> i; // Added by VJ
cout<<"Our group task ID combination is: 2,4,7,8"<<endl;//1,2,4,6,7,8"<<endl;
int task; bool flag = false;
while(true) {
cout << "Enter task ID (0 to exit): ";
cin >> task;
switch(task) {
case 2: {task2(argv[1]); break;}
case 4: {task4(argv[1]); break;}
case 7: {task7(argv[1]); break;}
case 8: {task8(argv[1]); break;}
case 0: {flag = true; break;}
default : {cout << "Task not found!" << endl; break;}
}
if(flag) break;
}
return 0;
}
void task2(string filename) {
ifstream file(filename);
Image_035* image = new Image_035();
file >> *image;
image->set_arr_der();
image->reflection_y();
Pixel** A = image->get_r_arr();
image->min_blue();
image->generate_C();
image->gaussian_filter();
Pixel** C = image->get_r_arr2();
Image* i1 = new Image(image->get_w(),image->get_h());
Image* i2 = new Image(image->get_w(),image->get_h());
i1->set_arr2(C);
i2->set_arr2(A);
// CompositeImage *comp = new CompositeImage(i1,i2,0.75);
// image->set_arr2(comp->get_arr());
composite_image* comp = new composite_image(*i1, *i2, 0.75);
image->set_arr2(comp->get_arr());
std::ofstream outFile("output_task2_imt2016035.ppm");
outFile << *image;
file.close();
outFile.close();
}
void task7(string filename) {
ifstream file(filename);
string mode;
int width,ht,max_val;
file>>mode>>width>>ht>>max_val;
ofstream out6("output_task7_imt2016005.ppm");
// ofstream out61("output_task7_imt2016005a.ppm");
// ofstream out62("output_task7_imt2016005b.ppm");
// ofstream out63("output_task7_imt2016005c.ppm");
// ofstream out64("output_task7_imt2016005d.ppm");
// ofstream out65("output_task7_imt2016005e.ppm");
out6<<mode<<endl<<width<<" "<<ht<<endl<<max_val<<endl;
// out61<<mode<<endl<<width<<" "<<ht<<endl<<max_val<<endl;
// out62<<mode<<endl<<width<<" "<<ht<<endl<<max_val<<endl;
// out63<<mode<<endl<<width<<" "<<ht<<endl<<max_val<<endl;
// out64<<mode<<endl<<width<<" "<<ht<<endl<<max_val<<endl;
// out65<<mode<<endl<<width<<" "<<ht<<endl<<max_val<<endl;
Image *input = new Image(width,ht);
for (int i = 0; i < ht; ++i)
{
for (int j = 0; j < width; ++j)
{
int r,g,b;
file>>r>>g>>b;
input->set_pixel(i,j,r,g,b);
}
}
ScaledImage *sc1 = new ScaledImage(input);
ScaledImage *sc2 = new ScaledImage(input,"A");
ScaledImage *sc3 = new ScaledImage(input,"AB");
ScaledImage *sc4 = new ScaledImage(input,"B");
CombinedImage *ci = new CombinedImage(sc1,sc2,sc3,sc4);
SquareClip *clip = new SquareClip(ci,min(floor(ht/2),floor(width/2)));
// for (int i = 0; i < ht; ++i)
// {
// for (int j = 0; j < width; ++j)
// {
// out61<<sc1->color_at(i,j)<<" ";
// }
// }
// for (int i = 0; i < ht; ++i)
// {
// for (int j = 0; j < width; ++j)
// {
// out62<<sc2->color_at(i,j)<<" ";
// }
// }
// for (int i = 0; i < ht; ++i)
// {
// for (int j = 0; j < width; ++j)
// {
// out63<<sc3->color_at(i,j)<<" ";
// }
// }
// for (int i = 0; i < ht; ++i)
// {
// for (int j = 0; j < width; ++j)
// {
// out64<<sc4->color_at(i,j)<<" ";
// }
// }
// for (int i = 0; i < ht; ++i)
// {
// for (int j = 0; j < width; ++j)
// {
// out65<<ci->color_at(i,j)<<" ";
// }
// }
for (int i = 0; i < ht; ++i)
{
for (int j = 0; j < width; ++j)
{
out6<<clip->color_at(i,j)<<" ";
}
}
file.close();
}
void task4(string input) {
ifstream inputfile(input);
Histogram h;
inputfile >> h;
h.ini_britarr();
h.ini_local_min();
inputfile.close();
Histogram output = h.segmentation();
ofstream outfile("output_task4_imt2016122.ppm");
outfile << output << '\n';
}
void task8(string filename) {
ifstream f_ptr(filename);
Image i;
f_ptr >> i;
noise_image n(i.get_w(), i.get_h());
// cc_image c(CompositeImage(&i, &n, 0.5));
cc_image c(composite_image(i, n, 0.5));
ofstream o_ptr("output_task8_imt2016083.ppm");
o_ptr << c;
f_ptr.close();
}