If your image consists of Distinct Background and Foreground, you can get a threshold for this automatically, as described below in this article http://www.academypublisher.com/proc/isip09/papers/isip09p109.pdf .
- Calculate Otsu Threshold + Binary Threshold for your image.
- Use the Otsu threshold as a higher threshold for the Canny algorithm.
CODE:
Mat mCanny_Gray,mThres_Gray;
Mat mSrc_Gray=imread("Test.bmp",0);
double CannyAccThresh = threshold(mSrc_Gray,mThres_Gray,0,255,CV_THRESH_BINARY|CV_THRESH_OTSU);
double CannyThresh = 0.1 * CannyAccThresh;
Canny(mSrc_Gray,mCanny_Gray,CannyThresh,CannyAccThresh);
imshow("mCanny_Gray",mCanny_Gray);
You can also link to this stream.
source
share