Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there an easy way to select for morphological components which do not border/touch the edges of an image?

Taking this doodle as an example:

enter image description here

We'd want to only select morphological components that stay at least some critical distance from the edges of the image.

share|improve this question
    
For example, after labeling all connected components you can check pixels on the border and mark objects that you meet as unlabeled –  Eddy_Em Sep 2 '13 at 20:40
    
Are the morphological components you have in mind the same as the ones shown by MorphologicalComponents[yourimage] // Colorize? –  Michael E2 Sep 2 '13 at 20:46
1  
How about adding a border to the picture and then removing the border component (with everything attached to it)? –  David Carraher Sep 2 '13 at 20:48
3  
How about DeleteBorderComponents[yourimage]? –  Michael E2 Sep 2 '13 at 20:49
1  
@MichaelE2 hit the nail on the head, imho. –  David Carraher Sep 2 '13 at 20:51
show 3 more comments

1 Answer

up vote 5 down vote accepted

DeleteBorderComponents does what you ask. You can crop or pad the border, I suppose, if you wish to delete components that are close to the border.

img = Import["http://i.stack.imgur.com/2fQ3j.png"];
DeleteBorderComponents[img]

Mathematica graphics

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.