Objective: to gain understanding on kernel processing

advertisement
Lab Worksheet 3 - Convolution
Objective: to gain understanding on convolution and kernel processing.
This exercise is to help you gain understanding on convolution and kernels. There are
two main effects that convolution kernels can do on images, smoothing (for removing
noise, blurring) and sharpening (for edge detection).
For further information on convolution and kernels, please read recommended
reference books on relevant chapters as well as the website below:
http://homepages.inf.ed.ac.uk/rbf/HIPR2/hipr_top.htm
For the lab exercise this week:
Task 1 kernel operation
Step1 follow steps described in “lab-week2-start”, open the
“ConvolutionTool” in chap07 (similar way of opening “ImageViewer”)
program
Step 2, double click the program content “ConvolutionTool”, and see the program
window on the right. From the instruction of the beginning of the program, you will
find there are two types of input methods,
Examples of use:
java ConvolutionTool image.jpg
java ConvolutionTool image.jpg 5 5
If just input image name as the only one argument, the program will work with 3x3
kernels as a default setting. If input both image name and a suggested kernel size (for
example, 5 5), then it will work with 5x5 kernels or any other size of kernels as
suggested.
Step 3 Try to use the following kernels as input to see the effect of the output images.
Sample 3x3 unweighted smoothing kernel:
0 1 0
1 1 1
0 1 0
1 1 1
1 1 1
1 1 1
To enlarge the smoothing radius, you can enlarge the kernel, e.g., a 5x5 smoothing
kernel:
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
And here's weighted 3x3 smoothing kernel also known as Gaussian Blur:
0 1 0
1 4 1
0 1 0
a 5x5 Gaussian smoothing kernel:
0
1
2
1
0
1 2
4 8
8 16
4 8
1 2
1
4
8
4
1
0
1
2
1
0
To make image sharper, i.e. enhance edges:
0 -1 0
-1 5 -1
0 -1 0
The effect can be intensified by applying this kernel:
-1
-1
-1
-1
9
-1
-1
-1
-1
Very interesting effect can be achieved with following kernel. Notice that the sum of
the elements is 0. This kernel highlight the edges of the image and makes other parts
darker.
-1
-1
-1
-1
8
-1
-1
-1
-1
Task 2. simple image processing
Use sample image “noise.jpg” (under image directory) as input to perform one of
those smooth algorithm, such as “MedianFilter.java” “MeanFilter.java”
“GaussianBlur.java”, to gain a smoothed image, in order to remove the noise in the
image. You can also search and use some other images where noise present. Let’s say
we have saved the output smoothed image as “smooth.jpg” for these programs, we
can then use this image as an input for SoberEdgeDetector.java and obtained an image
after the edge detection. Compare this image with the output if we directly use
“noise.jpg” as input to SoberEdgeDetector.java”.
Download