1 /**
2 * 获取一张二值化图片3 *@parambufferImg4 *@return
5 */
6 public staticBufferedImage binaryImage(BufferedImage bufferImg){7 int height =bufferImg.getHeight();8 int width =bufferImg.getWidth();9 int rgb = bufferImg.getRGB(0, 0);10 int rgbArray[][] = new int[width][height];11
12 for(int i=0;i
18 int threshold =otsuThreshold(rgbArray, height, width);19
20 BufferedImage bufferedImage=new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);//构造一个类型为预定义图像类型之一的 BufferedImage,TYPE_BYTE_BINARY(表示一个不透明的以字节打包的 1、2 或 4 位图像。)
21
22 for(int i=0;ithreshold){25 int black=new Color(255,255,255).getRGB();26 bufferedImage.setRGB(i, j, black);27 }else{28 int white=new Color(0,0,0).getRGB();29 bufferedImage.setRGB(i, j, white);30 }31 }32 }33
34 try{35 ImageIO.write(bufferedImage, "jpg", new File("D:"+File.separat