Make borders not rounded - modifying fmw42's contour script

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
Zelf
Posts: 12
Joined: 2015-05-12T11:14:41-07:00
Authentication code: 6789

Make borders not rounded - modifying fmw42's contour script

Post by Zelf » 2018-11-29T11:50:21-07:00

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

snibgo
Posts: 10931
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2018-11-29T12:13:19-07:00

Try changing "disk:20" to "square:20".
snibgo's IM pages: im.snibgo.com

Zelf
Posts: 12
Joined: 2015-05-12T11:14:41-07:00
Authentication code: 6789

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

Post by Zelf » 2018-11-29T12:23:27-07:00

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

snibgo
Posts: 10931
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2018-11-29T12:45:52-07:00

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.)
snibgo's IM pages: im.snibgo.com

Zelf
Posts: 12
Joined: 2015-05-12T11:14:41-07:00
Authentication code: 6789

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

Post by Zelf » 2018-11-29T13:00:21-07:00

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?

Post Reply