Reputation: 45
I've been doing some work with images captured from a CMOS image sensor and saved to YUV422. I've converted them to TIFF and PNG formats using both ImageMagick and FFMPEG and done some analysis of the images and noticed that the RGB values differ between the two image formats. I'm a little confused as to why as they're both lossless formats and the images are in the sRGB colourspace (verified with ImageMagick 'identify' command). Do they not use the same YCbCr->sRGB conversion algorithm? Am I missing something about the conversion process?
I used the following commands to convert the images:
ffmpeg -pix_fmt uyvy422 -s 972x972 -i input.yuv output.png
ffmpeg -pix_fmt uyvy422 -s 972x972 -i input.yuv output.tiff
magick -size "972x972" pal:input.yuv output.png
magick -size "972x972" pal:input.yuv output.tiff
Upvotes: 3
Views: 1409
Reputation: 32094
I think I found the reason for the differences:
The PNG output image is saved in RGB format, and the TIFF output image is saved in YUV422 format.
I used the following commands for creating uncompressed images (no LZW lossless compression):
ffmpeg -y -pix_fmt uyvy422 -s 972x972 -i input.yuv -compression_level 0 output.png
ffmpeg -y -pix_fmt uyvy422 -s 972x972 -i input.yuv -compression_algo raw output.tiff
Size of output.tiff: 1,891,802 Bytes (about 972*972*2).
Size of output.png: 2,844,142 Bytes (about 972*972*3).
The conversion formula and the interpolation method used by FFmpeg
and the viewer has minor differences.
That probably means you may get different results from different viewers when displaying the Tiff image.
In order to avoid the differences, you can force FFmpeg to convert images to RGB:
ffmpeg -pix_fmt uyvy422 -s 972x972 -i input.yuv -pix_fmt rgb24 output.png
ffmpeg -pix_fmt uyvy422 -s 972x972 -i input.yuv -pix_fmt rgb24 output.tiff
Now the PNG and TIFF are identical.
Upvotes: 2