-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGrayConvertProcess.java
31 lines (30 loc) · 1.23 KB
/
GrayConvertProcess.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
import javax.media.jai.*;
import java.awt.color.ColorSpace;
import java.awt.image.RenderedImage;
/**
* This class can convert a colored image to grayscale.
*
* @author Christopher Sasarak
*/
public class GrayConvertProcess implements ImageProcess{
/**
* This method will make an image GrayScale.
*
* @param img A RenderedImage to operate on.
* @return RenderedImage The new grayscale image.
*/
public RenderedImage process(RenderedImage img){
/**
* This matrix is for converting the image to grayscale.
* There is one destination band and n source bands ( [0][1..n] ).
* The double values are what we multiply the source pixels bands by
* to get their ultimate value, which are then combined into the single band
* of the output. The last item in the second part of the array is a constant
* value that will be added to the destination band. I have set it to 0 so
* it has no effect.
* The values I used are from this website: http://www.johndcook.com/blog/2009/08/24/algorithms-convert-color-grayscale/
*/
double[][] matrix = {{.21, .71, 0.07, 0.0}};
return JAI.create("bandcombine", img, matrix, null);
}
}