Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CITemperatureAndTint for image in iOS

Is there any sample code or example for CITemperatureAndTint? I have read its documentation but i need some example to implement it.

like image 699
Prerna chavan Avatar asked Jul 13 '12 04:07

Prerna chavan


1 Answers

CIFilter *yourFilter = [CIFilter filterWithName:@"CITemperatureAndTint"];
[yourFilter setValue:yourInputImage forKey:@"inputImage"];
[yourFilter setValue:[CIVector vectorWithX:6500 Y:500] forKey:@"inputNeutral"]; // Default value: [6500, 0] Identity: [6500, 0]
[yourFilter setValue:[CIVector vectorWithX:1000 Y:630] forKey:@"inputTargetNeutral"]; // Default value: [6500, 0] Identity: [6500, 0]
CIImage *resultImage = [yourFilter valueForKey: @"outputImage"];
UIImage *resultOutputImage = [UIImage imageWithCGImage:[context createCGImage:resultImage fromRect:resultImage.extent]];    

You can see what values for color temperature give you which colors in this wikipedia link.

For Reference

CITemperatureAndTint has three input parameters: Image, Neutral and TargetNeutral. Neutral and TargetNeutral are of 2D CIVector type, and in both of them, note that the first dimension refers to Temperature and the second dimension refers to Tint. What the CITemperatureAndTint filter basically does is computing a matrix that adapts RGB values from the source white point defined by Neutral (srcTemperature, srcTint) to the target white point defined by TargetNeutral (dstTemperature, dstTint), and then applying this matrix on the input image (using the CIColorMatrix filter). If Neutral and TargetNeutral are of the same values, then the image will not change after applying this filter. I don't know the implementation details about iPhoto, but I think the two slide bars give the Temperature and Tint changes (i.e. differences between source and target Temperature and Tint values already) that you want to add to the source image.

like image 136
Bala Avatar answered Oct 28 '22 06:10

Bala