CoreImage: Filters and Image Processing

Author: IT Sectr Published: 2026-05-06 Reading time: 9 min

CoreImage is an Apple framework for real-time image and video processing, providing dozens of built-in CIFilter for color correction, blurring, texture overlays and detection. According to Apple Documentation, CoreImage uses the GPU for high-performance pixel processing on iOS devices. The framework supports CIImage as an immutable image object and filter chains for composing effects without quality loss.

Key Takeaways

  • CoreImage — Apple framework for GPU-accelerated image and video processing on iOS and macOS
  • CIFilter — basic building block with over 200 built-in effects and support for custom Metal shaders
  • CIImage — immutable object representing an image in the CoreImage pipeline without binding to a specific format
  • CIDetector — component for detecting faces, text, QR codes and rectangles in an image
  • GPU processing — CoreImage automatically uses Metal or OpenGL for parallel GPU computations

What is CoreImage

CoreImage is an Apple framework for raster image and video processing, first introduced in macOS 10.4 Tiger and ported to iOS 5.0. Unlike Core Graphics or UIKit, CoreImage works at the pixel shader level, using the GPU for parallel computations. This allows applying complex effects — blur, color correction, morphing — to megapixel-resolution images in milliseconds.

CoreImage architecture is built on the concept of lazy evaluation: CIFilter does not perform processing until rendering in CIContext. The developer builds a chain of multiple CIFilters, connecting the output of one filter to the input of another, and only the render call launches the full GPU pipeline. This minimizes the number of passes through the graphics card and maintains performance.

CoreImage supports wide color gamut (P3, sRGB, linear sRGB), HDR images and working with 16-bit and 32-bit pixel formats. On devices with Neural Engine, CoreImage can combine GPU shaders with Core ML for intelligent processing — for example, automatic color correction based on machine learning, as implemented in the Photos app on iOS 17.

CoreImage Architecture: CIImage, CIFilter, CIContext

Three main classes form the core of CoreImage: CIImage (data), CIFilter (operation) and CIContext (execution environment). Each class is responsible for its own pipeline phase and does not mix responsibilities.

CIImage — Immutable Source

CIImage is a lightweight object that describes an image but does not directly contain pixel data. It can be created from UIImage, CGImage, Metal texture, GL texture or a file on disk. CIImage is immutable — any filter application creates a new CIImage without modifying the original. This allows building transformation chains without copying data between steps.

An important feature: CIImage is not tied to screen resolution or color space until rendering. The same CIImage can be rendered into a UIImage for screen and into a TIFF file for printing with different parameters — CoreImage automatically adapts processing to the target context.

CIFilter — Processing Operation

CIFilter is the main class for applying effects. Each CIFilter is a shader program with input parameters (inputImage, inputIntensity, inputRadius, etc.) and one output image. Apple ships over 200 built-in CIFilters, grouped by categories: CICategoryColorEffect (color correction), CICategoryBlur (blur), CICategoryStylize (stylization), CICategoryGeometryAdjust (geometric transformations).

To create a custom CIFilter, the developer writes a Metal shader (CIKernel) — a fragment shader in the Metal Shading Language that processes each pixel independently. After compilation, the shader is registered as a CIFilter subclass and can be used in chains alongside Apple’s built-in filters.

CategoryExample FilterPurpose
ColorEffectCIColorControlsBrightness, contrast, saturation
BlurCIGaussianBlurGaussian blur with adjustable radius
StylizeCIPixellatePixelation with specified scale
GeometryAdjustCIAffineTransformRotation, scale, translation via affine matrix
CompositeCISourceOverCompositingImage compositing with alpha channel

CIContext — Rendering Environment

CIContext is a heavyweight object that manages GPU resource allocation, shader compilation and buffering. Creating a CIContext is an expensive operation, so Apple recommends creating it once per application lifecycle and reusing it. The context is tied to a specific GPU (Metal, OpenGL) or CPU and determines the color space of the output image.

CIFilter: Built-in Filters and Custom Metal Shaders

The CIFilter library is constantly expanding: iOS 17 added new filters for HDR processing and machine learning. All built-in filters are documented in the Apple Developer Documentation and can be searched by categories or names. To discover available filters on the device, use CIFilter.filterNames(inCategory:).

Chain of Multiple Filters

The main capability of CoreImage is composing multiple CIFilters into a chain. The output of one filter is fed to the input of another through the inputImage parameter. CoreImage optimizes the chain at the rendering stage: adjacent filters working in the same color space are combined into a single GPU pass (kernel fusion). This provides a performance gain without developer intervention.

Custom Filters via CIKernel

To create a custom effect, the developer writes a Metal function with the [[kernel]] annotation. The function receives pixel coordinates and returns a color. CoreImage passes the shader to the GPU, where it executes in parallel for all image pixels. Custom filters are especially useful for unique visual effects: sepia with a nonlinear curve, dispersion blur, or film grain simulation.

metal
#include <CoreImage/CoreImage.h>

[[kernel]] float4 customFilter(sample_t s, float intensity) {
    float4 result;
    result.rgb = s.rgb * (1.0 - intensity) + s.r * intensity;
    result.a = s.a;
    return result;
}

Performance and Caching

CoreImage automatically manages the intermediate results cache. If the same filter chain is applied to different images, CoreImage can reuse compiled shaders. For maximum performance, avoid creating a CIContext for each frame — use one context and reset the filter’s input parameters.

CIDetector: Face, Text and Object Detection

CIDetector is a CoreImage subsystem for detecting semantic objects in an image without using Vision or Core ML. CIDetector supports four detection types: faces (CIDetectorTypeFace), text (CIDetectorTypeText), QR codes (CIDetectorTypeQRCode) and rectangles (CIDetectorTypeRectangle). The detector works on the CPU with optimization for NEON instructions, ensuring stable speed on devices without a powerful GPU.

Face Detection

The face detector CIDetectorTypeFace returns an array of CIFaceFeature with face bounds coordinates, eye and mouth positions. Since iOS 12, CIDetector also detects smiles (hasSmile) and left/right eye position (leftEyeClosed, rightEyeClosed). Detection accuracy is sufficient for most AR and photo applications, but for critical scenarios Apple recommends Vision.framework.

Rectangle Detection

CIDetectorTypeRectangle finds rectangular areas in an image — documents, business cards, device screens. The detector returns CIRectangleFeature with four points forming the rectangle contour. According to WWDC 2024, the rectangle detector uses the same neural network architecture as Vision, but with lower memory consumption. This makes it preferred for real-time frame stream processing, for example, in document scanner applications.

Code Examples: Filters and Detection in Swift

Practical examples will help solidify understanding of CoreImage. Let’s look at two typical scenarios: applying a color filter to a photo and face detection with bounding box drawing.

Applying Sepia to an Image

A basic example of the CISepiaTone filter, which converts a color image to sepia tones. The filter accepts the inputIntensity parameter from 0 (original) to 1 (maximum effect). Note the lazy evaluation: the CIImage returned by filter.outputImage does not contain pixels — rendering only happens when context.createCGImage is called.

swift
import CoreImage

guard let inputImage = CIImage(image: uiImage) else { return }
let filter = CIFilter(name: "CISepiaTone")
filter?.setValue(inputImage, forKey: kCIInputImageKey)
filter?.setValue(0.8, forKey: kCIInputIntensityKey)

let context = CIContext()
let outputImage = filter?.outputImage
let cgImage = context.createCGImage(outputImage!, from: inputImage.extent)
let resultImage = UIImage(cgImage: cgImage!)

Face Detection with Bounding Box Drawing

The following example uses CIDetector to find faces in an image and draw a rectangle around each detected face. CIFaceFeature contains coordinates in the image coordinate system (origin at bottom-left), so when drawing on UIKit, coordinate transformation via affine transform is required.

swift
let detector = CIDetector(
    ofType: CIDetectorTypeFace,
    context: context,
    options: [CIDetectorAccuracy: CIDetectorAccuracyHigh]
)
let features = detector?.features(in: inputImage) as? [CIFaceFeature]

for face in features ?? [] {
    print("Face bounds: \(face.bounds)")
    if face.hasSmile {
        print("Person is smiling")
    }
}

Composing Multiple Effects

The final example demonstrates a chain of three filters: color correction, vignetting and texture overlay. Note that the outputImage of the first filter is passed as inputImage to the second — without intermediate rendering. When createCGImage is called, CoreImage combines all three operations into a single GPU pass.

swift
let colorFilter = CIFilter(name: "CIColorControls")
colorFilter?.setValue(inputImage, forKey: kCIInputImageKey)
colorFilter?.setValues([
    kCIInputBrightnessKey: 0.1,
    kCIInputContrastKey: 1.2
])

let vignetteFilter = CIFilter(name: "CIVignette")
vignetteFilter?.setValue(colorFilter?.outputImage, forKey: kCIInputImageKey)
vignetteFilter?.setValue(2.0, forKey: "inputRadius")

let finalImage = vignetteFilter?.outputImage
let result = context.createCGImage(finalImage!, from: inputImage.extent)

Frequently Asked Questions

How is CoreImage different from Core Graphics?

CoreImage runs on the GPU and is optimized for pixel operations (filters, color correction), while Core Graphics is a CPU library for vector drawing and 2D contexts. CoreImage is faster for batch image processing, Core Graphics is more precise for step-by-step interface drawing.

Can CoreImage be applied to real-time video?

Yes — CoreImage supports processing individual video frames through AVPlayerItemVideoOutput or AVCaptureOutput. For streaming processing, use AVVideoComposition with CIFilter, which allows applying effects without copying frames between CPU and GPU.

What color profile does CoreImage use by default?

CoreImage by default works in the sRGB working color space (kCGColorSpaceSRGB). When creating a CIContext, you can specify an alternative space — extended linear sRGB for HDR or Display P3 for wide-gamut displays.

How many CIFilter filters can be combined in a chain?

There is no limit on the number of filters in a chain, but every 5–7 consecutive filters create an additional GPU pass. For more than 10 filters, it is recommended to split the chain into groups and render intermediate results to avoid exceeding the shader register limit.

Does CIDetector work on devices without Neural Engine?

Yes — CIDetector works on the CPU using NEON instructions on all devices with iOS 5.0 and above. Detection accuracy is the same on all devices, but speed is higher on Apple A12+ chips due to hardware-accelerated neural networks.

Summary

  • CoreImage — GPU-accelerated Apple framework for image and video processing on iOS and macOS
  • CIImage, CIFilter and CIContext form a three-tier architecture with lazy evaluation
  • Over 200 built-in CIFilters cover most color correction, blur and stylization tasks
  • Custom filters are created via Metal CIKernel with the [[kernel]] annotation
  • CIDetector finds faces, text, QR codes and rectangles without Vision.framework
  • Filter chains are automatically optimized through kernel fusion into a single GPU pass
  • For real-time video processing, use AVVideoComposition with CIFilter

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also