ImageMagick - Convex Hull
Author: ImageMagick Studio LLC
Description: Use ImageMagick® to create, edit, compose, and convert bitmap images. Resize an image, crop it, change its shades and colors, add captions, and more.
Keywords: convex, hull, image converter, image resizer, image editor, photo editor, jpg converter, png converter, tiff converter, vector images, online, free, swiss army

The convex hull is the is the smallest area convex polygon containing the set of points inside it. The convex hull may be visualized as the shape enclosed by a rubber band stretched around the set of points.

The convex-hull string format returns a list of x,y coordinates of the vertices of the convex-hull polygon containing all the non-black pixels within it.

    magick [-fuzz XXX%] [-define convex-hull:background-color] -format "%[convex-hull]" info:

where the string format is sensitive to an optional `-fuzz` value and to an optional background color specified by the define. The command above will find the background color automatically according to the fuzz value unless the background color is defined. The fuzz value defaults to 0 when not specified.

For example, consider the following white rectangle on a black background:

The convex hull set of points may be computed as:

    magick rect.png -format "%[convex-hull]" info:
    190,121 193,122 281,154 377,189 378,190 377,193 345,281 310,377 309,378 306,377 218,345 122,310 121,309 122,306 154,218 189,122 190,121

The convex hull may also be drawn as a polygon (filled or unfilled) using `-draw` as follows:

    magick rect.png -set option:hull "%[convex-hull]" -fill none -stroke red -strokewidth 1 -draw "polygon %[hull]" blocks_hull.png

Here is an example using a non-convex shaped image on a black background:

    magick blocks_black.png -set option:hull "%[convex-hull]" -fill none -stroke red -strokewidth 1 -draw "polygon %[hull]" blocks_hull.png

Finally, here is an example with a non-constant, non-black background using -fuzz to determine the background color:

    magick barn_rot20.png -fuzz 30% -set option:hull "%[convex-hull]" -fill none -stroke red -strokewidth 1 -draw "polygon %[hull]" barn_rot20_hull.png