Digital Photography Compression Cont'
JPEG optimization and sharpen filters

JPEG - How to Optimise

The JPEG format uses the DCT (Discrete Cosine Transform) method of compressing and as we have seen, it works by subdividing the image into small 8 x 8 pixel areas and then compresses each of these independent of the others. If the 8 x 8 area (64 total pixels) contains 64 totally different values, then to get each one back we must set the compression quality to pretty high. The way DCT works also makes it hard for it to compress well when all the pixels are the same. (A bit weird but that's the way it is.) After all it is based on approximating the information using a variation of a cosine function, and the cosine is continuously changind and not a constant.

As it happens, the DCT process works well with values that change in an orderly manner and stay within a certain region. So how can you create something like that in all or part of a picture?

Filtering functions are based on the concept of changing something compared to something else. Changing the hue (color) of a pixel is not a filtering function it is an absolute change. Take sharpening for example, the change of any one pixel neither sharpens it nor blurs it, it simply changes it. For there to be a sharpen or blur, the pixels changed must be referenced to others around it.

If you study what filters do, you will find that they all can be grouped into 3 categories regardless of the final result. They either have the effect of sharpening an image, blurring and image, or distorting an image. And that's about it. Let's look at my definitions:

Filter Type

Filter Function



distortion filters move pixels from one location to another. They do not sharpen an image or blur an image.



sharpen filters cause pixels to differentiate themselves from one another.



blur filters cause pixels to become more alike.

So why do I make this claim? How did I reach this conclusion? By studying the histogram of images before and after applying filters. The histogram reveals a lot of information if you will take the time to read it. It can even reveal more information if you look at it before and after doing things.

Lets look at the simplest filter, distortion.

Distortions are caused by groups of pixels moving from one location to another. The way they move is defined by the type of distortion filter applied.

The original image is at the top, and its associated histogram is shown just below.

The second image was distorted using a TWIRL filter in PhotoShop. The image appears to be wrapping around its centre. The associated histogram is just below it. Notice that that the histogram for the original , and the "twirled" image are almost exactly alike. So why almost?

There are a few minor differences, but I believe these are a function of the algorithm used in calculating the TWIRL effect. Most of the filters use real numbers that do not always have exact equivalents, and there is always a slight round-off error. Hence some pixels that move after others may end up replacing or duplicating an original ones.

In the third image, I ran a RIPPLE filter and the resultant histogram is again shown below the filtered image. The ripple obviously changes the visual characteristics of the image. Again the histogram of this image is virtually identical to that of the original image.

These filters move data around the image but do not change the RGB values of the individual pixels. Their distribution stays the same. Hence these filters do not sharpen an image or blur an image, they simply change the image. (Visually distort it!) Sharpening and blurring do change the RGB values and we'll look at them next.

(Special Note: if you were to look at the actual histograms of the images in this document they would show greater differences. That is because the JPEG compression routine used to compress them does introduce more artefacts and changes in the RGB values of the pixels. These histograms were taken before the JPEG compression was applied.)

So what about Sharpen?

We will use the same image as before and we will apply some more filters to it one at a time. The first and most obvious is the SHARPEN filter.

Again the first image is the original without filtration, followed by its histogram.

Now in the next series of three images I have applied the standard Photoshop SHARPEN filter to the image numerous times.

In the second image down, the filter was applied only once, and at first glance there appears to be little or no change in this histogram. Close examination will reveal that there is one noticeable although not large change. There is more data at the end of each histogram now. There distribution of colors in the overall histogram now has more values with both 0 and 255.

In the third image down the SHARPEN filter as applied 3 times. Look again at the two end points. They both show a higher percentage of the total pixels at the ends. It is barely noticeable from this image, but the center portion of the histogram is beginning to shrink and become flatter.

In the forth image, after the application of 8 sharpen filters, there is an easily noticeable shift in both the real image, and its histogram. The centre of the histogram is becoming much flatter and the two ends are continuing to grow. We cannot measure the growth because the two ends are already at the highest values charted, but they are continuing to grow.

In the last image, the SHARPEN was applied about 15 times, and as you can see the color is disappearing and the image is becoming a series of black and white dots that outline the original content. The histogram is now almost flat, and all of the data has moved to the outside of the histogram.

The sharpen filter increases contrast (or the mathematical differences) between pixels. the highest contrast images contain only Black and White and are thus made up of all zeros (0) or all 255 maximum value. The histogram displays this as the two maximum lines at each end of the graph.

Summary: Sharpening can be seen when the information in a histogram redistributes itself to the outside edges of the histogram. The net effect is a build up of contrast in the image.


Now let's look at the BLUR filter ...