我需要将灰度图像的像素强度数据的二维数组转换回图像。我试过这个:
BufferedImage img = new BufferedImage(
regen.length, regen[0].length, BufferedImage.TYPE_BYTE_GRAY);
for(int x = 0; x < regen.length; x++){
for(int y = 0; y<regen[x].length; y++){
img.setRGB(x, y, (int)Math.round(regen[x][y]));
}
}
File imageFile = new File("D:\\img\\conv.bmp");
ImageIO.write(img, "bmp", imageFile);
其中“regen”是一个二维双数组。我得到一个相似但不准确的输出。很少有像素与它必须是完全相反的(对于值为 255 的像素,我得到黑色)。很少有灰色阴影也被视为白色。你能告诉我我在做什么错误吗?