Exercises

  1. Use cvFilter2D() to create a filter that detects only 60 degree lines in an image. Display the results on a sufficiently interesting image scene.

  2. 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.

  3. Can you make a separable kernel from the filter shown in Figure 6-5? If so, show what it looks like.

  4. In a drawing program such as PowerPoint, draw a series of concentric circles forming a bull's-eye.

    1. Make a series of lines going into the bull's-eye. Save the image.

    2. 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.

  5. 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

    image with no caption

    and the angle is

    image with no caption

    . 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.

  6. 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.

  7. 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.

  8. 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.

  9. Can you think of a way to use the Hough transform to identify any kind of shape with a distinct perimeter? Explain how.

  10. Look at the diagrams of how the log-polar function transforms a square into a wavy line.

  11. 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?

  12. 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.

  13. 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.

  14. 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.

  15. 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?

  16. Practice histogram equalization on images that you load in, and report the results.

  17. Load an image, take a perspective transform, and then rotate it. Can this transform be done in one step?