2016-07-27 68 views
0

在此代码中,我将图像作为输入并输出相同的图像。据我所知,如果两幅图像相同,那么它们的PSNR值将是inf。所以我使用MATLAB来计算他们的PSNR值,但它显示了48.05,这意味着这些图像不一样。但我读和写相同的图像,为什么发生这种情况。我该如何解决它?Java中的图像输入输出

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(); 
    } 
} 

回答

1

JPGlossy格式,您将会失去信息读取它,并在每次保存的时间写出来。

也许尝试使用非有损格式,如PNG或GIF。

+0

让我知道如果它为png格式 –

+0

由于同样的,它的PNG格式 –

+0

凉爽的工作,你介意打绿色的勾号? –

1

对了,Salman评论,无损压缩,文件中最初的每一点数据在未压缩后都会保留。这通常用于可能丢失信息的txt文档或电子表格文件,例如财务数据。 PNG或GIF使用无损压缩。 使用损失压缩的优势是什么?它通过删除冗余信息使文件变小。通常用户不会注意到它,并用于声音和视频。 JPEG使用有损压缩,通常创作者可以决定在文件大小和图像质量之间进行折衷时要引入多少损失。

取材大多来自:http://whatis.techtarget.com/definition/lossless-and-lossy-compression