Muzamil Hassan
Muzamil Hassan

Reputation: 851

core image filter apply

how i apply CIToneCurve filter i applied

  filter= [CIFilter filterWithName:@"CIScreenBlendMode"];
     [filter setValue:beginImage1 forKey:kCIInputImageKey];
     [filter setValue:beginImage forKey:@"inputBackgroundImage"];

different filters with this approach now i want to apply CIToneCurve how should i apply this with these parameters

inputImage A CIImage class whose display name is Image.

inputPoint0 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 1. Default value: [0, 0] Identity: [0, 0]

inputPoint1 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 2l. Default value: [0.25, 0.25] Identity: [0.25, 0.25]

inputPoint2 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 3l. Default value: [0.5, 0.5] Identity: [0.5, 0.5]

inputPoint3 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 4. Default value: [0.75, 0.75] Identity: [0.75, 0.75]

inputPoint4 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 5. Default value: [1, 1] Identity: [1, 1]

i write these but my app crash with out giving any error

Upvotes: 2

Views: 5421

Answers (1)

nacho4d
nacho4d

Reputation: 45108

each filter accepts different kind of parameters but once you get use to them is pretty easy. You didn't post what error you are getting but this works for me:

- (void)doCIToneCurveFilter
{
    // Set an appropriate image. A bit dark so we see the results clearer
    // This image is being taken from http://photo.tutsplus.com/tutorials/post-processing/adobe-camera-raw-for-beginners-tone-curve/
    imageView.image = [UIImage imageNamed:@"turtles"];
    imageView.frame = CGRectMake(0, 0, imageView.image.size.width*0.7, imageView.image.size.height*0.7); // shrank this a bit 2 images fit on screen

    // Make the input image recipe
    CIImage *inputImage = [CIImage imageWithCGImage:imageView.image.CGImage];

    // Make tone filter filter
    // See mentioned link for visual reference
    CIFilter *toneCurveFilter = [CIFilter filterWithName:@"CIToneCurve"];
    [toneCurveFilter setDefaults];
    [toneCurveFilter setValue:inputImage forKey:kCIInputImageKey];
    [toneCurveFilter setValue:[CIVector vectorWithX:0.0  Y:0.0] forKey:@"inputPoint0"]; // default
    [toneCurveFilter setValue:[CIVector vectorWithX:0.27 Y:0.26] forKey:@"inputPoint1"]; 
    [toneCurveFilter setValue:[CIVector vectorWithX:0.5  Y:0.80] forKey:@"inputPoint2"];
    [toneCurveFilter setValue:[CIVector vectorWithX:0.7  Y:1.0] forKey:@"inputPoint3"];
    [toneCurveFilter setValue:[CIVector vectorWithX:1.0  Y:1.0] forKey:@"inputPoint4"]; // default

    // Get the output image recipe
    CIImage *outputImage = [toneCurveFilter outputImage];

    // 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]];

    // Draw the image in screen
    UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:cgimg]];
    CGRect f = imageView2.frame;
    f.origin.y = CGRectGetMaxY(imageView.frame);
    f.size.width = imageView.frame.size.width;
    f.size.height = imageView.frame.size.height;
    imageView2.frame = f;

    [self.view addSubview:imageView2];
}

And this is the result:

Result CIToneCurve

The image I used was taken from here and there you can find the curve I approximated in this example:

curve

PS: If you are wondering why the my result image does not look exactly the same as the result in the link it is because my image is a partial image and color distribution is different. Alike but not exactly the same. So applying exactly the same curve will not give the exactly same result.

I hope it helps

Upvotes: 9

Related Questions