-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGrayscale.java
More file actions
32 lines (26 loc) · 832 Bytes
/
Grayscale.java
File metadata and controls
32 lines (26 loc) · 832 Bytes
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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package image2d;
import java.awt.image.BufferedImage;
/**
*
* @author pratchaya
*/
public class Grayscale {
public static BufferedImage apply(BufferedImage _image) {
BufferedImage imageOutput = Unitys.copyImage(_image);
int grayscale;
for (int i = 0; i < _image.getWidth(); i++) {
for (int j = 0; j < _image.getHeight(); j++) {
int rgb;
int p = RGB.getRGBW(_image, i, j);
rgb = (int) ((((p >> 16) & 0xFF) * 0.2125) + (((p >> 8) & 0xFF) * 0.7154) + ((p & 0xFF) * 0.0721));
rgb = (rgb << 16) | (rgb << 8) | (rgb);
imageOutput.setRGB(i, j, rgb);
}
}
return imageOutput;
}
}