Ask Your Question

Revision history [back]

imwrite changes the channels when saving

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 ?