Hey,
I have written the MATLAB code according to the algo given in he tutorials for edge detection.
"Edge Detection
Edge detection is a technique to locate the edges of objects in the scene. This can be useful for locating the horizon, the corner of an object, white line following, or for determing the shape of an object. The algorithm is quite simple:
sort through the image matrix pixel by pixel
for each pixel, analyze each of the 8 pixels surrounding it
record the value of the darkest pixel, and the lightest pixel
if (darkest_pixel_value - lightest_pixel_value) > threshold)
then rewrite that pixel as 1;
else rewrite that pixel as 0;
What the algorithm does is detect sudden changes in color or lighting, representing the edge of an object."
I want to know how to get the threshold value for best results.
If I calculate the threshold according to the original method of finding the mean of all the elements of image matrix, then its too big a value.
See, in this algo we find the difference between the largest and smallest neighbour of a matrix element. Now for a grayscale image, this difference is not too big, not more than 50 at extreme points and generally around 20-30. But as the pixel value is almost same for all pixels in a grayscale image and hence the threshold calculated by the normal method is always greater than the difference and the resulting image is completely black.
I ran the code on a 640x480 grayscale image. It gave the best result at threshold = 20 whereas the threshold calculated by computing the mean was coming out to be = 115.
Now how to calculate the accurate threshold?