Randall
Randall

Reputation: 14839

CIFilters for compositing Red, Green, and Blue color channels

I am building a "Curves" editor for an image and would like to split out each color channel to run through the CIToneCurve filter before compositing them back together into a single color image. (I'm aware of the CIColorCurves filter, but that doesn't give me the control I want.)

I am able to separate the channels using three separate CIColorCube filters to generate the 3 separate color channels, but I'm not sure how to put them back together to form a single color image.

Using the maximumCompositingFilter and minimumCompositing filters works, but when I run the individual color photos through the ToneCurve, adjusting the highs or the lows (depending on which compositing filter I used) messes up the colors.

Upvotes: 1

Views: 729

Answers (2)

Randall
Randall

Reputation: 14839

Ended up using the suggestion posted by Frank Schlegel and using simple additive compositing. I had to write my own CIFilter to do that, but it was quite simple.

half4 rgbaComposite(sample_h redColor, sample_h greenColor, sample_h blueColor, sample_h alphaColor) {
        return half4(redColor.r, greenColor.g, blueColor.b, alphaColor.a);
}

This is for a metal backed CIFilter. Each input assumes that it only contains a single color channel.

Upvotes: 0

Flex Monkey
Flex Monkey

Reputation: 3633

You could do this with Accelerate.vImage.

Apple has an article that discusses converting an interleaved image to separate planar buffers: https://developer.apple.com/documentation/accelerate/optimizing_image_processing_performance

...and there's an article that discusses vImage / Core Image interoperability using CIImageProcessorKernel: https://developer.apple.com/documentation/accelerate/reading_from_and_writing_to_core_video_pixel_buffers. I can't remember if CIImageProcessorKernel supports single channel 8-bit images such as R8.

...also, this Apple sample code project may be of interest: Applying Tone Curve Adjustments to Images.

Upvotes: 2

Related Questions