1
$\begingroup$

I train a convolutional neural network on compressed jpeg images. I noticed that my code takes pretty much the same amount of space in memory whether I use high quality jpeg images or the same jpeg images but compressed. I know that processing a jpeg image starts by decoding it, so my question is: does 'decoding' a jpeg image uncompresses it? In other words, does a compressed image regain its original size (in bytes) when decoded?

$\endgroup$
2
$\begingroup$

Image processing is mostly done on frames. The digital image frame is a rectangular raster of pixels, either in an RGB color space or a color space such as YCbCr. So, as you noticed, you can be sure that your compressed images are decoded to rectangular rasters in your application. Each encoded image file stores with its data the source bitmap size (width and height) and the source color space (pixel format and bitness). When decoding, these parameters are restored. So, irrespective of what lossless/lossy algorithms are used, the sizes (in bytes) of recovered raster rectangles are identical, if both lo-res and hi-res compressed image files are received by encoding the same source bitmap data.

EDIT: A "multiresolution" comment fairly corrects my answer, and there is the other explanation why the application may not allocate in CPU memory the entire memory occupied by a source raster: a decoder can use GPU memory. But OP notices that decompressed images take "pretty much the same amount of space in memory" irrespective of encoded image quality. Even with multiresolution, the application can decode the image to source dimensions. Also, code performance dependence on image quality is not part of the question.

Still, the "multiresolution" comment is absolutely necessary for completeness.

| improve this answer | |
$\endgroup$
  • $\begingroup$ I did not mean to correct your perfectly sound answer. With some decoding options, images can be retrieved at a fraction of the original size I don't know though whether people use that in practice $\endgroup$ – Laurent Duval Jul 11 at 12:41
  • 1
    $\begingroup$ My answer was imperfect in that it could mislead someone to believe that decoders always decode to images with frame sizes of encoded images. Thank you for your correction. I know an application that uses the multiresolution feature of JPEG2000. $\endgroup$ – V.V.T Jul 11 at 13:17
  • $\begingroup$ The Hierarchical Mode of the JPEG Standard is rarely used! Please share the JPEG2000 use in AI! $\endgroup$ – Laurent Duval Jul 11 at 13:29
  • 1
    $\begingroup$ It is not an AI app. An acquaintance of mine used JPEG2000 and its multiresolution feature in a medical imaging application. $\endgroup$ – V.V.T Jul 11 at 17:39
2
$\begingroup$

Decoding is sometimes another word for uncompressing. Compression used to be called "source coding" (in comparison to channel coding).

For images compressed at a single resolution, like in the baseline JPEG, finally-decompressed images have the same size as the original, as already answered. This might not be the case with multiresolution coder like JPEG2000.

Moreover, highly compressed images (ie with poorer quality) may be a bit faster to decode than high-quality ones, because there is less information to decode.

| improve this answer | |
$\endgroup$
1
$\begingroup$

A jpeg compressed image contains (in byte) the upper bound for unique «information» that can reliably be extracted from that image. Decoding will increase the file size, but not knowledge about the true scene. Further, jpeg is «fairly good» but far from perfect in judging what details matters for a human viewer.

With that in mind, what about training on the compressed jpeg data? No need to expand a couple of dct coefficients to 8x8 pixels of «smooth» data?

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for this information! I just use a library for jpeg decoding, so I don't don't know anything about dct coefficients... But one thing is for sure, when I take the same image in 2 variants : original (high quality) and compressed, when I read them and store them in an object in RAM, they both have the same size, just to say that compression doesn't play a role in minimizing RAM usage when processing these images $\endgroup$ – S.E.K. Jul 11 at 15:04
  • $\begingroup$ When an image is compressed (or encoded), its file size is reduced, e.g. to 10% of its original size. When an image is decompressed (or decoded), its file size is returned back to the original, only now the image data will be more or less distorted due to compression errors. $\endgroup$ – Knut Inge Jul 12 at 6:47
  • $\begingroup$ In the case of jpeg, that compression is quite simple. You could use the functionality of a jpeg library, or code up something in python thag would parse the bitstream, decode entropy coding, and you would get a variable-length vector per 8x8 pixel block with weights for the (linear block transform) dct coefficients. Depending on how memory constrained you are and the capabilities of your machine learning setup, that may or may not make sense. $\endgroup$ – Knut Inge Jul 12 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.