SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
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: A Powerful Framework for Image Processing

Más contenido relacionado

La actualidad más candente

Xamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego MeetupXamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego MeetupSeamgen
 
Design your 3d game engine
Design your 3d game engineDesign your 3d game engine
Design your 3d game engineDaosheng Mu
 
【Unite 2017 Tokyo】Unity5.6での2D新機能解説
【Unite 2017 Tokyo】Unity5.6での2D新機能解説【Unite 2017 Tokyo】Unity5.6での2D新機能解説
【Unite 2017 Tokyo】Unity5.6での2D新機能解説Unity Technologies Japan K.K.
 
OGDC2013_ Spine Animation_ Mr Alviss Ha
OGDC2013_ Spine Animation_ Mr Alviss HaOGDC2013_ Spine Animation_ Mr Alviss Ha
OGDC2013_ Spine Animation_ Mr Alviss Haogdc
 
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_glchangehee lee
 

La actualidad más candente (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 a Core Image: A Powerful Framework for Image Processing

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)Chris Adamson
 
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 MachineESUG
 
Core Animation
Core AnimationCore Animation
Core AnimationBob McCune
 
High resolution animated scenes from stills
High resolution animated scenes from stillsHigh resolution animated scenes from stills
High resolution animated scenes from stillsCarolyn Rose
 
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 CoreTextMugunth Kumar
 
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 EdgeBill Liu
 
iOS Game Development With UIKit
iOS Game Development With UIKitiOS Game Development With UIKit
iOS Game Development With UIKitMartin Grider
 
Image Conversion Library
Image Conversion LibraryImage Conversion Library
Image Conversion LibraryIshita Gupta
 
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...Gerke Max Preussner
 
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.2013Kevin Munc
 
TMD2063 | Digital Animation - Chapter 3
TMD2063 | Digital Animation - Chapter 3TMD2063 | Digital Animation - Chapter 3
TMD2063 | Digital Animation - Chapter 3Diyana Harithuddin
 
Dimond recognition system
Dimond recognition systemDimond recognition system
Dimond recognition systemAmit Gandhi
 
Core image presentation
Core image presentationCore image presentation
Core image presentationKyle Stewart
 
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 architectureSebastien Kuntz
 
Masterin Large Scale Java Script Applications
Masterin Large Scale Java Script ApplicationsMasterin Large Scale Java Script Applications
Masterin Large Scale Java Script ApplicationsFabian Jakobs
 
Motion design in FIori
Motion design in FIoriMotion design in FIori
Motion design in FIoriRoman Rommel
 

Similar a Core Image: A Powerful Framework for Image Processing (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
 

Último

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 

Último (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 

Core Image: A Powerful Framework for Image Processing

  • 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