- Compress the original image to JPG.
- Compress the original image to ECW using different compression levels until the resulting ECW file is slightly larger than the JPG file obtained in the previous step (this gives the ECW file a slight advantage).
- Uncompress both files to a format that imagemagick can read.
- Compare the uncompressed versions with the original image to quantify their lossiness.
A screenshot illustrating this process can be seen here. I have used GDAL and imagemagick for this. Lossiness is quantified by computing the PSNR value (the higher the better: very lossy images have a low PSNR). The result of this is that JPG files are smaller but less lossy than ECW files:
|Image size (pixels)||JPG size (Mbytes)||ECW size (Mbytes)||JPG PSNR||ECW PSNR||JPG wins?|
|5355 x 5349||5.36||5.67||37.7||35.5||YES|
|5351 x 5154||6.53||6.93||35.1||34.2||YES|
|4096 x 4096||5.08||5.45||27.6||27.4||YES|
The fact that JPG uncompresses faster than ECW can clearly be seen with just one test. The uncompress time can be estimated with the time Linux command applied to gdal_translate:
From JPG to BMP: 18.4 seconds (16.1 seconds if we discount copy time)
From ECW to BMP: 27.1 seconds (24.8 seconds if we discount copy time)
Copy BMP to BMP: 2.3 seconds (estimated time needed to copy result to disk)
So what is good about ECW?
The ECW format allows fast access to application-defined zones of the raster with very low memory consumption. The typical scenario is that the application’s viewport needs to paint about one million pixels on the screen, while the original raster is a huge image with hundreds of millions or even billions of pixels. The JPG format needs to be fully expanded, so usually most of the resulting pixels will not be used.
How can we avoid uncompressing unneeded pixels?
We must use JPG images in a way that does not force us to uncompress pixels that are not going to be painted. One way to achieve this is by cutting up the original image in pieces that are small enough so that -after quickly selecting the needed ones- we can cover the application’s viewport without uncompressing a number of pixels that is significantly larger than the viewport size. In other words: use JPG tiles.