Image Processing Edge Detection: Remove unwanted edges

45 views (last 30 days)
Philip on 15 Apr 2011
Commented: Rongsong Yang on 5 Jul 2018
Firstly, apologies for the length of this question. But I feel it needs a little bit of an explanation so that my objective can be understood.
I want to detect only the edge that surrounds the subject of the image, but edge detection operators such as canny, sobel etc. (with varying thresholds) all yield too many edges (false positives for what I want to achieve)...
My workaround for this is to use segmentation to pick out only the subject of the image and the background, and I seem to have done this successfully. I have then run canny edge detection on this segmented version, which appears at first to give me the edge I want. However, after a deeper examination, these edges are off by sometimes up to 4 pixels because of the way the segmentation process worked. So I am wondering if there is now a way to use the segmented edge image to say "keep all edges within 5 pixels of this edge, and remove all the others"...
Can anyone tell me how I can do this?

Answers (2)

Sean de Wolski
Sean de Wolski on 15 Apr 2011
doc bwdist
on a logical image will return the distances to the edge. Then you can use a threshold (e.g D <=5) to expand it.
Ps. Your question was well written and we don't mind the length ;) However, as a forum, whenever an image processing related question is asked, it's strongly advised to post an image. You can see how do this by clicking on "Markup Help". We may be able to help you find a better way altogether.
  1 Comment
Philip on 15 Apr 2011
Thanks for the advice! Taking it onboard, I've posted attachments of the two images:
Full edge detection:
Canny edge (from segmented image):
As you will see, the Canny edge detection from the segmented image is "broken" (incomplete), and is also not exactly on the edge of the object. I therefore need to find the respective "closest" edge from the "full edge detection" image and use that instead - whilst also dropping all the other edges that appear in this image.

Sign in to comment.

Sean de Wolski
Sean de Wolski on 15 Apr 2011
D = bwdist(canny_edge_detection); % Distance xform
M = full_edge_detection_image&(D<5); % Edges in the full edge image and within within 5 of the canny.
Could you post the original image too.
Rongsong Yang
Rongsong Yang on 5 Jul 2018
what do you mean "full_edge_detection_image&(D<5)"? It seems undefined in Matlab

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by