Forgive me, I've never done any image work, ever, and I'm also completely new to IM. Still trying to explain it best I can and figure it out.
Start image
End current result (see the gap inside?)
What I actually want (little gap is gone). Other images have bigger gaps that I want to remove. So the threshold needs to be big enough. The point is, remove anything that isn't supposed to be there.
Code
Code: Select all
border=40
octagon=20
fuzz=0
blur=2x20
threshold=500
magick \( $1 +repage -bordercolor white -border 1x1 \
-fuzz $fuzz% -fill transparent -floodfill +0+0 white -shave 1x1 \
-bordercolor transparent -border ${border}x${border} \) \
\( -clone 0 -fill white -colorize 100% \) \
\( -clone 0 -alpha extract +write tmp0.png -write mpr:alpha -morphology edgeout octagon:$octagon +write tmp1.png \) \
-alpha off -compose over -composite +write tmp2.png \
\( mpr:alpha -morphology dilate octagon:$octagon \
-blur $blur -level 50x100% +write tmp3.png \) \
-alpha off -compose copy_opacity -composite -trim \
$1.gif
---------
Problem: there's a lot of other holes in the image I want to keep (the waterdrops), but still remove the gap that shouldn't be there
And removing all the gaps would remove my water drops too
My intended solution:
After the morphology edgeout code, use a write-mask right before the define connected code
Code: Select all
-morphology edgeout octagon:$octagon \
-write-mask mpr:alpha -define connected-components:mean-color=true \
-define connected-components:area-threshold=$threshold \
-connected-components 4 +write-mask
Problem, that didn't work. My next idea to solve it, is
1, overlay the alpha extraction (mpr:alpha) on top of the morphology edgeout image (this will make the inside completely white, except for the holes I want to remove)
It would look likes this:
2, remove the holes with the define connected (actually, I can use morphology close here now at this point since it won't have unintended side effects)
This would give this
3, use the alpha extraction to again cut out (turn black) the inside, just like the original edgeout will look, but minus the hole I don't want
This would result in the (see how the gap is now gone)
I don't know if this is the best way to approach this problem, but it's the best I can think of. I also don't know yet how to do what I want to (what I said above), because I'm still new, and still reading the docs. Is this the best way to accomplish my goal? Any other way? How would I do it?
I hope I explained clearly enough for you this time