You are on page 1of 17

5/13/2014 CS 7966 - Project 3

http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 1/17
CS 7966 Image Processing
Project 3 - Antialiasing Filters
Chelsea Robertson
croberts@cs.utah.edu
April 13, 2006
Filters
I decided to use a Butterworth lowpass filter and a Gaussian lowpass filter, both of which are radially symmetric. The third filter I chose to implement is a separable lowpass Box
filter. The equations for these filters are given below:
Butterworth lowpass Filter:
H(u,v) = 1 / [1 + D(u,v) / Do]^(2*n)
where D(u,v) is the distance from any point (u,v) to the center of the Fourier transform, Do is the distance of the cutoff frequency, and n is the order
Gaussian lowpass Filter:
H(u,v) = e^[ -(D(u,v)*D(u,v)) / (2*Do*Do) ]
where D(u,v) is the distance from any point (u,v) to the center of the Fourier transform and Do is the cutoff frequency (measure of the spread of the Gaussian curve)
Lowpass Box Filter:
H(u,v) = 1.0 for (D(u) < Do/2) && (D(v) < Do/2)
0.0 otherwise
where D(u) and D(v) are the distances from any point (u,v) to the center of the Fourier transform in each direction, Do is the width of the box, so Do/2 is the distance of the
cutoff
frequency in each direction
Test Images
Below are the three images I used to test my filtering algorithms.
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 2/17
Statistical Analysis
A couple statistical measures were used in order to evaluate the performance of the antialiasing filters used.
These measures are in-spectrum energy loss and foldback error and are shown in the diagram on the right.
The rectangular region is an ideal filter with a sharp cutoff at the specified radius. The gaussian shaped filter
represents the filter being evaluated. The red portion represents the energy loss and the blue portion
represents the leakage (foldback error). The methods I used to measure these values are discussed below.
In-spectrum Energy Loss
This value was measured by computing the area between the curve of the filter and 1. I did this using the filter image. I looped through the pixels, and if the distance of the pixel
was less then or equal to the cutoff (radius of the filter) then (1 - value of pixel) was added to the total energy loss. Then I divided the total energy loss by the area of the ideal
filter (for circularly symmetric filters a circle was used to compute this area, for rectangular filters a rectangle was used) to get the percentage of energy lost.
Foldback Error
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 3/17
This value was measured by computing the area under the curve of the filter from the cutoff to infinity (edges of image). This was done similarly to the in-spectrum energy loss. I
also computed the total area, by summing the area under the curve of the filter. Then I divided the foldback error by the total area to get the percentage of foldback error.
Subsampling
Algorithm
The algorithm I used for subsampling is as follows:
Read Image
Fourier Transform
Filter Image
Inverse Fourier Transform
Reduce Image
Write Image
Executable
The command line input to run the subsampling program is below (followed by an example):
> ./subsample input_filename scale_factor filter_type cutoff order
where filter_type is the following number represention of the filter:
1. butterworth
2. gaussian
3. separable box filter
4. identity (no filter for comparison purposes)
and order is optional (1.0 if not specified)
> ./subsample lena.tif 2 1 100
Analytical Results
Butterworth Filter Results
Below is a table containing all of the Butterworth filters tested, with the corresponding values of the parameters labeling the columns and rows. As you can see from the images,
Do controls the radius of the filter and n controls how steep or sharp the transition is at the edges of the filter. The images are scaled down, so in order to see the full resolution
image just click on the appropriate image.
Do = 50 Do = 100 Do = 200
n = 1
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 4/17
n = 2
n = 4
n = 8
Below are two tables containing the results of energy loss and foldback error for subsampling using the above Butterworth filters. The values in the tables are given as
percentages.
In-Spectrum Energy Loss Foldback Error
n\Do 50 100 200
1 30.6 30.7 30.7
2 21.4 21.5 21.4
4 13.2 13.3 13.3
8 7.5 7.5 7.5

n\Do 50 100 200
1 80.3 68.7 38.0
2 49.0 45.7 29.3
4 22.0 21.9 18.7
8 9.9 9.9 9.7
These results match what was expected. The in-spectrum energy loss is constant as Do increases. This is because the area between the ideal filter and curve of the butterworth is
changing proportional to the change in area of the ideal filter. Thus resulting in a constant percentage. Also, as n increases, the in-spectrum energy loss decreases. This makes
sense because as n increases, the cutoff becomes more steep, resulting in a smaller area between the ideal and the butterworth curves. Likewise, foldback error decreases as Do
increases because the portion outside of the cutoff and under the curve is decreasing relative to the total area under the curve. Also, as n increases, foldback error decreases.
This is for similar reasons as the in-spectrum energy loss. As n increases, the curve becomes more steap, resulting in a smaller area under the curve and outside the cutoff, making
it a lower percentage of the total area.
Gaussian Filter Results
Below is a table containing all of the Gaussian filters tested, with the corresponding values of the parameter above the images. Once again, the images are scaled down, so click
on the appropriate image to see it in full resolution.
Do = 50 Do = 100 Do = 200
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 5/17
Below is a table containing the results of energy loss and foldback error for subsampling using the above Gaussian filters. The values in the tables are given as percentages.
Do 50 100 200
In-Spectrum Energy Loss 21.3 21.3 21.3
Foldback Error 60.7 59.8 38.4
These results are also what was expected and similar to the results from changing Do in the Butterworth filter. The in spectrum energy loss doesn't really change as the cutoff
increases. This is because I am measuring the percentage. The area under the curve is changing, but it is staying proportional to the area of the ideal filter because the gaussian
filter is based on standard deviation. Since the number of standard deviations is constant, the area between the ideal filter (1) and the curve of the gaussian filteris constant,
resulting in a constant percentage. However, the foldback error decreases as the cutoff increases. This is because I am measuring the foldback error as the percentage of the
filter outside the cutoff relative to the entire area under the curve of the filter. Since the area under the curve is increasing, the percentage outside the cutoff is getting relatively
smaller, resulting in a lower percentage.
Separable Box Filter Results
Below is a table containing all of the Box filters tested, with the corresponding values of the parameter above the images. Once again, the images are scaled down, so click on the
appropriate image to see it in full resolution.
Do = 50 Do = 100 Do = 200
Below is a table containing the results of energy loss and foldback error for subsampling using the above Box filters. The values in the tables are given as percentages.
Do 50 100 200
In-Spectrum Energy Loss 4.1 2.0 1.0
Foldback Error 0.0 0.0 0.0
In theory, the box filter is ideal, which means it should have an in-spectrum energy loss equal to zero and a foldback error equal to zero. Based on my results, I came to the
conclusion that these numbers contain some roundoff error at the borders of the filter. I think this is the case because if the border was included with the total energy loss, then
that contained the error, and when the border was included with the total foldback error that measure contained approximately the same error. Also, as the box gets larger, there
is more area covered in the box, so the percentage of error at the border gets smaller. This supports my theory that my numbers are off due to roundoff error.
Empirical Results
Butterworth Filter Results
Do = 50 Do = 100 Do = 200
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 6/17
n = 1
n = 2
n = 4
n = 8
The images seem to support the analytical results for the Butterworth filter. As you look at the images across a row, they seem to become less blurry. Also, as you go down a
column, there appears to be some ringing. This artifact isn't very noticeable in this image, but it becomes more apparent in the other example images.
Do = 50 Do = 100 Do = 200
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 7/17
n = 1
n = 2
n = 4
n = 8
The same is true for Lena. To the right, the images become more clear. Towards the bottom, the ringing becomes noticeable around the hard edges in the image.
Do = 50 Do = 100 Do = 200
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 8/17
n = 1
n = 2
n = 4
n = 8
This image shows the affects of changing n the best. The ringing is perfectly clear in the images with n = 8, and is also noticeable for images with n = 4. Also, this image does the
best job of showing the darkening of the image resulting from filtering.
Gaussian Filter Results
Do = 50 Do = 100 Do = 200
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 9/17
As can be seen in the above images, the blurriness decreases as the cutoff frequency is increased. These results are quite comparable with those given from the Butterworth filter.
However, the advantage of Gaussian filtering is that it is gauranteed to have no ringing.
Do = 50 Do = 100 Do = 200
The same results are obvious with this image. A higher cutoff frequency gives better results.
Do = 50 Do = 100 Do = 200
Similarly for this image, the higher cutoff frequency makes the image more clear. But, as you can see, the overall image appears slightly darker with the higher cutoff. In any case,
Gaussian filtering is far superior to the box filter, which will be quite obvious in the images below.
Separable Box Filter Results
Do = 50 Do = 100 Do = 200
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 10/17
As you can see in the images, the smallest box filter produces the blurriest image. This is because the ideal box filter results in ringing due the sharp cutoff of the filter. As the size
of the box filter increases, the resulting image becomes more clear.
Do = 50 Do = 100 Do = 200
Once again, the box filter of size 50 is extremely blurry. However, this image shows the ringing much better than the previous image. In the middle image, it is clear that there is
ringing going on at the edges in the image. Similarly, the largest box filter produces the best results, as the ringing is not very noticeable.
Do = 50 Do = 100 Do = 200
This image is great for showing the Gibbs phenomenon resulting when using the box filter because it contains many edges. Similar to the previous images, the box filter of size 50
produces awful results. The box filter of size 100 shows the ringing quite nicely. With the largest box filter not much ringing can be seen, but the ringing seems to have darkened
the entire image.
Supersampling
Algorithm
The algorithm I used for subsampling is as follows:
Read Image
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 11/17
Create Supersampled Image padded with zeros (supersampled images)
Fourier Transform
Filter Image
Inverse Fourier Transform
Write Image
Executable
The command line input to run the supersampling program is below (followed by an example):
> ./supersample input_filename scale_factor filter_type cutoff order
where filter_type is the following number represention of the filter:
1. butterworth
2. gaussian
3. separable box filter
4. identity (no filter for comparison purposes)
and order is optional (1.0 if not specified)
> ./supersample pattern1.tif 2 2 150
Analytical Results
I did not include images of the filters in this section because they are almost identical to the images of the filters in the subsampling section. I used the exact same filters, so the
only difference is that there is more black area around each of the filters.
Butterworth Filter Results
Below are two tables containing the results of energy loss and foldback error for supersampling using the above Butterworth filters. The values in the tables are given as
percentages.
In-Spectrum Energy Loss Foldback Error
n\Do 50 100 200
1 30.6 30.7 30.7
2 21.4 21.5 21.4
4 13.2 13.3 13.3
8 7.5 7.5 7.5

n\Do 50 100 200
1 85.8 80.3 68.7
2 49.8 49.0 45.7
4 22.0 21.9 21.9
8 9.9 9.9 9.9
These results match the results obtained in subsampling. As Do increases, in-spectrum energy loss is constant and foldback error decreases. Also, as n increases, both energy
loss and foldback error decrease.
Gaussian Filter Results
Below is a table containing the results of energy loss and foldback error for supersampling using the above Gaussian filters. The values in the tables are given as percentages.
Do 50 100 200
In-Spectrum Energy Loss 21.3 21.3 21.3
Foldback Error 60.7 60.7 59.8
These results are similar to those obtained in the subsampling. However, the foldback error is decreasing at a slower rate because the proportion of area outside the cutoff is not
changing as quickly as it was before in the subsampling.
Separable Box Filter Results
Below is a table containing the results of energy loss and foldback error for supersampling using the above Box filters. The values in the tables are given as percentages.
Do 50 100 200
In-Spectrum Energy Loss 4.1 2.0 1.0
Foldback Error 0.0 0.0 0.0
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 12/17
These results are the same as the results obtained for subsampling. Theoretically, this should be the case because the size of the image has nothing to do with the performance of
the box filter because it is ideal. So both energy loss and foldback error should be zero for the ideal filter.
Empirical Results
Note: These images have been scaled down to fit nicely in the report. In doing so, the small images picked up artifacts and do not accurately represent the
supersampled image. To view the full supersampled image you must click on the image and then click on it again (when it opens as its own page).
Butterworth Filter Results
Do = 50 Do = 100 Do = 200
n = 1
n = 2
n = 4
n = 8
I like the supersampled images because they show the affects of filtering more clearly then the subsampled. This set of images shows the same results as the subsampled, but it is
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 13/17
much easier to see in the larger images.
Do = 50 Do = 100 Do = 200
n = 1
n = 2
n = 4
n = 8
Similarly, Lena shows the same results, but once again, it is easier to see the transition from blurry to clear, and from no ringing to ringing.
Do = 50 Do = 100 Do = 200
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 14/17
n = 1
n = 2
n = 4
n = 8
This group of images shows the results of Butterworth filtering the best. The left images are definitely blurry and the right are much more clear. Likewise, in the top images there is
no ringing, but you can see it become more prominant as you go to the bottom images.
Gaussian Filter Results
Do = 50 Do = 100 Do = 200
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 15/17
The above images produce similar results to the subsampled images. As the cutoff frequency increases, the images are more clear.
Do = 50 Do = 100 Do = 200
The same results are seen in this image. As a result of eliminating the ringing, the edges become slightly blurry.
Do = 50 Do = 100 Do = 200
Just like in the subsampled versions of this image, they get more clear as Do increases, but the image is also darker.
Separable Box Filter Results
Do = 50 Do = 100 Do = 200
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 16/17
The smallest box filter produces terrible results on this image. It is extremely blurry due to the ringing and the image is almost unrecognizeable. The second image is a little better,
but still very blurry due to ringing. The same is true for the largest filter size.
Do = 50 Do = 100 Do = 200
The same is true for Lena. The images become less blurry (because of ringing) as the filter size increases, but the largest isstill not great. Also, in the subsampled image with a box
filter of size 200, the ringing is hardly noticeable, but in the supersampled image it is very obvious.
Do = 50 Do = 100 Do = 200
The results for this image are the same. Do=50, is absolutely useless, Do=100, pretty bad, but the image can be made out, and Do=200 is a little better. Once again, the ringing
is obvious in this image compared to the subsampled version. Also, the ringing of the box filter resulted in darkening the entire image.
Conclusions
I think the images and analytical evaluation of the filters compliment eachother in evaluating the performance of different filters on subsampling and supersampling. The statistics
allow you to numerically see what is happening as the parameters of the filters change, but the images allow you to visually see the results the parameters have on the filters.
The Butterworth filter allows for the most control of the filters tested. The two parameters allow it to behave similar to a Box filter and to a Gaussian filter depending on the
circumstances. When you need tight control of the transition between high and low frequencies near the cutoff frequency, you can get a filter resembling a Box filter. This is nice,
however it can possibly result in ringing depending on how close to the Box filter it is.
The Gaussian filter allows for less control, but it is nice in that it doesn't result in ringing. This is great when artifacts aren't acceptable for the specific application. The only
drawback to this is that it may result in a little blurrier image.
5/13/2014 CS 7966 - Project 3
http://www.cs.utah.edu/~croberts/courses/cs7966/project3/index.html 17/17
The Box filter is the ideal filter, as there is no energy loss or foldback error. However, because of this, it produces terrible ringing artifacts, which causes it to be less then ideal.

You might also like