Now we will see a few sample images whose edges we wish to detect using Canny detector. However we shall see preprocessing will help in producing better edges. However the preprocessing depends on the particular problem present in the image.
This image is very low contrast. It is clear from the histogram of the original image that image does have enough dynamic range. The pixels are mostly concentrated on the higher sides and hence the images appears low contrast. The edges extracted from it are shown below
Original image
Histogram of intensities
Edges extracted from original image
We can rectify this problem by doing a histogram equalization on the original image. Below is histogram equalized image and edges extracted from it. Though the image quality is enhanced by histogram equalization, the edge detection performance seems to have degraded, as the edges look noisy. Therefore simple edge extraction on the original image seems to suffice without any preprocessing.
Histogra equalized image
Histogram of equalized image
Edges of histogram equalised image
The image is very dark. The histogram suggests that histogram equalization might help. After histogram equalization we get the following image and histogram:
Original
Histogram
Equalized image
Histogram of equalized image
Looking at the histogram equalized image, we see it is noisy, hence we pass it through a Gaussian filter. Now we compare the Canny detection results:
Edges of original image
Edges from equalized image
Edges of gaussian filtered image
Edges of equalized + gaussian filtered image
Edge detection on the original image gives very sparse edges. The equalized image gives very noisy edges. The gaussian filtered image or equalized+filtered images give better edges.
The original image is shown below. We observe that the image is very noisy. It seems to contain both Gaussian noise and salt and pepper noise.
Original image
Edge detection on original image
Gaussian noise can be removed by Gaussian filter, and salt and pepper noise can be removed using median filtering. We should apply median filtering first. If we apply Gaussian filtering first, it will spread around the salt and pepper noise, but if we do median filtering first, it will completely remove the salt/pepper noise.
Edges of median filtered image
Edges of median + gaussian filtered image
The next image is a colour image with coloured salt and pepper noise. The image is from this site. Since it has coloured salt and pepper noise, we apply median filtering on each channel separately. We observe that though median filtering helped restore the image, it did not have a significant effect on edge detection. That is because edge detection is robust to light salt/pepper noise anyway.
Original image
Edge of original image
Filtered image
Edge of filtered image
Consider this pixelated image. We cannot hope to perform Canny edge detection on this, as it would give us the pixel borders as shown below.
Pixellated image
Edge detection on original image
Therefore some smoothing is required. We can smooth it in two ways:
With sigma of Gaussian filtering set to 3, we get similar results for both methods. For a smaller sigma, we do not get enough smoothing, and the pixel edges persist. For large sigma, the image becomes too blurred. It seems that the upsampled image gives slightly better edges.
Gaussian smoothed
Edges detected from gaussian smoothed image
Upsampled image
Edges from upsampled image