-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImageEditor.java
More file actions
executable file
·110 lines (84 loc) · 2.14 KB
/
Copy pathImageEditor.java
File metadata and controls
executable file
·110 lines (84 loc) · 2.14 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
import java.awt.Color;
public class ImageEditor
{
public static Color colorFromGrey(int grey)
{
return new Color(grey,grey,grey);
}
public static int greyFromColor(Color c)
{
int grey = (int) (c.getRed() + c.getGreen() + c.getBlue())/3;
return grey;
}
public static Picture makeGreyscale(Picture p)
{
Picture newP = new Picture(p.width(),p.height());
int y = 0;
for (int i = 0; i < p.width(); i++)
{
for (int j = 0; j < p.height(); i++)
{
Color colour = p.get(i,j);
y = greyFromColor(colour);
colour = colorFromGrey(y);
newP.set(i,j,colour);
}
}
return newP;
}
public static Picture threshold(Picture p, int thresh)
{
Picture newP = new Picture(p.width(),p.height());
int y = 0;
for (int i = 0; i < p.width(); i++)
{
for (int j = 0; j < p.height(); i++)
{
Color colour1 = p.get(i,j);
y = greyFromColor(colour1);
if ( y > thresh)
{
colour1 = colorFromGrey(y);
newP.set(i,j,colour1);
}
else
{
Color colour_new = new Color(0,0,0);
newP.set(i,j,colour_new);
}
}
}
return newP;
}
public static Picture adjustPicture(Picture p, double adjustR, double adjustG, double adjustB )
{
Picture newP = new Picture(p.width(),p.height());
for (int i = 0; i < p.width(); i++)
{
for (int j = 0; j < p.height(); i++)
{
Color colour2 = p.get(i,j);
int newR = (int) (colour2.getRed() * adjustR);
int newG = (int) (colour2.getGreen() * adjustG);
int newB = (int) (colour2.getBlue() * adjustB);
Color colour_new_again = new Color(newR, newG, newB);
newP.set(i,j,colour_new_again);
}
}
return newP;
}
public static void main(String[] args)
{
Picture p = new Picture("lion2.jpg");
//Picture p = new Picture( "spider.jpg");
p.show();
Picture thres = threshold(p, 140);
thres.show();
Picture greyscale = makeGreyscale(p);
greyscale.show();
Picture redComponent = adjustPicture(p, 1.0,0.0,0.0);
redComponent.show();
//Picture redComponent_grey = makeGreyscale(adjustPicture(p, 0.0,0.0,1.0));
//threshold(redComponent_grey, 35).show();
}
}