Why is the Canny edge detection in MATLAB different to OpenCV?
When I am comparing the outputs of using the “edge” function in MATLAB to the “Canny” function in OpenCV, I notice that the OpenCV implementation filters out more edges compared to the MATLAB’s implementation.
In MATLAB, I use:
>> edge(I, 'canny', [], 2.0)
In OpenCV (C++), I use:
>> cv::Canny(gray_image_smooth, edge, lowThresh, highThresh);
where I have tried to set the low and high thresholds using a manner similar to what is given in the “edge” function.
NOTE:-
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.
The ‘canny’ option in the MATLAB edge function attempts to be as precisely faithful as possible to the algorithm described in Canny’s Masters Thesis and PAMI paper:
There are several notable differences between the algorithm in “edge” and what appears in OpenCV:
1) Smoothing of input image prior to computation of gradients.
We use a 16x16 gaussian filter with sigma sqrt(2) prior to computing gradients. OpenCV does not do this step.
2) In the gradient computation step, we use a Derivative of Gaussian filter. OpenCV uses the Sobel operator.
3) Our non-maximum suppression step is different than that of OpenCV and is faithful to the algorithm described in the Canny paper.
4) Determining hysteresis threshold limits
We do this using a histogram approach, where the gradient magnitude is binned into 64 levels, and the threshold is based on a percentile of the gradient values (the 70% level is the high threshold). 28% (0.4 of the 70%) is the level for the lower threshold. So there are two levels: Any pixel in the top 30% of the gradient (which passes the non-maximum suppression step) is definitely an edge pixel. The pixels between high and low threshold are included in another list for the next step OpenCV does not have a mechanism for determining the hysteresis threshold limits automatically
SEE COMPLETE ANSWER CLICK THE LINK