-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinTest.java
More file actions
37 lines (29 loc) · 821 Bytes
/
BinTest.java
File metadata and controls
37 lines (29 loc) · 821 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
33
34
35
36
37
package com.briup.knn;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.imageio.ImageIO;
public class BinTest {
public static void main(String[] args) throws FileNotFoundException, IOException {
//BufferedImage
BufferedImage img=ImageIO.read(new FileInputStream("src/0_13.png"));
int height=img.getHeight();
int width=img.getWidth();
for(int i=0;i<height;i++) {
for(int j=0;j<width;j++) {
int rgb = img.getRGB(j, i);
Color gray=new Color(127, 127, 127);
int g_rgb=gray.getRGB();
if (rgb<g_rgb) {
System.out.print("0");
}
else {
System.out.print("1");
}
}
System.out.println();
}
}
}