3
$\begingroup$

I have a binary image of a line, like this one:

enter image description here

What I'd like to do is to dilate the line, but only towards the 'inside' of the line. That is, to add white pixels towards the center of the image, using DiskMatrix[] or any other kernel of a given radius/size. I've been trying to find ways to do this for a bit but I have no idea where/how to begin.

Thanks!

$\endgroup$
4
  • 1
    $\begingroup$ WatershedComponents[img]//Colorize//Binarize $\endgroup$
    – b3m2a1
    Mar 8, 2021 at 5:04
  • $\begingroup$ @b3m2a1 yeah, this works by filling the entire 'inside'. But what I really want is to control how much does it fill, that's why I mentioned the kernel size. Thanks! $\endgroup$ Mar 8, 2021 at 5:27
  • $\begingroup$ Ah you can use Dilation as usual and use that as a mask to clip off anything outside, e.g. Dilation[woof, 50]*mask will give you a nice result if woof is the OG image and mask is what comes out of that $\endgroup$
    – b3m2a1
    Mar 8, 2021 at 5:28
  • $\begingroup$ Hmm. I see. If you add it as an answer I can accept it. $\endgroup$ Mar 8, 2021 at 5:29

1 Answer 1

8
$\begingroup$

Because the Manipulate is fun:

woof = Import["https://i.stack.imgur.com/JKnlk.png"];
mask = WatershedComponents[woof] // Colorize // Binarize

enter image description here

Manipulate[Dilation[Binarize@woof, i]*mask, {i, 1, 100}]

enter image description here

$\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.