Code: Select all
convert original.jpg -fuzz 25% -fill None -floodfill +0+0 '#0a613e' -alpha extract -morphology Open Disk mask.png
Now I would like to automatically detect the background color to make my script more reusable.
For that I get the average color of the borders.
First, here is how I get the color for the 200px north border:
Code: Select all
original.jpg -gravity North -crop 0x200+0+0 -resize 1x1 color.png
Now, the code for all borders of the image is:
Code: Select all
convert \( original.jpg -gravity North -crop 0x200+0+0 -resize 1x1 \) \( original.jpg -gravity South -crop 0x200+0+0 -resize 1x1 \) \( original.jpg -gravity East -crop 200x0+0+0 -resize 1x1 \) \( original.jpg -gravity West -crop 200x0+0+0 -resize 1x1 \) +append -resize 1x1 color.png