a method for compression includes applying a discrete cosine transform to said image data to obtain transform coefficients , quantizing the transform coefficients by applying a quantization level scaled through a gain value , adjusting the gain value as a function of desired image parameters by executing a first time said quantization operation applying a first gain value and obtaining first quantized data , estimating statistically a second gain value suitable to obtain the desired image parameters , and executing a second time said quantization operation applying said second gain value . the operation of statistical estimation of the second gain value includes evaluating a threshold value as a function of the desired image parameters and setting to zero a percentage of coefficients of the first quantized data as a function of the threshold value .