I am using opencv module to read and write the image. here is the code and below is the image i am reading and second image is after saving it on disk using
import cv2 img = cv2.imread('originalImage.jpg') cv2.imwrite('test.jpg',img)
It is significantly visible that colors are dull in second image. Is there any workaround to this problem or I am missing on some sort of setting parameters..?
The difference is that the initial image (on the left in the diagram) has an attached ICC profile whereas the second one (on the right) does not.
I obtained the above image by running the ImageMagick utility called
identify like this:
identify -verbose first.jpg > 1.txt identify -verbose second.jpg > 2.txt
Then I ran the brilliant
opendiff tool (which is part of macOS) like this:
You can extract the ICC profile from the first image also with ImageMagick like this:
convert first.jpg profile.icc
Your first input image has some icc-Profile associated in the meta-data, which is an optional attribute and most devices may not inject it in the first place. The ICC profile basically performs a sort of color correction, and the correction coefficients are calculated for each unique device during calibration.
Modern Web Browsers, Image Viewing utilities mainly take into account this ICC profile information before rendering the image onto the screen, that is the reason why there is a diff in both the images.
But Unfortunately OpenCV doesn’t reads the ICC config from the meta data of the image to perform any color correction.
I have done a bit of research on the point @mark raised about ICC profile. I have figured out a way to handle this in python PIL module. here is the code that worked for me. I have also learned to use PNG file format rather JPEG to do lossless conversion.
import Image img = Image.open('originalImage.jpg') img.save('test.jpg',icc_profile=img.info.get('icc_profile'))
I hope this will help others as well.