Playing with “Edge Detection”

A lot of articles explain what is edge detection, how to apply it, and the usage of it. Different edge detection techniques such as sobel, prewitt, and canny are easily found from any image processing software.

However, when we really want to perform edge detection for certain purpose, the problems arise. Look at the following example:



1. Original image
S = imread('p5-in1.jpg');
ShowColorImage(S,'0');



2. Edge detection using different methods
S2 = RGB2Gray(S);
S3 = edge(S2,'sobel');
ShowImage(S3,'0');





S4 = edge(S2,'prewitt');
ShowImage(S4,'0');





S5 = edge(S2,'canny');
ShowImage(S5,'0');




It seems like great but the usage of these output are useless until we really know what we want to do. For exmaple, we want to find the white rabbit, we need to perform some pre-processing before the edge detection so that we can fully utilize the function to suite to our needs.

3. Edge detection for the white rabbit
Since we know the RGB value for white color is [255,255,255], we can pre-process the image to extract the white color region from the image.

Sw = S(:,:,1)>200 & S(:,:,2)>200 & S(:,:,3)>200;
Sw2 = edge(double(Sw),'prewitt');
ShowImage(Sw2,'0');




Well, it seems like make more sense. Let's have a look on how to perform edge detection on the black rabbit:

4. Edge detection for the black rabbit

Sb = S(:,:,1)<40>
Sb2 = edge(double(Sb),'prewitt');
ShowImage(Sb2,'0');



The post processing can be used to remove unwanted noise.