We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4dfdf49 commit 684936fCopy full SHA for 684936f
Binarize.java
Monoscaler.java
@@ -0,0 +1,23 @@
1
+/**
2
+ * Convert a grayscale image to a binary image.
3
+ *
4
+ * @author Christopher Sasarak
5
+ */
6
+import javax.media.jai.*;
7
+import java.awt.image.RenderedImage;
8
+
9
+public class Monoscaler implements ImageProcess {
10
+ /**
11
+ * This method accepts a RenderedImage and converts it to
12
+ * binary.
13
14
+ * @param img The source image.
15
+ * @return RenderedImage The image after being processed by the method.
16
17
+ public RenderedImage process(RenderedImage img){
18
+ Histogram hist = (Histogram)JAI.create("histogram", img).getProperty("histogram");
19
+ double[] threshold = hist.getPTileThreshold(0.5);
20
21
+ return JAI.create("binarize", img, new Double(threshold[0]));
22
+ }
23
+}
0 commit comments