Use cvFilter2D()
to create a filter that detects
only 60 degree lines in an image. Display the results on a sufficiently interesting
image scene.
Separable kernels. Create a 3-by-3 Gaussian kernel using rows [(1/16, 2/16, 1/16), (2/16, 4/16, 2/16), (1/16, 2/16, 1/16)] and with anchor point in the middle.
Run this kernel on an image and display the results.
Now create two one-dimensional kernels with anchors in the center: one going
"across" (1/4, 2/4, 1/4), and one going down (1/4, 2/4, 1/4). Load the same original
image and use cvFilter2D()
to convolve the image
twice, once with the first 1D kernel and once with the second 1D kernel. Describe
the results.
Describe the order of complexity (number of operations) for the kernel in part a and for the kernels in part b. The difference is the advantage of being able to use separable kernels and the entire Gaussian class of filters—or any linearly decomposable filter that is separable, since convolution is a linear operation.
Can you make a separable kernel from the filter shown in Figure 6-5? If so, show what it looks like.
In a drawing program such as PowerPoint, draw a series of concentric circles forming a bull's-eye.
Make a series of lines going into the bull's-eye. Save the image.
Using a 3-by-3 aperture size, take and display the first-order x- and y-derivatives of your picture. Then increase the aperture size to 5-by-5, 9-by-9, and 13-by-13. Describe the results.
Create a new image that is just a 45 degree line, white on black. For a given series of aperture sizes, we will take the image's first-order x-derivative (dx) and first-order y-derivative (dy). We will then take measurements of this line as follows. The (dx) and (dy) images constitute the gradient of the input image. The magnitude at location (i, j) is
and the angle is
. Scan across the image and find places where the magnitude is at or near maximum. Record the angle at these places. Average the angles and report that as the measured line angle.
Do this for a 3-by-3 aperture Sobel filter.
Do this for a 5-by-5 filter.
Do this for a 9-by-9 filter.
Do the results change? If so, why?
Find and load a picture of a face where the face is frontal, has eyes open, and takes up most or all of the image area. Write code to find the pupils of the eyes.
A Laplacian "likes" a bright central point surrounded by dark. Pupils are just the opposite. Invert and convolve with a sufficiently large Laplacian.
In this exercise we learn to experiment with parameters by setting good lowThresh
and highThresh
values in cvCanny()
. Load an image with suitably
interesting line structures. We'll use three different high:low threshold settings of
1.5:1, 2.75:1, and 4:1.
Report what you see with a high setting of less than 50.
Report what you see with high settings between 50 and 100.
Report what you see with high settings between 100 and 150.
Report what you see with high settings between 150 and 200.
Report what you see with high settings between 200 and 250.
Summarize your results and explain what happens as best you can.
Load an image containing clear lines and circles such as a side view of a bicycle. Use the Hough line and Hough circle calls and see how they respond to your image.
Can you think of a way to use the Hough transform to identify any kind of shape with a distinct perimeter? Explain how.
Look at the diagrams of how the log-polar function transforms a square into a wavy line.
Draw the log-polar results if the log-polar center point were sitting on one of the corners of the square.
What would a circle look like in a log-polar transform if the center point were inside the circle and close to the edge?
Draw what the transform would look like if the center point were sitting just outside of the circle.
A log-polar transform takes shapes of different rotations and sizes into a space where these correspond to shifts in the θ-axis and log(r) axis. The Fourier transform is translation invariant. How can we use these facts to force shapes of different sizes and rotations to automatically give equivalent representations in the log-polar domain?
Draw separate pictures of large, small, large rotated, and small rotated squares. Take the log-polar transform of these each separately. Code up a two-dimensional shifter that takes the center point in the resulting log-polar domain and shifts the shapes to be as identical as possible.
Take the Fourier transform of a small Gaussian distribution and the Fourier transform of an image. Multiply them and take the inverse Fourier transform of the results. What have you achieved? As the filters get bigger, you will find that working in the Fourier space is much faster than in the normal space.
Load an interesting image, convert it to grayscale, and then take an integral image of it. Now find vertical and horizontal edges in the image by using the properties of an integral image.
Use long skinny rectangles; subtract and add them in place.
Explain how you could use the distance transform to automatically align a known shape with a test shape when the scale is known and held fixed. How would this be done over multiple scales?
Practice histogram equalization on images that you load in, and report the results.
Load an image, take a perspective transform, and then rotate it. Can this transform be done in one step?