Page 1 of 1

How to extract a polygon from an image

Posted: 2014-03-26T09:44:35-07:00
by seth5744
I would like to use Magick++ or the imagemagick command line to extract
an n-gon from an image. The n-gon is specified by a list the
vertices. So, for example I would like to be able to extract an n-gon
defined by the points a,b,c,d,e,f,g,h which define a region that looks
like:

Code: Select all

          a---------h
          |         |
          |         g-f
          |           |
          b---c       |
              |       |
              |       |
              |       |
              d-------e
out of, for example, a png image. I assume I have to do some kind of
composite operation with an image mask, or if using Magick++ define a
DrawableClipPath. But, I can't find any documentation for this. Any
help would be appreciated.

p.s. My preference is to do this using C++ and Magick++ because I have other
processing to do, but am happy to do it with the commandline too.

Re: How to extract a polygon from an image

Posted: 2014-03-26T09:59:11-07:00
by snibgo
Perhaps you want the same as another user: see viewtopic.php?f=1&t=25228 where I give a command that turns everything outside a polygon transparent, and trims.

If you want something different, just say.

I can't help with the equivalent in Magick++.

Re: How to extract a polygon from an image

Posted: 2014-03-26T10:16:39-07:00
by seth5744
Your solution is almost exactly what I want. However, the non-included regions are transparent, and I want them to be white. Is there a simple fix?

Re: How to extract a polygon from an image

Posted: 2014-03-26T10:45:05-07:00
by snibgo
Put "-background White -flatten" before the output filename.