Image Compression |
![]() |
Home |
Show content only (no menu, header)Image Compression by quantization below noise levelTo limit the size of images to be transfered by the network, RAW images are compressed by quantization at or just below the noise level. RAW files have integer pixel values between 0 and 16383 (14-bit resolution), but the noise level allows for a smaller number of discrete values at the cost of a higher quantization noise. The quantization noise is set to be equal (or less than) the quadratic sum of readout and photon noise to avoid a significant increase of overall noise. Pixel values x (0 - 16383) are resampled according the the following equation:x [ADU] -> f(x)The resampling function f (integer->integer) is chosen so that the quantization noise is smaller by a factor α than the quadratic sum of readout and photon noise. With g the gain in e-/ADU and RON the readout noise in ADU: Noise [ADU] = sqrt( RON2 + x/g) The quantization noise constraint can be written: df/dx = 1/(αNoise) with x and Noise in ADU. Integrating this equation leads to : f(x) = 2α-1 sqrt(g) (sqrt(g RON2 + x) - RON sqrt(g)) The quantization is achieved by replacing the pixel value x by the nearest integer to f(x). To recover x from f(x), the following equation can be used: x = (αf(x)/(2sqrt(g)) + RON sqrt(g) )2 - g RON2 f(x) ExampleAs an example, I consider here an image acquired at ISO 100:alpha = 0.5 g = 1.36 e-/ADU RON = 15.8 ADUThe function f(x) is shown in the following figure. With these parameters, the image can be quantized into just over 500 levels without increasing the overall noise level by more than sqrt(1+0.52)-1 = 12% .
Source CodeThe source code is part of module image_format in Cfits. The two functions are requant (compress) and dequant (restore). See the example script for use (this scripts is used for the benchmark below):# param 1: alpha Cfits << EOF loadfits IMG_0000.fits im requant im imq $1 15.8 1.36 1024 save_sh imq "!imq.fits" quit EOF rzip -k imq.fits mv imq.fits.rz imq.fits.$1.rz # testing Cfits << EOF loadfits imq.fits dequant imq im $1 15.8 1.36 1024 loadfits IMG_0000.fits im00 imdiff=im-im00 save_fl im "!im.fits" save_fl imdiff "!imdiff.fits" quit EOF BenchmarkTest on a single image, acquired at ISO 100.Description size file name ------------------------------------------------------------------- RAW image: 19291122 IMG_0000.CR2 RAW image, rzipped: 18535254 IMG_0000.CR2.rz RAW image, FITS (single precision): 60641280 IMG_0000.fits RAW image, short int: 30323520 imq.fits alpha = 0.1, rzipped: 13099237 imq.fits.0.1.rz alpha = 0.2, rzipped: 10238906 imq.fits.0.2.rz alpha = 0.5, rzipped: 7409063 imq.fits.0.5.rz alpha = 1.0, rzipped: 5425962 imq.fits.1.0.rz alpha = 1.5, rzipped: 4361783 imq.fits.1.5.rz alpha = 2.0, rzipped: 3628414 imq.fits.2.0.rzWith alpha = 0.5, the image size on disk is reduced to 38% of its original size (28% for alpha = 1.0). UseThe compress and uncompress commands are part of the main skycam utility. To compress image 4 acquired on 2011-02-26 :/skycam/skycam compress 2011-02-26 4To compress all files from frame numbers 0 to 100 for date 2011-02-26: seq 0 100| xargs -I {} /skycam/skycam compress 2011-02-26 {} Page content last updated: 27/06/2023 06:35:52 HST html file generated 27/06/2023 06:34:44 HST |