我想找到图像的每个像素,然后我会得到总像素值,然后我会找到平均值。我比较每个像素值与我得到的平均值,如果它> 255,像素值将变为1(代表黑色),如果< 255则变为0(代表白色)。之后,我设置新的RGB颜色,并绘制输出图像。 Input在java中的图像平均阈值
基于我的理念,我认为输出图像是黑白图像,但它只是显示黑色。 Output
public class Imej {
public void mapping(BufferedImage image) throws IOException {
BufferedImage binary = new BufferedImage(image.getWidth(),
image.getHeight(), BufferedImage.TYPE_BYTE_BINARY);
int i, j;
int w = image.getWidth();
int h = image.getHeight();
image.setRGB(i, j, new Color(pixel[i][j]).getRGB());
ImageIO.write(binary,"png",output);
}
}
这是readimage
。
public void readimage() {
BufferedImage image = null;
File f = null;
try {
image = ImageIO.read(new File(/** path **/));
//System.out.println(image);
mapping(image);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public static void main(String[] args) {
Imej a = new Imej();
a.readimage();
}
你的意思'225',或者你的意思'255'?或者,你的意思是'w'还是'h'取决于上下文? –
是255 ......... – kenreal
您的当前*输入图像为300x300。 –