CoreImage provides a framework for processing still images and applying a set of operations on them to either produce new images or perform image analysis (like performing face detection and photography auto-enhance). The operations are hardware accelerated and provide better performance than most hand written implementations.
CoreImage can apply either one filter to an image or you can use the built-in chaining support to apply a series of filters at once to an image. For example, you could apply a Sepia Filter, followed by a Hue adjustment filter, followed by a contrast filter. The idea behind the chaining support is to avoid intermediate copies and intermediate buffers during image processing. Additionally, some of these filtering operations can be performed entirely on the GPU in a single pass, without having to copy data back and forth from the GPU to the main memory.
The CoreImage runtime sits below the CoreGraphics, CoreVideo and ImageIO stacks and provides services to all of them. Depending on the filter operations and the hardware platform, CoreImage will execute the filters in the CPU or the GPU.
To use CoreImage on iOS, you follow these steps:
C# Example
// This sample turns the image into a sepia image // Load the image using UIImage, it is convenient var uiimage = UIImage.FromFile ("sample.jpg"); // Create the CIImage, using the UIImage's CGImage as a reference var image = new CIImage (uiimage.CGImage); // Create the filter var sepia = new CISepiaTone () { Image = image, Intensity = .8f }; // Generate the recipe. It is important to note that at this point // the resulting CIImage merely contains the recipe on how to create // the image, this is important, because you can use this result as // the input to another filter to chain filters together and only // at the last minute, when the CIContext rendering APIs are used, // does the actual pipeline execute. This allows for a series of // operations to all be performed in one step without intermediate // buffer copies. CIImage output = sepia.OutputImage; // To render the results, we need to create a context, and then // use one of the context rendering APIs, in this case, we render the // result into a CoreGraphics image, which is merely a useful representation // var context = CIContext.FromOptions (null); var cgimage = context.CreateCGImage (output, output.Extent); // The above cgimage can be added to a screen view, for example, this // would add it to a UIImageView on the screen: myImageView.Image = UIImage.FromImage (cgimage);
Face detection is done with the CoreImage.CIDetector class by calling the CoreImage.CIDetector.CreateFaceDetector(CoreImage.CIContext, bool) method which returns an array of CoreImage.CIFeature objects with any detected face features found.
Auto-adjustments are implemented by calling the CoreImage.GetAutoAdjustmentFilters() method. This method returns a list of suggested CIFilter which you in turn would apply to your image and render to a context.
To chain filters, all you have to do is connect the OutputImage property from a filter to the Image property of another filter. This is a modified version of the previous example showing how to chain two filters together:
C# Example
var uiimage = UIImage.FromFile ("sample.jpg"); var image = new CIImage (uiimage.CGImage); var sepia = new CISepiaTone () { Image = image, Intensity = .8f }; // Chain the Sepia filter to a Color inversion filter, this is done // by assigning the CIColorInvert.Input to the sepia.OutputImage var invert = new CIColorInvert () { Image = sepia.OutputImage; } CIImage output = invert.OutputImage; var context = CIContext.FromOptions (null); var cgimage = context.CreateCGImage (output, output.Extent); myImageView.Image = UIImage.FromImage (cgimage);
Type | Reason |
---|---|
CIAccordionFoldTransition | Animates a transition by creating an accordion-fold effect on the source image. |
CIAdditionCompositing | The CIAdditionCompositing CoreImage filter. |
CIAffineClamp | A CoreImage.CIAffineFilter that extends the border pixels to the post-transform boundaries. |
CIAffineFilter | An abstract class that defines a CoreImage.CIFilter that performs an affine transform on an image and then performs a filtering operation on the transformed image. |
CIAffineTile | A CoreImage.CIAffineFilter that tiles the transformed image. |
CIAffineTransform | Performs an affine transform on an image. |
CIAreaHistogram | Creates histogram data for a given image and rectangle of interest. |
CIAutoAdjustmentFilterOptions | When passed to CoreImage.CIImage.GetAutoAdjustmentFilters, limits the results. |
CIAztecCodeGenerator | Generates an Aztec code for the specified CoreImage.CIAztecCodeGenerator.Message. |
CIBarsSwipeTransition | A CoreImage.CITransitionFilter that animates a transition by moving a bar over the source image. |
CIBlendFilter | An abstract CoreImage.CIFilter that combines a background and foreground image. |
CIBlendWithAlphaMask | A CoreImage.CIBlendWithMask that uses a mask image to blend foreground and background images. |
CIBlendWithMask | A CoreImage.CIBlendFilter that uses a grayscale mask to blends its foreground and background images. |
CIBloom | A CoreImage.CIFilter that creates an edge-flow effect. |
CIBumpDistortion | A CoreImage.CIDistortionFilter that creates a bump at the specified center point. |
CIBumpDistortionLinear | A filter that distorts the image around a convex or concave line. |
CICheckerboardGenerator | The CICheckerboardGenerator CoreImage filter |
CICircleSplashDistortion | Makes the pixels at the circumference of a circle spread out to the boundaries of the image. |
CICircularScreen | A CoreImage.CIScreenFilter that creates a circular bulls-eye-style halftone screen. |
CICode128BarcodeGenerator | Generates a Code 128 barcode. |
CIColor | A Core Image color, including both color values and a reference to a color space. |
CIColorBlendMode | The CIColorBlendMode CoreImage filter |
CIColorBurnBlendMode | The CIColorBurnBlendMode CoreImage filter |
CIColorClamp | A filter that constrains the color values between the range specified. |
CIColorControls | The CIColorControls CoreImage filter |
CIColorCrossPolynomial | A filter that modifies the source pixels by applying a set of polynomial cross-products. |
CIColorCube | The CIColorCube CoreImage filter |
CIColorCubeWithColorSpace | A filter that modifies the source pixels using a 3D color-table and then maps the result to a color space. |
CIColorDodgeBlendMode | The CIColorDodgeBlendMode CoreImage filter |
CIColorInvert | The CIColorInvert CoreImage filter |
CIColorKernel | Documentation for this section has not yet been entered. |
CIColorMap | Changes colors based on an input gradient image's mapping. |
CIColorMatrix | The CIColorMatrix CoreImage filter |
CIColorMonochrome | The CIColorMonochrome CoreImage filter |
CIColorPolynomial | A filter that modifies the source pixels by applying a set of cubic polynomials. |
CIColorPosterize | Reduces the number of levels for each color component. |
CICompositingFilter | An abstract CoreImage.CIFilter that composites two images. |
CIConstantColorGenerator | The CIConstantColorGenerator CoreImage filter |
CIContext | Orchestrates the rendering of a CIFilter pipeline. |
CIContextOptions | Use to configure the CIContext rendering pipeline. |
CIConvolution3X3 | A filter that performs a custom 3x3 matrix convolution. |
CIConvolution5X5 | A filter that performs a custom 5x5 matrix convolution. |
CIConvolution9Horizontal | A filter that performs a horizontal convolution of 9 elements. |
CIConvolution9Vertical | A filter that performs a vertical convolution of 9 elements. |
CIConvolutionCore | An abstract class that is the base for convolution filters. |
CICopyMachineTransition | A CoreImage.CITransitionFilter that mimics the effect of a photocopier. |
CICrop | The CICrop CoreImage filter |
CIDarkenBlendMode | The CIDarkenBlendMode CoreImage filter |
CIDetector | Image analysis class for face detection. |
CIDetectorOptions | Options for use with face detection. Used with CoreImage.CIDetector.CreateFaceDetector. |
CIDifferenceBlendMode | The CIDifferenceBlendMode CoreImage filter |
CIDisintegrateWithMaskTransition | A CoreImage.CITransitionFilter that uses a mask to define the transition. |
CIDissolveTransition | A CoreImage.CITransitionFilter that performs a cross-dissolve. |
CIDistortionFilter | An abstract CoreImage.CIFilter for distortions. |
CIDivideBlendMode | A CoreImage.CIBlendFilter that divides the color values of its CIBlendFilter.Image and CoreImage.CIBlendFilter.BackgroundImage. |
CIDotScreen | A CoreImage.CIScreenFilter that screens with a halftone dot pattern. |
CIEightfoldReflectedTile | A CoreImage.CITileFilter that applies 8-way reflected symmetry. |
CIExclusionBlendMode | The CIExclusionBlendMode CoreImage filter |
CIExposureAdjust | The CIExposureAdjust CoreImage filter |
CIFaceBalance | The CIFaceBalance CoreImage filter |
CIFaceFeature | Locations of the eyes and mouths in a detected face. In video sequences, attempts to maintain a consistent CoreImage.CIFaceFeature.TrackingID. |
CIFalseColor | The CIFalseColor CoreImage filter |
CIFeature | An area of an image in which a CoreImage.CIDetector has detected a match. |
CIFilter | CoreImage image filter. |
CIFilterAttributes | Constants used for CIFilter's attributes |
CIFilterCategory | Constants used for CIFilter filtering facilities to find filters by category. |
CIFilterInputKey | Keys that can be used to configure the CIFilter input values. |
CIFilterOutputKey | Keys that can be used to get output results out of a CIFilter. |
CIFlashTransition | A CoreImage.CITransitionFilter that presents a starburst-like flash. |
CIFormat | An enumeration whose values specify color spaces. |
CIFourfoldReflectedTile | A CoreImage.CITileFilter that applies 4-way reflected symmetry. |
CIFourfoldRotatedTile | A CoreImage.CITileFilter that rotates the source image in 90-degree increments. |
CIFourfoldTranslatedTile | A CoreImage.CITileFilter that applies four translations to the source image. |
CIGammaAdjust | The CIGammaAdjust CoreImage filter |
CIGaussianBlur | Applies a Gaussian blur. |
CIGaussianGradient | The CIGaussianGradient CoreImage filter |
CIGlassDistortion | Distorts the input image so that it appears viewed through glass blocks whose geometry corresponds to the CIGlassDistortion.Texture image. |
CIGlideReflectedTile | A CoreImage.CITileFilter that translates and smears the source image. |
CIGloom | A CoreImage.CIFilter that dulls the highlights of the source image. |
CIHardLightBlendMode | The CIHardLightBlendMode CoreImage filter |
CIHatchedScreen | A CoreImage.CIScreenFilter that filters via a hatched halftone pattern. |
CIHighlightShadowAdjust | The CIHighlightShadowAdjust CoreImage filter |
CIHistogramDisplayFilter | Renders a one-dimensional CoreImage.CIFilter.Image histogram as a typical two-dimensional histogram. |
CIHoleDistortion | A Xamarin.CoreImage.CIDistortionFilter that distorts pixels around a circular area. |
CIHueAdjust | The CIHueAdjust CoreImage filter |
CIHueBlendMode | The CIHueBlendMode CoreImage filter |
CIImage | Represents a set of instructions to create an image for use by CoreImage. |
CIImageInitializationOptions | Options that can be used when initializing a new CoreImage.CIImage. |
CIImageInitializationOptionsWithMetadata | A type of CoreImage.CIImageInitializationOptions that has additional metadata properties. |
CIImageOrientation | An enumeration whose values specify the origin of the CoreImage.CIImage. |
CIKernel | Documentation for this section has not yet been entered. |
CIKernelRoiCallback | Documentation for this section has not yet been entered. |
CILanczosScaleTransform | A scaling transform that uses Lanczos resampling. |
CILightenBlendMode | The CILightenBlendMode CoreImage filter |
CILightTunnel | A CoreImage.CIFilter that creates a spiraling effect. |
CILinearBurnBlendMode | Darkens the image based on the colors of the background image. |
CILinearDodgeBlendMode | Darkens the image based on the colors of the background image. |
CILinearGradient | The CILinearGradient CoreImage filter |
CILinearToSRGBToneCurve | A filter that maps color intensity from a linear gamma curve to the sRGB color space. |
CILineScreen | A CoreImage.CIScreenFilter that simulates a halftone made of lines. |
CILuminosityBlendMode | The CILuminosityBlendMode CoreImage filter |
CIMaskToAlpha | A CoreImage.CIFilter that converts a grayscale image to an alpha mask. |
CIMaximumComponent | A CoreImage.CIFilter that creates a grayscale image from the maximum value of the RGB color values. |
CIMaximumCompositing | The CIMaximumCompositing CoreImage filter |
CIMinimumComponent | A CoreImage.CIFilter that creates a grayscale image from the minimum component of the RGB values. |
CIMinimumCompositing | The CIMinimumCompositing CoreImage filter |
CIModTransition | A CoreImage.CITransitionFilter that reveals the background image via a series of irregularly shaped holes. |
CIMultiplyBlendMode | The CIMultiplyBlendMode CoreImage filter |
CIMultiplyCompositing | The CIMultiplyCompositing CoreImage filter |
CIOverlayBlendMode | The CIOverlayBlendMode CoreImage filter |
CIPerspectiveCorrection | A CoreImage.CIPerspectiveTransform that is cropped according to the perspective control points, but whose pixels are not transformed. |
CIPerspectiveTile | A CoreImage.CIFilter that applies a perspective transform and then tiles the result. |
CIPerspectiveTransform | A CoreImage.CIFilter that applies a transform the simulates perspective. |
CIPerspectiveTransformWithExtent | A filter that alters a portion of the total image based on a perspective transform. |
CIPhotoEffect | The base class for photo effect filters. |
CIPhotoEffectChrome | A filter that exaggerates color of the image producing a vintage look. |
CIPhotoEffectFade | A filter that reduces color of the image producing a vintage look. |
CIPhotoEffectInstant | A filter that that distorts colors in a style reminiscent of instant film. |
CIPhotoEffectMono | A filter that produces a low-contrast black-and-white image. |
CIPhotoEffectNoir | A filter that produces a high-contrast black-and-white image. |
CIPhotoEffectProcess | A filter that produces a vintage look with exagerrated cool colors. |
CIPhotoEffectTonal | A filter that produces a black-and-white image with minimal contrast changes. |
CIPhotoEffectTransfer | A filter that produces a vintage look with exagerrated warm colors. |
CIPinchDistortion | A CoreImage.CIDistortionFilter that pinches pixels towards a rectangular area. |
CIPinLightBlendMode | Replaces image colors with the bright colors from the background image. |
CIPixellate | A CoreImage.CIFilter that pixelates the original image. |
CIQRCodeFeature | Documentation for this section has not yet been entered. |
CIQRCodeGenerator | Generates a QR code. |
CIRadialGradient | The CIRadialGradient CoreImage filter |
CIRandomGenerator | A CoreImage.CIFilter whose pixels are randomly colored. |
CIRectangleFeature | A CoreImage.CIFeature describing a rectangle. |
CISaturationBlendMode | The CISaturationBlendMode CoreImage filter |
CIScreenBlendMode | The CIScreenBlendMode CoreImage filter |
CIScreenFilter | A CoreImage.CIFilter that mimics halftone screens. |
CISepiaTone | The CISepiaTone CoreImage filter |
CISharpenLuminance | A CoreImage.CIFilter that sharpens the image. |
CISixfoldReflectedTile | A CoreImage.CITileFilter that applies 6-way reflected symmetry. |
CISixfoldRotatedTile | A CoreImage.CITileFilter that rotates the image in 60-degree increments. |
CISmoothLinearGradient | A filter that produces a gradient along a linear axis between two endpoints. |
CISoftLightBlendMode | The CISoftLightBlendMode CoreImage filter |
CISourceAtopCompositing | The CISourceAtopCompositing CoreImage filter |
CISourceInCompositing | The CISourceInCompositing CoreImage filter |
CISourceOutCompositing | The CISourceOutCompositing CoreImage filter |
CISourceOverCompositing | The CISourceOverCompositing CoreImage filter |
CISRGBToneCurveToLinear | A filter that adjusts tone response in sRGB color space and then maps it to a linear gamma curve. |
CIStarShineGenerator | A CoreImage.CIFilter that simulates lens flare. |
CIStraightenFilter | The CIStraightenFilter CoreImage filter |
CIStripesGenerator | The CIStripesGenerator CoreImage filter |
CISubtractBlendMode | Subtracts the background image pixels from those in the CoreImage.CIFilter.Image. |
CISwipeTransition | A CoreImage.CITransitionFilter that swipes from one image to the other. |
CITemperatureAndTint | The CITemperatureAndTint CoreImage filter |
CITileFilter | A CoreImage.CIFilter that applies a filter and then tiles the results. |
CIToneCurve | The CIToneCurve CoreImage filter |
CITransitionFilter | A CoreImage.CITransitionFilter that animates a transition between two images. |
CITriangleKaleidoscope | A CoreImage.CIFilter that creates a kaleidoscopic effect. |
CITwelvefoldReflectedTile | A CoreImage.CITileFilter that applies 12-way reflected symmetry. |
CITwirlDistortion | A CoreImage.CIDistortionFilter that rotates pixels around a point. |
CIUnsharpMask | A CoreImage.CIFilter that increases the contrast of edges in the image. |
CIVector | A vector for use with Core Image objects such as CoreImage.CIFilter. |
CIVibrance | The CIVibrance CoreImage filter |
CIVignette | The CIVignette CoreImage filter |
CIVignetteEffect | A filter that modifies the brightness of the outside of an image. |
CIVortexDistortion | A CoreImage.CIDistortionFilter that creates a tight spiraling distortion suggestive of a vortex. |
CIWarpKernel | Documentation for this section has not yet been entered. |
CIWhitePointAdjust | The CIWhitePointAdjust CoreImage filter |
FaceDetectorAccuracy | An enumeration whose values specify the accuracy of face detection. |