SlideShare a Scribd company logo
Core Image



Mark Pavlidis
Co-founder
Flixel Photos Inc.

Toronto Cocoa and WebObjects Developers Group
2013/01/08
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
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
Overview
Apply an image filter to the source pixel data



                       Monochrome
                          Filter




 • Pixel Accurate
 • Non-destructive
 • Filters can be chained together
Core Image Runtime
How it works
Core Image Runtime
How it works




 • Operates on image data types from:
   • Core Graphics
   • Core Video
   • Image I/O
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
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
Core Image Inputs
• Photo Library and Files
   imageWithContentsOfURL:

• Live Video Capture
   imageWithCVPixelBuffer:
   imageWithCVImageBuffer:

• In Memory
   imageWithCGImage:

• GL Texture
   imageWithTexture:size:flipped:colorSpace:
Core Image Outputs
• CGImageRef
 • Output to UIImage, ImageIO, ALAssetLibrary
   createCGImage:fromRect:

• CAEAGLLayer
   drawImage:inRect:fromRect:
• CVPixelBufferRef
   render:toCVPixelBuffer:

• Bitmap
   render:toBitmap:rowBytes:bounds:format:colorSpace:
Simple Filter
// Create a CIImage
CIImage *ciImage = [CIImage imageWithContentsOfURL:myURL];



// Create a CIFilter
CIFilter *filter = [CIFilter
                  filterWithName:@”CIColorMonochrome”];
[filter setValue:ciImage forKey:kCIInputImageKey];
[filter setValue:@(0.5) forKey:@”inputIntensity];



// Render the filter output image into a UIImage
UIImage *uiImage = [UIImage
                   imageWithCIImage:filter.outputImage];
Filter Chains
// Filter 1
CIImage *output = [CIFilter
                   filterWithName:@”CIColorMonochrome”]
                   keysAndValues:
                   kCIInputImageKey, ciImage,
                   @”inputIntensity, @(0.5),
                   nil].outputImage;

// Filter 2
output = [CIFilter
          filterWithName:@”CIVignette”] keysAndValues:
          kCIInputImageKey, output,
          @”inputIntensity, @(0.5),
          @”inputRadius, @(1.5),
          nil].outputImage;

•CI defers pixel processing until render is requested
•CI optimizes the render graph (e.g., sepia then scale)
Math!
• An image filter is kernel
• Output is the convolution of the source & kernel
      Source                                 Output
                           Kernel

  2     2      2       1     1      1

  2     1      3      -1     2      1          6

  2     2      1      -1     -1     1




• Commutative, associative, distributive, associative
 with scalar multiplication, multiplicative identity
Demo - QuartzComposer
Demo - Simple filter
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
Face Detection
CIDetector
• Identifies rectangles that contain human faces
• Feature detection
    • eyes & mouth position, tracking ID and frame count (video)

 CIContext *context = [CIContext
                       contextWithOptions:nil];
 NSDictionary *opts = @{CIDetectorAccuracy,
 !    ! ! ! ! ! ! CIDetectorAccuracyHigh};
 CIDetector   *detector = [CIDetector
 !    ! !     ! ! ! detectorOfType:CIDetectorTypeFace
 !    ! !     ! ! ! ! !       context:context
 !    ! !     ! ! ! ! !       options:opts];
 NSArray *features = [detector featuresInImage:myImage
 !    ! ! ! ! !                        options:opts];
Demo - Redacted Faces
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
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
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
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)
[self release];
 Mark Pavlidis
 mark@pavlidis.ca
 Twitter: @mhp
 ADN: @mhp
Core Image

More Related Content

What's hot (8)

Xamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego MeetupXamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego Meetup
 
Design your 3d game engine
Design your 3d game engineDesign your 3d game engine
Design your 3d game engine
 
【Unite 2017 Tokyo】Unity5.6での2D新機能解説
【Unite 2017 Tokyo】Unity5.6での2D新機能解説【Unite 2017 Tokyo】Unity5.6での2D新機能解説
【Unite 2017 Tokyo】Unity5.6での2D新機能解説
 
OGDC2013_ Spine Animation_ Mr Alviss Ha
OGDC2013_ Spine Animation_ Mr Alviss HaOGDC2013_ Spine Animation_ Mr Alviss Ha
OGDC2013_ Spine Animation_ Mr Alviss Ha
 
Android - Graphics Animation in Android
Android - Graphics Animation in AndroidAndroid - Graphics Animation in Android
Android - Graphics Animation in Android
 
ProjectsSummary
ProjectsSummaryProjectsSummary
ProjectsSummary
 
Gl efficiency
Gl efficiencyGl efficiency
Gl efficiency
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
 

Similar to Core Image

High resolution animated scenes from stills
High resolution animated scenes from stillsHigh resolution animated scenes from stills
High resolution animated scenes from stills
Carolyn Rose
 

Similar to Core Image (20)

Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
 
Dino2 - the Amazing Evolution of the VA Smalltalk Virtual Machine
Dino2 - the Amazing Evolution of the VA Smalltalk Virtual MachineDino2 - the Amazing Evolution of the VA Smalltalk Virtual Machine
Dino2 - the Amazing Evolution of the VA Smalltalk Virtual Machine
 
Core Animation
Core AnimationCore Animation
Core Animation
 
High resolution animated scenes from stills
High resolution animated scenes from stillsHigh resolution animated scenes from stills
High resolution animated scenes from stills
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreText
 
Cocos2d programming
Cocos2d programmingCocos2d programming
Cocos2d programming
 
AISF19 - Unleash Computer Vision at the Edge
AISF19 - Unleash Computer Vision at the EdgeAISF19 - Unleash Computer Vision at the Edge
AISF19 - Unleash Computer Vision at the Edge
 
iOS Game Development With UIKit
iOS Game Development With UIKitiOS Game Development With UIKit
iOS Game Development With UIKit
 
Image Conversion Library
Image Conversion LibraryImage Conversion Library
Image Conversion Library
 
GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...
GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...
GDC Europe 2014: Unreal Engine 4 for Programmers - Lessons Learned & Things t...
 
Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013
 
Animation in iOS
Animation in iOSAnimation in iOS
Animation in iOS
 
TMD2063 | Digital Animation - Chapter 3
TMD2063 | Digital Animation - Chapter 3TMD2063 | Digital Animation - Chapter 3
TMD2063 | Digital Animation - Chapter 3
 
Dimond recognition system
Dimond recognition systemDimond recognition system
Dimond recognition system
 
Core image presentation
Core image presentationCore image presentation
Core image presentation
 
IEEE VR-SEARIS 2014 Keynote - MiddleVR - Philosophy and architecture
IEEE VR-SEARIS 2014 Keynote - MiddleVR - Philosophy and architectureIEEE VR-SEARIS 2014 Keynote - MiddleVR - Philosophy and architecture
IEEE VR-SEARIS 2014 Keynote - MiddleVR - Philosophy and architecture
 
Masterin Large Scale Java Script Applications
Masterin Large Scale Java Script ApplicationsMasterin Large Scale Java Script Applications
Masterin Large Scale Java Script Applications
 
Introduction to OCI Image Technologies Serving Container
Introduction to OCI Image Technologies Serving ContainerIntroduction to OCI Image Technologies Serving Container
Introduction to OCI Image Technologies Serving Container
 
Diagnosing issues in your ASP.NET applications in production with Visual Stud...
Diagnosing issues in your ASP.NET applications in production with Visual Stud...Diagnosing issues in your ASP.NET applications in production with Visual Stud...
Diagnosing issues in your ASP.NET applications in production with Visual Stud...
 
Motion design in FIori
Motion design in FIoriMotion design in FIori
Motion design in FIori
 

Recently uploaded

Recently uploaded (20)

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

Core Image

  • 1. Core Image Mark Pavlidis Co-founder Flixel Photos Inc. Toronto Cocoa and WebObjects Developers Group 2013/01/08
  • 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:
  • 10. Core Image Outputs • CGImageRef • Output to UIImage, ImageIO, ALAssetLibrary createCGImage:fromRect: • CAEAGLLayer drawImage:inRect:fromRect: • CVPixelBufferRef render:toCVPixelBuffer: • Bitmap render:toBitmap:rowBytes:bounds:format:colorSpace:
  • 11. Simple Filter // Create a CIImage CIImage *ciImage = [CIImage imageWithContentsOfURL:myURL]; // Create a CIFilter CIFilter *filter = [CIFilter filterWithName:@”CIColorMonochrome”]; [filter setValue:ciImage forKey:kCIInputImageKey]; [filter setValue:@(0.5) forKey:@”inputIntensity]; // Render the filter output image into a UIImage UIImage *uiImage = [UIImage imageWithCIImage:filter.outputImage];
  • 12. Filter Chains // Filter 1 CIImage *output = [CIFilter filterWithName:@”CIColorMonochrome”] keysAndValues: kCIInputImageKey, ciImage, @”inputIntensity, @(0.5), nil].outputImage; // Filter 2 output = [CIFilter filterWithName:@”CIVignette”] keysAndValues: kCIInputImageKey, output, @”inputIntensity, @(0.5), @”inputRadius, @(1.5), nil].outputImage; •CI defers pixel processing until render is requested •CI optimizes the render graph (e.g., sepia then scale)
  • 13. Math! • An image filter is kernel • Output is the convolution of the source & kernel Source Output Kernel 2 2 2 1 1 1 2 1 3 -1 2 1 6 2 2 1 -1 -1 1 • Commutative, associative, distributive, associative with scalar multiplication, multiplicative identity
  • 15. Demo - Simple filter
  • 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
  • 17. Face Detection CIDetector • Identifies rectangles that contain human faces • Feature detection • eyes & mouth position, tracking ID and frame count (video) CIContext *context = [CIContext contextWithOptions:nil]; NSDictionary *opts = @{CIDetectorAccuracy, ! ! ! ! ! ! ! CIDetectorAccuracyHigh}; CIDetector *detector = [CIDetector ! ! ! ! ! ! detectorOfType:CIDetectorTypeFace ! ! ! ! ! ! ! ! context:context ! ! ! ! ! ! ! ! options:opts]; NSArray *features = [detector featuresInImage:myImage ! ! ! ! ! ! options:opts];
  • 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)
  • 23. [self release]; Mark Pavlidis mark@pavlidis.ca Twitter: @mhp ADN: @mhp