Page 1 of 1

Make borders not rounded - modifying fmw42's contour script

Posted: 2018-11-29T11:50:21-07:00
by Zelf
I'm modifying @fmw42's awesome contour script. I want to first make the borders not rounded and follow exactly the contour of the original image.

Source Image

Image

Code: Select all

convert \
\( bb0e6dd421df72541a79f271fb4f1a90.png -bordercolor white -border 1 \
-alpha off -fuzz 1% -fill none \
-draw "matte 0,0 floodfill" \
-fuzz 2 -trim +repage \
-bordercolor none -border 50 \
-background white -alpha background \
-alpha off -write mpr:img -alpha on \
-alpha extract -morphology dilate disk:20 \
-blur 0x1 -level 0x75% -write mpr:msk1 +delete \) \
\( mpr:msk1 -negate -fill "gray(95%)" -opaque black \
-fill "white" -opaque white \
-blur 0x10 -write mpr:msk2 +delete \) \
\( mpr:msk1 -morphology edgein diamond:1 -negate -write mpr:edg +delete \) \
mpr:img mpr:msk1 -alpha off -compose copy_opacity -composite \
mpr:msk2 -reverse -compose over -composite \
"testing.png"
Result Image How do I modify the script to perfectly follow the contour of the image? In this example the border should be perfectly square, not rounded.

Image

Re: Make borders not rounded - modifying fmw42's contour script

Posted: 2018-11-29T12:13:19-07:00
by snibgo
Try changing "disk:20" to "square:20".

Re: Make borders not rounded - modifying fmw42's contour script

Posted: 2018-11-29T12:23:27-07:00
by Zelf
That certainly did it. However, if my image does have rounded corners or elements, is there a way to configure for exactly following the contour?

Image

Re: Make borders not rounded - modifying fmw42's contour script

Posted: 2018-11-29T12:45:52-07:00
by snibgo
Imagine the morphology shape (disk, square, whatever) tracing around your contour, with the centre of the shape always on the contour. The total area traced by the shape will be used to dilate the white.

Perhaps square will always give the result you want. If not, you'll need to define what you want. (With images.)

Re: Make borders not rounded - modifying fmw42's contour script

Posted: 2018-11-29T13:00:21-07:00
by Zelf
We'll do some testing with square. Thanks.

How would I modify this script to add the white border with square corners, but make transparent again everything outside of the white border?