This is the first time I'm experimenting with Core Image (on OS X, 10.7.3) and running into a brick wall. I am sure this is something stupid that I am doing and I need someone more familiar with the framework to point me to this.
Consider the following code (suppose imageURL is a valid file URL pointing to a jpg on disk):
CIImage *inputImage = [CIImage imageWithContentsOfURL:imageURL]; CIFilter *filter = [CIFilter filterWithName:@"CIAreaAverage" keysAndValues: kCIInputImageKey, inputImage, kCIInputExtentKey, [inputImage valueForKey:@"extent"], nil]; CIImage *outputImage = (CIImage *)[filter valueForKey:@"outputImage"];
When you run this code, the last line starts:
0 CoreFoundation 0x00007fff96c2efc6 __exceptionPreprocess + 198 1 libobjc.A.dylib 0x00007fff9153cd5e objc_exception_throw + 43 2 CoreFoundation 0x00007fff96cbb2ae -[NSObject doesNotRecognizeSelector:] + 190 3 CoreFoundation 0x00007fff96c1be73 ___forwarding___ + 371 4 CoreFoundation 0x00007fff96c1bc88 _CF_forwarding_prep_0 + 232 5 CoreImage 0x00007fff8f03c38d -[CIAreaAverage outputImage] + 52 6 Foundation 0x00007fff991d8384 _NSGetUsingKeyValueGetter + 62 7 Foundation 0x00007fff991d8339 -[NSObject(NSKeyValueCoding) valueForKey:] + 392
Now, the Master Image Filter Reference clearly states that CIAreaAverage "Returns a single-pixel image containing the average color for the region of interest." Indeed, it is even more difficult when I consider the filter attributes in the debugger (before trying the call to valueForKey: :
(lldb) po [filter attributes] (id) $3 = 0x00007fb3e3ef0e00 { CIAttributeDescription = "Calculates the average color for the specified area in an image, returning the result in a pixel."; CIAttributeFilterCategories = ( CICategoryReduction, CICategoryVideo, CICategoryStillImage, CICategoryBuiltIn ); CIAttributeFilterDisplayName = "Area Average"; CIAttributeFilterName = CIAreaAverage; CIAttributeReferenceDocumentation = "http://developer.apple.com/cgi-bin/apple_ref.cgi?apple_ref=//apple_ref/doc/filter/ci/CIAreaAverage"; inputExtent = { CIAttributeClass = CIVector; CIAttributeDefault = "[0 0 640 80]"; CIAttributeDescription = "A rectangle that specifies the subregion of the image that you want to process."; CIAttributeDisplayName = Extent; CIAttributeType = CIAttributeTypeRectangle; CIUIParameterSet = CIUISetBasic; }; inputImage = { CIAttributeClass = CIImage; CIAttributeDescription = "The image to process."; CIAttributeDisplayName = Image; CIUIParameterSet = CIUISetBasic; }; outputImage = { CIAttributeClass = CIImage; }; }
There outputImage right there - set as type CIImage!
So what am I doing wrong? All the documents and tutorials that I have seen show that -valueForKey: is the correct way to access attributes, including outputImage .