0
votes

I have started to explore deep into image Processing. Curious to know the answer of a simple question(which I tried googling but I guess I could not find a satisfactory answer): I have an RGB image:

enter image description here

then I applied simple OpenCV command: img=cv2.imread(r'E:\opencv\elephant.jpg',0)

cv2.imwrite('updated_elephant.jpg',img)

and finally got the output image:

see the memory used which is more than RGB image

Coming back to the question, why is there an increase in the size of the output image?(same thing happens with cv2.cvtColor() function.)Any insight or example relating to this would be appreciated.

Thank You for Your Sincere attention.

1
When you cv2.imread the image is decompressed. When recompressing, the compression quality, method etc can be very different from original, therefore you cannot expect a similar size.Ahmet

1 Answers

3
votes

JPEG is a lossy format, well described on Wikipedia. Have a read.

Encoders are allowed to make decisions about how they encode the data. Some will down-sample the colour one way, some another way and yet others will not do chroma-subsampling at all.

Some encoders will use integers for quantisation because it is faster on some processors, others may use floating point because they value accuracy more.

Some coders use the JPEG suggested tables of coefficients for discarding high frequencies, some use their own tables - this is the quality setting.

Therefore you will potentially get different filesizes and renditions on different platforms, or on the same platform with a different encoder, or on the same platform with the same encoder but a different software version.


If you want to look at chroma sub-sampling and quality settings in more detail, use ImageMagick in Terminal:

magick identify -verbose YOURIMAGE.JPG info:

If you want to spend several hours studying JPEG in minute detail, I commend this series of videos to you - link.