extracting a shape from a transparent background efficiently
Posted: 2014-12-20T04:21:18-07:00
Suppose an image is given consisting of a monochrome shape (polygon) and a transparent background; there is no transparent border around the shape; points or edges touching the image border. If such images are rotated the ratio of the image may increase and the shape is not any more touching the image borders.
Has IM a function that can directly and efficiently extract a shape from a transparent background (the method must be available in PerlMagick)?
Until now I use four subroutines that determine the distance from left, right, top, bottom to the rotated shape and use those values to compute the parameters for a crop-command but this is expensive because in principle row by row and column by column must be checked for non transparent pixels.
Or perhaps there is a special kind of rotation available: In http://www.imagemagick.org/Usage/distorts/#srt one can read: „One argument is just a simple rotation about the images center, basically producing a similar result to the older Rotate Operator, but without any image size increase.“ But this will cause problems by potentially cutting of pieces of the shape.
Thanks for any help!
Has IM a function that can directly and efficiently extract a shape from a transparent background (the method must be available in PerlMagick)?
Until now I use four subroutines that determine the distance from left, right, top, bottom to the rotated shape and use those values to compute the parameters for a crop-command but this is expensive because in principle row by row and column by column must be checked for non transparent pixels.
Or perhaps there is a special kind of rotation available: In http://www.imagemagick.org/Usage/distorts/#srt one can read: „One argument is just a simple rotation about the images center, basically producing a similar result to the older Rotate Operator, but without any image size increase.“ But this will cause problems by potentially cutting of pieces of the shape.
Thanks for any help!