A method is for compressing a digital image that is made up of a matrix of elements,
with each element including a plurality of digital components of different types
for representing a pixel. The method includes splitting the digital image into
a plurality of blocks, and calculating for each block a group of DCT coefficients
for the components of each type, and quantizing the DCT coefficients of each block
using a corresponding quantization table scaled by a gain factor for achieving
a target compression factor. The method further includes determining at least one
energy measure of the digital image, and estimating the gain factor as a function
of the at least one energy measure. The function is determined experimentally according
to the target compression factor.