2
$\begingroup$

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.

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

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

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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