6
$\begingroup$

I strongly suspect that there should be a built-in solution to the following problem:

I have a binary image like this:

image = Binarize@ColorNegate@Graphics[{
     Disk[{0, 0}, 1],
     Disk[{-1.5, 1.5}, 0.5],
     Disk[{3, 1}, {1, 1.5}]
     }, PlotRange -> 3 {{-1, 1}, {-1, 1}}]

enter image description here

I want to process the components with functions like MorphologicalComponents and ComponentMeasurements. How can I exclude components that touch the image boundary? In this example the partially cropped ellipse should be excluded.

$\endgroup$
  • $\begingroup$ I am almost certain I have seen options for this somewhere, but I can't seem to find it in the docs. $\endgroup$ – Szabolcs Mar 11 at 16:58
  • 2
    $\begingroup$ Use DeleteBorderComponents first to remove them? $\endgroup$ – SHuisman Mar 11 at 17:06
  • 1
    $\begingroup$ @SHuisman Will you post an answer or will you vote to close as "easily found in the docs"? I really didn't find it, even knowing I've seenit. $\endgroup$ – Szabolcs Mar 11 at 17:07
9
$\begingroup$

Use DeleteBorderComponents first to remove them:

image = DeleteBorderComponents[image]

There is also:

ComponentMeasurements[image, ... , #AdjacentBorderCount == 0 &]
| 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.