-
Notifications
You must be signed in to change notification settings - Fork 0
/
EdgeDetect.java
52 lines (47 loc) · 1.48 KB
/
EdgeDetect.java
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
import java.lang.Math;
public class EdgeDetect implements Manipulator {
public void manipulate(ImageBase ib) {
Picture picture = ib.getPicture();
int imageWidth = picture.getWidth();
int imageHeight = picture.getHeight();
double red, blue, green;
Pixel pix, left, bottom;
int lr = 0;
int lb = 0;
int lg = 0;
int br = 0;
int bb = 0;
int bg = 0;
Picture pict = new Picture(imageWidth, imageHeight);
for (int x = 0; x < imageWidth; x++) {
for (int y = 0; y < imageHeight; y++) {
pix = left = bottom = picture.getPixel(x, y);
if (x != 0) {
left = picture.getPixel(x-1, y);
lr = left.getRed() - pix.getRed();
lb = left.getBlue() - pix.getBlue();
lg = left.getGreen() - pix.getGreen();
}
if (y != imageHeight-1) {
bottom = picture.getPixel(x, y+1);
br = bottom.getRed() - pix.getRed();
bb = bottom.getBlue() - pix.getBlue();
bg = bottom.getGreen() - pix.getGreen();
}
red = Math.sqrt((lr*lr)+(br*br));
blue = Math.sqrt((lb*lb)+(bb*bb));
green = Math.sqrt((lg*lg)+(bg*bg));
pix.setRed((int)red);
pix.setGreen((int)green);
pix.setBlue((int)blue);
pict.setPixel(x, y, pix);
}
}
// tells the ImageBase object to display the new Picture.
ib.setPicture(pict);
ib.refresh();
}
public String getManipulationName() {
return "Edge Detect";
}
}