There are a number of videos online illustrating the effect of increasing JPEG (JPG) compression on both file size and image quality (see example 1, example 2, or example 3). I wanted to try recompression on my own data because the effect can be recreated quickly using a simple MATLAB script. It is a very simple demonstration of the effect of lossy image compression. For a simple demonstration of the effect of compression, I load an image into MATLAB and then progressively increase the JPEG compression (by decreasing the ‘Quality’ parameter in imwrite), saving each incremental image as a frame. I then load all of the frames and assemble them into a video file. Here’s an example of increasing image compression at 10 frames per second:
In addition, I tried recompressing the image to see the effect of repeated JPEG compression on the output. An initial image is loaded, it is compressed, then that image is loaded and compressed at a lower quality, then that image is loaded and compressed at an even lower quality, and so on and so forth. Here’s the output at 10 frames per second when we do this from the least amount of JPEG compression (‘Quality’,100) to the most amount of compression (‘Quality’,0):
Just to be artistic, we can then repeat the cycle 10x and observe the effect of repeated compression. Here is an example at 30 frames per second with 10 loops of the repeated recompression:
Click through for the MATLAB code and a couple more example videos.