Imencode - different buffer sizes for identical image sizes

I have a series of images that are all identical in size (size meaning 152 rows and 302 columns). I try to encode each of these images, and then later decode them.

When I encode these images, I sometimes get different buffer sizes, like 54848 or 52876 (both larger than 152*302=45904 ).

Also, if I change a single pixel value in an input image, the values of 3723 different places in the buffer are different.

I have seen this behavior with tiff and png images so far.

Can anyone point me in the direction of a resource to better understand:

  • why are images of the same matrix size producing different buffer sizes? Can I enforce them to be a particular size?
  • how can I understand the encoded data? I know there is information other than the pure pixel values in the encoded data, but I do not understand where/what it is…

thanks in advance!

do you realize that these functions use compression because the file types PNG and TIFF allow it?

imencode returns a bunch of bytes, the same bytes that would be found in a file written by imwrite

you don’t expect a compressed file’s size to have much to do with the image’s resolution, right?

apart from size, the pixel content matters. i.e. run length encoding leads to a 4,1 sequence for 1 1 1 1 pixels, and to 1,1, 1,2, 1,3, 1,4 sequence for 1 2 3 4 pixels. a plain uniform white image will be much smaller than something with a lot of high-freq. details

no. you cant