find empty area

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

If there is only one such area, you can do something like this...

Code: Select all

  convert  image.jpg  -matte  -fill none  -opacity white \
                 -fill white -colorize 100%  -trim   info:
to ouptut the minimal rectangle for that area.
This converts pure white into a shaped mask and thing -trim is used to locate that area.
Add a -fuzz factor if the white is not pure white. See
http://www.cit.gu.edu.au/~anthony/graph ... olor/#fuzz

If multiple areas are posible, then you will need to also generate that mask, but you will probably have to do something like a "-verbose -segment arg" to find them. I have not however played much with -segment, so I would love to know what you come up with.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

-opacity takes a color value. any color that is EXACTLY that color is replaved by the -fill color.

To also replace 'near' colors you need to add a -fuzz factor. See the link I gave above. The rest of the code is to basically invert the color selection so all colors which are not transparent are changed to white so that -trim can be used to locate the area of the original color.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply