When we save a bitmap image, we can choose between lossy and lossless compression schemes to reduce the file size that stores the color information for each pixel that is composed in the bitmap image.
Lossless compression schemes retain all the original color information; and therefore, they keep the original quality, but they produce a large file size. On the other hand, lossy compression schemes replace some color information with approximated values to produce a smaller file size. Thus, lossy compression schemes don't keep the original quality.
In this recipe, we will learn how to choose between one scheme over the other. However, a smaller size is not the only thing that matters!
Capture an image of the map of the Louvre Museum in France in order to use it in our Moodle course. In this case, we contrast both lossy and lossless compression with this map. Save them as .PNG
, not as .JPG
, because the resolution of a .JPG
image is low and is not convenient to work with.
Enter http://maps.google.com/ and capture the image of the location of the Louvre Museum in France. We have already covered maps in Chapter 2, Working with 2D and 3D Maps. We are going to use GIMP. If you do not have it yet, download and install GIMP 2.6.8 (http://www.gimp.org/downloads/). Therefore, these are the steps to follow:
We are going to compare the two files. The image is the same: the part of the map that shows the location of the Louvre Museum in France. What we change is the extension, the type of the image file. We compare the two pictures and they will show that lossless compression is used when it is important that the original and the decompressed bitmap image or photograph be identical. PNG
only uses lossless compression.
Remember that we are still working with GIMP. Follow these steps in order to compare both images:
.JPG
image, the blurrier it gets. Pixels with different colors that add noise to the image delete color information and replace it with pixels of approximated values. This is shown in the following screenshot: .PNG
works. This type of image is lossless compression. Follow steps 1-3. The difference is that in the Name field, type "Louvre_Lossless" and make sure the extension is PNG image.3.14.245.167