How to extract a polygon from an image

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
seth5744
Posts: 4
Joined: 2014-03-26T09:41:41-07:00
Authentication code: 6789

How to extract a polygon from an image

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to extract a polygon from an image

Post 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++.
snibgo's IM pages: im.snibgo.com
seth5744
Posts: 4
Joined: 2014-03-26T09:41:41-07:00
Authentication code: 6789

Re: How to extract a polygon from an image

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to extract a polygon from an image

Post by snibgo »

Put "-background White -flatten" before the output filename.
snibgo's IM pages: im.snibgo.com
Post Reply