-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final project code
120 lines (102 loc) · 2.91 KB
/
Final project code
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
#include <Magick++.h>
#include <iostream>
#include <cmath>
using namespace std;
using namespace Magick;
void grayscale (string n){
Image image;
image.read( n );
int x = image.rows();
int z = image.columns();
Color image_array [x] [z];
Color image_array2 [x] [z];
Color myfirst;
Color second;
Color newRGB;
Color newRGB2;
int g;
for (int i=0; i < x; i++){
for (int u = 0; u < z; u++){
myfirst = image.pixelColor(u,i);
image_array [i][u] = myfirst;
}
}
for (int i=0; i < x; i++){
for (int u = 0; u < z; u++){
second = image_array [i] [u];
g = (second.redQuantum()+second.greenQuantum()+second.blueQuantum())/3;
newRGB.redQuantum(g);
newRGB.greenQuantum(g);
newRGB.blueQuantum(g);
image_array2 [i] [u] = newRGB;
}
}
for (int i=0; i < x; i++){
for (int u = 0; u < z; u++){
newRGB2 =image_array2 [i] [u];
image.pixelColor(u, i, newRGB2);
}
}
image.write( "x.JPG" );
}
void scale(string n){
Image image2;
image2.read( n );
int x = image2.rows();
int z = image2.columns();
int x2 = x/2;
int z2 = z/2;
Image image3( Geometry(z2, x2), Color(MaxRGB, MaxRGB, MaxRGB, 0));
Color image_array [x] [z];
Color image_array2 [x2] [z2];
Color pixel1, pixel2, pixel3, pixel4, pixel5;
int red,blue,green;
Color newRGB, newRGB2;
for (int i=0; i < x; i++){
for (int u = 0; u < z; u++){
pixel1 = image2.pixelColor(u,i);
image_array [i][u] = pixel1;
}
}
for (int i=0; i < x; i = i+2){
for (int u = 0; u < z; u = u+2){
int y = i/2;
int t = u/2;
pixel2 = image_array [i] [u];
pixel3 = image_array [i+1] [u];
pixel4 = image_array [i] [u+1];
pixel5 = image_array [i+1] [u+1];
red = (pixel2.redQuantum() + pixel3.redQuantum() + pixel4.redQuantum() + pixel5.redQuantum())/4;
blue = (pixel2.blueQuantum() + pixel3.blueQuantum() + pixel4.blueQuantum() + pixel5.blueQuantum())/4;
green = (pixel2.greenQuantum() + pixel3.greenQuantum() + pixel4.greenQuantum() + pixel5.greenQuantum())/4;
newRGB.redQuantum(red);
newRGB.greenQuantum(green);
newRGB.blueQuantum(blue);
image_array2 [y] [t] = newRGB;
}
}
for (int i=0; i < x2; i++){
for (int u = 0; u < z2; u++){
newRGB2 =image_array2 [i] [u];
image3.pixelColor(u, i, newRGB2);
}
}
image3.write( "y.JPG" );
}
int main(int argc,char **argv)
{
InitializeMagick(*argv);
try {
string File;
cout << "type the name of the image: ";
cin >> File;
grayscale(File);
scale(File);
}
catch( Exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
return 0;
}