imwrite changes the channels when saving

asked 2016-04-15 10:03:37 -0600

I'm reading an image and doing some processing on the blue channel without changing the Red nor the green channels.

When i finished processing the blue channel, i merged back the three channels into one RGB image. and when i use imshow to view the channels, every thing is alright and i can see that the changes i've made only affect the Blue channel and they do not affect the red nor the green ones.

Up to this point every thing is alright !

But when i save the image using imwrite, the resulting image is slightly different, in that the changes made on the blue channel seem to get propagated to the red and green channels, it's like imwrite is doing some kind of mean between the 3 channels :

 image = imread('image.jpg', IMREAD_COLOR);
 split(image, channels);
// Create some changes on channels[0]

merge(channels, 3, image);
// Up to this point every thing is alright
imwrite("modified.jpg", image); // Image changes when written;

Is there any solution to avoid this behavior ?

edit retag flag offensive close merge delete

Comments

can't side your findings.

can you try to save a png (or any other lossless codec?)

berak gravatar imageberak ( 2016-04-15 11:34:15 -0600 )edit

Hi berak, Me too i thought it was because of the lossy compression, but i tried to save it to .png, but the same thing happens.

allaoua gravatar imageallaoua ( 2016-04-15 12:37:28 -0600 )edit