In a month...
This is an example of CIColorMatrix
, setting all its parameters :)
-(void)doCIColorMatrixFilter { // Make the input image recipe CIImage *inputImage = [CIImage imageWithCGImage:[UIImage imageNamed:@"facedetectionpic.jpg"].CGImage]; // 1 // Make the filter CIFilter *colorMatrixFilter = [CIFilter filterWithName:@"CIColorMatrix"]; // 2 [colorMatrixFilter setDefaults]; // 3 [colorMatrixFilter setValue:inputImage forKey:kCIInputImageKey]; // 4 [colorMatrixFilter setValue:[CIVector vectorWithX:1 Y:1 Z:1 W:0] forKey:@"inputRVector"]; // 5 [colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:1 Z:0 W:0] forKey:@"inputGVector"]; // 6 [colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:1 W:0] forKey:@"inputBVector"]; // 7 [colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:1] forKey:@"inputAVector"]; // 8 // Get the output image recipe CIImage *outputImage = [colorMatrixFilter outputImage]; // 9 // Create the context and instruct CoreImage to draw the output image recipe into a CGImage CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]]; // 10 // Draw the image in screen UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:cgimg]]; CGRect f = imageView2.frame; f.origin.y = CGRectGetMaxY(imageView.frame); imageView2.frame = f; [self.view addSubview:imageView2]; }
So here is what the selection does:
In 1
we create ciimage, if you get zero, then make sure you pass the correct UIImage / CGImage or path.
In 2
create a filter, you know that :)
In 3
set the default filter parameters, the CoreImage programming guide offers us to do this, though (I have not experimented with some strange / bad things if avoided.)
In 4
set the input ciimage
From 5
to 8
we set the parameters. For example, I made a red vector {1,1,1,0}, so the image looks reddish. 6
, 7
and 8
not needed here, since their values โโcoincide with the default values โโ(remember, we called -setDefaults
?), But for educational purposes, I think they are fine :)
At 9
set the output image, although it has not yet been drawn.
Finally, at 10
you tell CoreImage to draw the output image in CGImage, and we will put this CGImage in UIImage and inside UIImageView.
This is the result (I used the same image as this ):
Hope this helps.