Re: Merging two images
Felix Saphir <[email protected]> Mon, 02 Nov 2009 16:00:10 +0100
| Newsgroups | gmane.comp.video.graphicsmagick.apis |
|---|---|
| Message-ID | <[email protected]> |
Bob Friesenhahn schrieb: > On Thu, 29 Oct 2009, Felix Saphir wrote: >> >> The next thing for me is to extract parts of the resulting image >> (rectangular and polygon shapes), and I think, it's going to be an >> interesting journey :) > > That sounds fun. Since raster images are rectangular, you will need to > do something with the opacity channel to make the hidden pixels > transparent, and perhaps by using composition. There is clip mask > functionality in GraphicsMagick which probably could be used. There is > also a poorly documented functionality in which a black/white image can > be used to mask out pixels from being changed by an image processing > operation, but that only works if the current image is changed, and not > for algorithms which produce a new image. Yes, thought about that as well, and just to document the black/white mask algorithm a bit for others reading this mailing list: 1) define two colors, eg. "Magick::Color keep( MaxRGB, MaxRGB, MaxRGB )" and "Magick::Color discard( 0, 0, 0 )" 2) set the mask's fill and stroke color to "keep" background color to "discard" and draw the shape to the mask 3) set the original image's matte to true and matte color to "keep" 4) compose the mask onto the original image using the Magick::CopyOpacityCompositeOp algorithm This will probably not work with all image types, comments and enhancements are welcome! Anyway, since I need a white background around each extracted shape, I use a different approach: The shape is drawn in black on a white background, and then composed over the original image with Magick::LightenCompositeOp as algorithm. That way, everything outside my shape becomes very bright (i.e. white), while nothing is changed on the inside. Or is there a better way to do this? Regards, Felix -- /^\ | ASCII Ribbon Campaign \ / | - no HTML in email and news x | http://www.asciiribbon.org/ / \ | http://www.gerstbach.at/2004/ascii ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference