Canny Edge Detection
This program implements Canny edge detection with the use OpenCV's cvCanny
function. The purpose is to get a glimpse of how low/high thresholds and mask
size affect the effect of Canny edge detection, not the implementation of
Canny algorithm per se.
1. Code/Program (Usage):
- The program tested on OpenCV in RedHat 8.0.
- Download the makefile (cannyMakefile)
and source code (canny.c).
- Download the test images: lena.pgm ,
o1r1.pgm
- Type: make -f cannyMakefile
- To do canny-detection, type: ./canny <input-image>
<output-BASE-file> <mask-size>
- All the output images are in "jpg" format, so only the base-file output
name is needed.
- I used the limited GUI provided by OpenCV, so I can adjust the Canny
parameters and save the edge images at any time.
- When you type 'S' or 's', the image will saved in the name format:
baseNamexMMMxNNNxSSS.jpg (MMM--the low
threshold value, NNN--the highthreshold value, SSS---the mask size), for example:
canniedLenax100x200x3.jpg.
- When you type spacebar, the program
will quit.
- For example, when I typed: ./canny lena.pgm canniedLena
3 , following will be displayed:
2. Result
- Canny edge on lena.pgm: mask size = 3, low / high thresholds
= 110 / 217.
- Canny edge on lena.pgm: mask size = 3, low / high thresholds
= 214 / 217.
- Canny edge on lena.pgm: mask size = 5, low / high thresholds
= 0 / 1705.
- Canny edge on lena.pgm: mask size = 5, low / high thresholds
= 244 / 458.
- Canny edge on lena.pgm: mask size = 5, low / high thresholds
= 891 / 1705.
- Canny edge on o1r1.pgm: mask size = 3, low / high thresholds
= 20 / 120.
- Canny edge on o1r1.pgm: mask size = 3, low / high thresholds
= 50 / 120.
- Canny edge on o1r1.pgm: mask size = 3, low / high thresholds
= 110 / 120.
3. Discussion.
- Because of the GUI interface, Canny edge detection has been taken
on the two input images under various parameter domains: mask size, low /high
thresholds. It can be divided into two cases: mask size with normal value
(3), and with a relatively large value (5).
- Under the case with large mask size, very big high threshold is needed.
It is strange that OpenCV has NOT provided help info on how to choose a reasonable
low/high threshold domain. Wild guess seems to be the only way. But
with the help of GUI slidebars we can quickly find the best low/high thresholds.
Following animated image shows such an effect.
- Much more detailed (smaller) edge can be detected with a relatively
big mask size than with small mask size.
- For a certain mask size, the high threshold is a more important factor
than low threshold.
- For a certain mask size and a chosen high threshold, the low
threshold can fine-tuen the coarse edge detected from the high threshold.
- It seems the best edge detection happens at high-threshold = 2 * low-threshold.