Reading of JPEG Images
15 ビュー (過去 30 日間)
古いコメントを表示
Hi All,
I have compared the image reading function of Photoshop and Matlab applied to jpg images and I have found a difference between them. For the comparison, I have first opened a jpg image with Photoshop and saved in png. Then, I have opened the jpg and png images with Matlab and I have computed the absolute difference between them. I have found that more than half of the pixels are different, with a maximal difference equal to 41. How could it be possible? which image reading function should I trust?
You can find the images in the attachment.
Best,
Simone
0 件のコメント
回答 (2 件)
Ameer Hamza
2020 年 4 月 25 日
It is not a matter of which to trust. This is the expected behavior. No image format saves the RGB intensity of every individual pixel. They use different methods to efficiently compress the image data so that the original image can be constructed from the compressed information. The purpose of image compression formats is not to save pixel-level information; rather, they are designed so that the overall appearance of the image remains the same.
JPEG format uses lossy compression: https://en.wikipedia.org/wiki/JPEG, which implies that if you compress an image using JPEG, some of the information in the original image is permanently lost. On the other hand, PNG is a lossless compression format: https://en.wikipedia.org/wiki/Portable_Network_Graphics, it retains all the information in the original image. Since PNG is a lossless format, therefore if the same image saved in JPEG and PNG, then the PNG file will have a larger size.
As you can see, the JPEG was never intended to save pixel-level information, therefore, If you compare both image pixel by pixel, you can see large variations at some points, but, overall, the appearance of the image is same. It is a tradeoff between retaining the image quality and making a file size smaller.
2 件のコメント
Walter Roberson
2020 年 4 月 25 日
No image format saves the RGB intensity of every individual pixel
... To be technically correct, the PPM file format stores RGB images with no compression at all. The data is also represented as text, rather than binary: the design intent was to make it text-only to prove a way to communicate between systems that might disagree on how to transfer binary files (for example a PPM file could be used on an EBCDIC computer.)
Simone Croci
2020 年 4 月 25 日
7 件のコメント
Ameer Hamza
2020 年 4 月 25 日
Yes, MATLAB and GIMP may be using the same decoding algorithms. But the underlying reason is the different implementation of decoders across libraries.
Just as a side note, the results posted by Stephen does seem to be a rare coincidence. It tried counting the unique colors in several other jpg images using MATLAB and imageio, and the number is never the same. For example,
MATLAB:
>> JPG = imread('lena10.jpg');
>> size(unique(reshape(JPG,[],3),'rows'))
ans =
51606 3
imageio:
>>> JPG = imageio.imread('lena10.jpg')
>>> len(np.unique(JPG.reshape(-1, JPG.shape[-1]), axis=0))
45359
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!