$24
Loading Images
Note that in this assignment, you will be performing operations on single channel (gray-scale) images, however some of the images sent to might be multi channel, so you will first need to convert them to single-channel gray-scale images. Please use the code snippet below.
import matplotlib.image as mpimg
from skimage.color import rgb2gray
image = rgb2gray( mpimg.imread( ’image.png’))
• Part I: Edge Detection
In this question, we will study various spatial filtering operations.
In this part of the assignment, you will perform edge detection on the provided three images: edge1.png, edge2.png, edge3.png (see Fig. 1). You will use different edge detection methods including Sobel, Prewitt and Canny edge detector. You will use gray-scale, single channel version of the provided images.
(a)
(c)
(b)
Figure 1: Input images to be used for edge detection in Part I.
1.1 Edge detection with Sobel and Prewitt operators
On each of the given three images, you will detect edges by using Sobel and Prewitt operators separately.
1. 3x3 Sobel Operators: For each given image above, detect horizontal and vertical edges by using Sobel operators and plot them. Include the results in your report. You will perform both horizontal and vertical edge detection on each image separately by using the corresponding 3x3 Sobel operator.
2. 3x3 Prewitt Operators: For each given image above, detect horizontal and vertical edges by using Prewitt operators and plot them. Include the results in your report. You will perform both horizontal and vertical edge detection on each image separately by using the corresponding 3x3 Prewitt operator.
3. Comment on your results: Show your results in your report and comment on them: are all the edges successfully detected? Are there any difference between using Sobel and Prewitt filters? If so, report which one yielded better result.
1.2 Edge detection with Canny edge detector
Another method that you will use for edge detection is Canny edge detector.
For this part, you have to find optimal parameters of Canny edge detector including the Gaussian smoothing parameter σ and the hysteresis thresholding parameters: T_low and T_high (in total three parameters) for each image.
2
1. Report the best values for each of those three parameters that worked best for you on each image. Comment on why you think that those parameters are the best parameters.
2. In your report, for comparison, include at least four different sets of parameters (i.e., you need to show different σ, T_low and T_high values and their corresponding result for four times).
3. How do your results compare to the results obtained from Sobel and Prewitt operators? If you see an improvement, comment on the potential reasons for that.
• Part II: Edge Linking with Hough Transform
For this part of the assignment, you will implement Hough transform and visualize the quality of your Hough implementation by drawing the detected lines on the input grayscale image. Hough transform operates on the detected edges to fit line(s) on the edge pixels. Please refer to the slides on Edge Detection. You should also check other online resources such as: PDF tutorial, and PDF tutorial for various presentations of Hough transform. In this section, you have three parts to work on. See below:
1. Implement Hough transform to predict the line parameters: ρ and θ for the lines that fit to the edges as discussed in the class. Use your implementation to find the lines shown on hough.png. To check your results, the expected output is shown in Fig. 2a. See Fig. 3a for the expected detected lines (shown in red).
(a)
(b)
Figure 2: Detected lines with Hough transform are shown on a basic sample image. Note: due to the nature of this particular sample image, the (grayscale) input image and the detected edges on that input image are considered the same.
2. You will use the images: edge1.png and hough2.png for the rest of this question (Image hough2.png is
shown in Fig. 3). Apply Hough transform to find the lines in the images: edge1.png and hough2.png
and highlight the found lines on each of those images. Remember: Typically, Hough Transform is used after applying an edge detection operator on the input image. First apply the edge detection algorithm of your choosing (from the ones used in the previous part) and then apply Hough Transform to find the lines on the detected edges. Plot both Hough Transforms (in ρ and θ space) and detected lines in the image space for each image. Did you need to use thresholding in Hough Space? If so, what threshold value worked best for you to find meaningful lines on each image?
3. For the image: edge.png, use Hough Transform and particularly find the line of the horizon that is clearly visible in the image. Report your results. Comment on the performance of your implementation, how well you were able to find the horizon line.
3
(a)
Figure 3: Image: hough2.png is shown.
4