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.

    1. Run this kernel on an image and display the results.

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

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

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

Get Learning OpenCV now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.