2. Motivation
Why use Core Image?
• Image processing and analysis
• Fast, efficient filters
• Auto enhancement
• Feature detection
• Still and “real-time” video
• Simple Objective-C API
3. Definitions
• Image Filter
• a single transform or effect
• built-in or loaded from an Image Unit plugin (OS X only)
• Framework
<CoreImage/CoreImage.h>
• Key Classes
CIImage, CIFilter, CIContext
4. Overview
Apply an image filter to the source pixel data
Monochrome
Filter
• Pixel Accurate
• Non-destructive
• Filters can be chained together
6. Core Image Runtime
How it works
• Operates on image data types from:
• Core Graphics
• Core Video
• Image I/O
7. Core Image Runtime
How it works
• Built-in or plugin filters apply effects
• Written in the Core Image Kernel Language
• JIT complier assembles instruction pipeline
8. Core Image Runtime
How it works
• Executed on the GPU or CPU
• Low-level graphics processing encapsulated by CI
• Performance: GLSL capabilities of the GPU or
processing power of the CPU
9. Core Image Inputs
• Photo Library and Files
imageWithContentsOfURL:
• Live Video Capture
imageWithCVPixelBuffer:
imageWithCVImageBuffer:
• In Memory
imageWithCGImage:
• GL Texture
imageWithTexture:size:flipped:colorSpace:
16. Tips and Best Practices
• CIImage and CIFilter are autoreleased
• Use autorelease pools
• CIImage, CIContext are immutable and thread-safe,
CIFilter is not
• CIContext is expensive
• Stores a lot of state information so reuse them
• Avoid CA animations when rendering on GPU
• Use smaller images when possible
• Use Core Animation to upscale view, texture, framebuffer
• Disable colour management
• If real-time performance and/or reduced quality is
unnoticeable
19. OS X and iOS Differences
Portability
• Some CIImage create methods differ
• Has more built-in filters
• Permits custom filter plugins
• filter.outputImage is iOS only, use
[filter valueForKey:kCIOutputImage]
• Remember to [filter setDefaults]
• All input parameter keys have strings defined
20. Alternatives
• GPUImage (iOS)
✓Hand-tuned OpenGL ES shaders that are much faster than CI
✓Custom filters
- Lacks advanced features of Core Image
• Aviary
✓ Everyone is using it (Twitter, Flickr)
- Everyone is using it
• Only still images
• Hardcore - Write your own GL shaders
• Don’t be silly
21. Summary
Core Image
• Fast and efficient image processing framework
• Simple Objective-C API
• Encapsulates the low-level instruction details
• Many built-in filters
• Advanced processing features:
• Face Detection
• Auto Enhancement
• Real-time video filters
22. More Information
• Core Image Programming Guide
• WWDC 2012 Videos
• Session 510 - Getting Started with Core Image
• Session 511 - Core Image Techniques
• Sample Code
• https://github.com/mhpavl/FilterDemo
• https://github.com/mhpavl/RedactedFaces
• Core Image Funhouse (TBD)