Digital Imaging Part 2 - Lossy Vs. Lossless
Understanding image compression is really just a matter of thinking in numbers. The number of bits that are stored and the number of pixels that make up the image are key factors. An uncompressed image with a resolution of 640 x 480 pixels has 307,200 pixels total. A true color (24 bit) image of that size would take about 1 MB of storage space considering each pixel uses 3 bytes. The file size increases with the image resolution, for instance, if we have a true color image resolution of 1024 x 768 pixels, it's going to take 2.5 MB of storage space. Now, imagine that you have a few 2.5 MB files on your server that are downloaded by everyone who visits your web site... you would probably use up a lot of bandwidth quickly!
Thankfully, we can compress image data to make the file smaller while retaining the size of the image. There are a lot of programs that can convert and compress your images with ease, in fact, most image editors can. Also, most digital cameras compress your images automatically so you can store more images and move them to your computer quicker. Smaller image files are easier to manage which is why compressed images are ubiquitous. Images can be compressed in two ways, lossless and lossy. The difference between the two is that lossless files retain their data while lossy files lose data.
Lossless files like TIFF, GIF and PNG are saved using algorithms that reduce file size but do so without losing image quality. Unfortunately, the compression ratios are quite a bit weaker than lossy. That means that it will ultimately be a larger file, but the quality will be well preserved. Usually, images that will be printed are saved with a lossless compression because the integrity of the image is more important than viewing it on the Internet, for example.
Lossy files like JPEG and JPEG2000 discard information when they are saved. The amount of information that is discarded directly influences the size of the file. It's important to note that once you save a lossy file, you can never go back to the previous state. Each time the file is opened and saved as a JPEG, it will lose more and more data which will cause the image to become pixelated. The reason for this is that pixel data is trashed during compression and when the image is reopened, the computer must fill in the missing data by borrowing from neighboring pixels. This also happens when an image has been saved using a very high compression ratio for the same reason.
High compression = Lower quality image
Take a look at these images for an example. The first image has been saved as a lossless PNG file (83.8 KB), the center has been saved with low compression (81.7 KB), and the third has been saved with high compression (45.5 KB). You can see the visual artifacting occurring most in the image that has been saved with the highest compression. It's up to you to decide if you want to compromise file size or quality when choosing image compression. If the file is to be placed on your website, consider how often people will download the file and how much strain a file that size could put on your bandwidth allowance. If a file is too large, it could take longer for your Web page to load and most people won't stick around to see. If the file is too small, viewers might not be able to make out what it is, or it could send the wrong message. It certainly doesn't look professional. When in doubt, choose a compression ratio that is somewhere in the middle and save it as a new file. Open it and see how it looks. If you don't like it, open the original file and save again until you get it just right.
Stacy Reed is Tucows' resident software librarian and editor. She has been reviewing PC and mobile software as well as web services for over a decade. Helping developers improve and promote their products is only one of her areas of expertise. Stacy is also an advocate for Open Source, Creative Commons and freeware, taking special interest in educational resources, social media, cloud sharing, and mobile technology.