在这段代码中,我将一张图像作为输入并输出相同的图像。据我所知,如果两个图像是相同的,那么它们的PSNR值将是inf。所以我用MATLAB计算了他们的PSNR值,但结果是48.05,这意味着这些图像是不一样的。但我读写了同样的图像,为什么会发生这种情况。我怎么才能修复它?
public class ImageProcessing {
BufferedImage image = null;
int width;
int height;
public ImageProcessing() {
// Input the image
try {
File input = new File("image0.jpg");
image = ImageIO.read(input);
width = image.getWidth();
height = image.getHeight();
/*int count = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
count++;
Color c = new Color(image.getRGB(j, i));
System.out.println("S.No: " + count + " Red: " + c.getRed() + " Green: " + c.getGreen() + " Blue: " + c.getBlue());
}
}*/
} catch (Exception e) {
System.out.println("Error: " + e);
}
// Output the image
try {
File input = new File("image1.jpg");
ImageIO.write(image, "jpg", input);
System.out.println("Writing complete.");
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
public static void main(String[] args) {
// TODO code application logic here
System.out.println("System Start");
ImageProcessing obj = new ImageProcessing();
}
}发布于 2016-07-27 22:59:09
JPG是一种lossy格式,每次保存时读入和写出都会丢失信息。
也许可以尝试使用无损格式,如PNG或GIF。
发布于 2016-07-27 23:23:43
是的,从Salman的评论来看,在无损压缩的情况下,文件中原来的每一位数据在解压缩后都会保留下来。这通常用于txt文档或电子表格文件,其中的信息可能会丢失,如财务数据。PNG或GIF使用无损压缩。使用有损压缩的优势是什么?它通过删除冗余信息使文件变得更小。通常情况下,用户不会注意到它,并在声音和视频中使用。JPEG使用有损压缩,通常创建者可以决定在文件大小和图像质量之间权衡引入多少损失。
主要来自:http://whatis.techtarget.com/definition/lossless-and-lossy-compression
https://stackoverflow.com/questions/38616493
复制相似问题