How to separate image from alpha using Quartz Composer?

Apologies in advance if this isn't the correct forum to pose questions about Quartz Composer.


I'm attempting to construct a Quartz Composer composition that will take an image containing transparency, and — within the structure of that composition — disect the image so that I can perform separate operations on the alpha mask and the full image (i.e. as if the mask did not exist). This would be akin to opening a PNG or TIFF in GraphicConverter, then accessing the images I want via Show Alpha Channel and Remove Alpha Channel.


I'm able to easily access the alpha channel by applying a Color Martix patch to the image, but I can't seem to figure out how to get to the full "unmasked" image.


Can anyone nudge me in the right direction as to how I could remove the alpha mask from an image?


Thanks!!


John

iMac and MacBook, Mac OS X (10.6.6), 20th Anniversary Mac, 128K Mac, original Apple II

Posted on Feb 22, 2012 4:15 PM

Reply
6 replies

Mar 7, 2012 5:14 AM in response to John Purlia

Hi John,


You could use the Core Image Filter to extract the Alpha channel as a mask, and then other filters to use that mask.


In the 'Settings' pane of 'Patch Inspector' for the 'Core Image Filter' place the following Core Image Kernel routine code:

/*

A Core Image kernel routine

Alpha to Mask White Opaque, Black Transparent

*/

kernel vec4 alphaToBlackWhite(sampler image)

{

vec4 pixelValue = sample(image, samplerCoord(image)); // Get a pixel

          unpremultiply(pixelValue);

          pixelValue.r = pixelValue.a; // Red channel

          pixelValue.g = pixelValue.a; // Green channel

          pixelValue.b = pixelValue.a; // Blue channel

           pixelValue.a = 1.0; // Alpha Channel make Opaque

          return premultiply(pixelValue);

}



Alternatively you could rewrite the above Kernel, more details on writing Core Image Kernels is in the developer documentation 'Image Tutorial: Writing Kernels'


Hope this helps,


Neil.

Mar 7, 2012 9:51 AM in response to John Purlia

I stumbled across your post today whilst searching for a solution to similar problem I had myself so glad it helped us both.


I wouldn't want to bring you out of retirement but, there are more patches that you can program...


In the 'Library' window from the popup menu – which by default is set to 'Library' – choose 'Program'.

This will filter the patches down to:


  • Core Image Filter (as mentioned above);
  • GLSL Shader;
  • JavaScript;
  • OpenCL Kernel.


In case you haven't found this, another useful patch is 'Composite' allows you to change standard blending filters from a popup menu, rather than dropping in a new patch and having to wire it up each time.


Have fun with your art.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to separate image from alpha using Quartz Composer?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.