iOS Guides | Samples

MonoTouch.CoreImage Namespace

Accelerated image processing.

Remarks

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 MonoTouch.CoreGraphics, MonoTouch.CoreVideo and MonoTouch.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:

  • Create a CIImage object. You can create these from multiple sources: CoreGraphics images, bitmap data, images on disk or CoreVideo image buffers. CIImage objects are immutable and represent recipes, that is, they will be computed on demand.
  • Create and configure a CIFilters object. This object combines image inputs or numeric input parameters to configure the effects of the filter. The configuration is done by setting various properties using the object indexer to any of the values documented in the
  • Create a CIContext object to track the processing pipeline. This is the object trough which CoreImage draws and it can be CPU or GPU bound.
  • Render the filter output into a target image using one of the CIContext methods.

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 CIDetector class by calling the MonoTouch.CoreImage.CIDetector.CreateFaceDetector(MonoTouch.CoreImage.CIContext, bool) method which returns an array of 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);

Classes

TypeReason
CIAccordionFoldTransitionAnimates a transition by creating an accordion-fold effect on the source image.
CIAdditionCompositingThe CIAdditionCompositing CoreImage filter.
CIAffineClampA CIAffineFilter that extends the border pixels to the post-transform boundaries.
CIAffineFilterAn abstract class that defines a CIFilter that performs an affine transform on an image and then performs a filtering operation on the transformed image.
CIAffineTileA CIAffineFilter that tiles the transformed image.
CIAffineTransformPerforms an affine transform on an image.
CIAreaHistogramCreates histogram data for a given image and rectangle of interest.
CIAutoAdjustmentFilterOptionsWhen passed to CIImage.GetAutoAdjustmentFilters, limits the results.
CIAztecCodeGeneratorGenerates an Aztec code for the specified CIAztecCodeGenerator.Message.
CIBarsSwipeTransitionA CITransitionFilter that animates a transition by moving a bar over the source image.
CIBlendFilterAn abstract CIFilter that combines a background and foreground image.
CIBlendWithAlphaMaskA CIBlendWithMask that uses a mask image to blend foreground and background images.
CIBlendWithMaskA CIBlendFilter that uses a grayscale mask to blends its foreground and background images.
CIBloomA CIFilter that creates an edge-flow effect.
CIBumpDistortionA CIDistortionFilter that creates a bump at the specified center point.
CIBumpDistortionLinearA filter that distorts the image around a convex or concave line.
CICheckerboardGeneratorThe CICheckerboardGenerator CoreImage filter
CICircleSplashDistortionMakes the pixels at the circumference of a circle spread out to the boundaries of the image.
CICircularScreenA CIScreenFilter that creates a circular bulls-eye-style halftone screen.
CICode128BarcodeGeneratorGenerates a Code 128 barcode.
CIColorA Core Image color, including both color values and a reference to a color space.
CIColorBlendModeThe CIColorBlendMode CoreImage filter
CIColorBurnBlendModeThe CIColorBurnBlendMode CoreImage filter
CIColorClampA filter that constrains the color values between the range specified.
CIColorControlsThe CIColorControls CoreImage filter
CIColorCrossPolynomialA filter that modifies the source pixels by applying a set of polynomial cross-products.
CIColorCubeThe CIColorCube CoreImage filter
CIColorCubeWithColorSpaceA filter that modifies the source pixels using a 3D color-table and then maps the result to a color space.
CIColorDodgeBlendModeThe CIColorDodgeBlendMode CoreImage filter
CIColorInvertThe CIColorInvert CoreImage filter
CIColorKernelKernel for a GPU process that only operates on color data.
CIColorMapChanges colors based on an input gradient image's mapping.
CIColorMatrixThe CIColorMatrix CoreImage filter.
CIColorMonochromeThe CIColorMonochrome CoreImage filter
CIColorPolynomialA filter that modifies the source pixels by applying a set of cubic polynomials.
CIColorPosterizeReduces the number of levels for each color component.
CICompositingFilterAn abstract CIFilter that composites two images.
CIConstantColorGeneratorThe CIConstantColorGenerator CoreImage filter
CIContextOrchestrates the rendering of a CIFilter pipeline.
CIContextOptionsUse to configure the CIContext rendering pipeline.
CIConvolution3X3A filter that performs a custom 3x3 matrix convolution.
CIConvolution5X5A filter that performs a custom 5x5 matrix convolution.
CIConvolution9HorizontalA filter that performs a horizontal convolution of 9 elements.
CIConvolution9VerticalA filter that performs a vertical convolution of 9 elements.
CIConvolutionCoreAn abstract class that is the base for convolution filters.
CICopyMachineTransitionA CITransitionFilter that mimics the effect of a photocopier.
CICropThe CICrop CoreImage filter
CIDarkenBlendModeThe CIDarkenBlendMode CoreImage filter
CIDetectorImage analysis class for face detection.
CIDetectorOptionsOptions for use with face detection. Used with CIDetector.CreateFaceDetector.
CIDifferenceBlendModeThe CIDifferenceBlendMode CoreImage filter
CIDisintegrateWithMaskTransitionA CITransitionFilter that uses a mask to define the transition.
CIDissolveTransitionA CITransitionFilter that performs a cross-dissolve.
CIDistortionFilterAn abstract CIFilter for distortions.
CIDivideBlendModeA CIBlendFilter that divides the color values of its CIBlendFilter.Image and CIBlendFilter.BackgroundImage.
CIDotScreenA CIScreenFilter that screens with a halftone dot pattern.
CIEightfoldReflectedTileA CITileFilter that applies 8-way reflected symmetry.
CIExclusionBlendModeThe CIExclusionBlendMode CoreImage filter
CIExposureAdjustThe CIExposureAdjust CoreImage filter
CIFaceBalanceThe CIFaceBalance CoreImage filter
CIFaceFeatureLocations of the eyes and mouths in a detected face. In video sequences, attempts to maintain a consistent CIFaceFeature.TrackingID.
CIFalseColorThe CIFalseColor CoreImage filter
CIFeatureAn area of an image in which a CIDetector has detected a match.
CIFilterCoreImage image filter.
CIFilterAttributesConstants used for CIFilter's attributes
CIFilterCategoryConstants used for CIFilter filtering facilities to find filters by category.
CIFilterInputKeyKeys that can be used to configure the CIFilter input values.
CIFilterOutputKeyKeys that can be used to get output results out of a CIFilter.
CIFlashTransitionA CITransitionFilter that presents a starburst-like flash.
CIFormatAn enumeration whose values specify color spaces.
CIFourfoldReflectedTileA CITileFilter that applies 4-way reflected symmetry.
CIFourfoldRotatedTileA CITileFilter that rotates the source image in 90-degree increments.
CIFourfoldTranslatedTileA CITileFilter that applies four translations to the source image.
CIGammaAdjustThe CIGammaAdjust CoreImage filter
CIGaussianBlurApplies a Gaussian blur.
CIGaussianGradientThe CIGaussianGradient CoreImage filter
CIGlassDistortionDistorts the input image so that it appears viewed through glass blocks whose geometry corresponds to the CIGlassDistortion.Texture image.
CIGlideReflectedTileA CITileFilter that translates and smears the source image.
CIGloomA CIFilter that dulls the highlights of the source image.
CIHardLightBlendModeThe CIHardLightBlendMode CoreImage filter
CIHatchedScreenA CIScreenFilter that filters via a hatched halftone pattern.
CIHighlightShadowAdjustThe CIHighlightShadowAdjust CoreImage filter
CIHistogramDisplayFilterRenders a one-dimensional CIFilter.Image histogram as a typical two-dimensional histogram.
CIHoleDistortionA CIDistortionFilter that distorts pixels around a circular area.
CIHueAdjustThe CIHueAdjust CoreImage filter
CIHueBlendModeThe CIHueBlendMode CoreImage filter
CIImageRepresents a set of instructions to create an image for use by CoreImage.
CIImageInitializationOptionsOptions that can be used when initializing a new CIImage.
CIImageInitializationOptionsWithMetadataA type of CIImageInitializationOptions that has additional metadata properties.
CIImageOrientationAn enumeration whose values specify the origin of the CIImage.
CIKernelA kernel for filters that use custom GPU steps.
CIKernelRoiCallbackCompletion handler for deterimining a region of interest in the source image.
CILanczosScaleTransformA scaling transform that uses Lanczos resampling.
CILightenBlendModeThe CILightenBlendMode CoreImage filter
CILightTunnelA CIFilter that creates a spiraling effect.
CILinearBurnBlendModeDarkens the image based on the colors of the background image.
CILinearDodgeBlendModeDarkens the image based on the colors of the background image.
CILinearGradientThe CILinearGradient CoreImage filter
CILinearToSRGBToneCurveA filter that maps color intensity from a linear gamma curve to the sRGB color space.
CILineScreenA CIScreenFilter that simulates a halftone made of lines.
CILuminosityBlendModeThe CILuminosityBlendMode CoreImage filter
CIMaskToAlphaA CIFilter that converts a grayscale image to an alpha mask.
CIMaximumComponentA CIFilter that creates a grayscale image from the maximum value of the RGB color values.
CIMaximumCompositingThe CIMaximumCompositing CoreImage filter
CIMinimumComponentA CIFilter that creates a grayscale image from the minimum component of the RGB values.
CIMinimumCompositingThe CIMinimumCompositing CoreImage filter
CIModTransitionA CITransitionFilter that reveals the background image via a series of irregularly shaped holes.
CIMultiplyBlendModeThe CIMultiplyBlendMode CoreImage filter
CIMultiplyCompositingThe CIMultiplyCompositing CoreImage filter
CIOverlayBlendModeThe CIOverlayBlendMode CoreImage filter
CIPerspectiveCorrectionA CIPerspectiveTransform that is cropped according to the perspective control points, but whose pixels are not transformed.
CIPerspectiveTileA CIFilter that applies a perspective transform and then tiles the result.
CIPerspectiveTransformA CIFilter that applies a transform the simulates perspective.
CIPerspectiveTransformWithExtentA filter that alters a portion of the total image based on a perspective transform.
CIPhotoEffectThe base class for photo effect filters.
CIPhotoEffectChromeA filter that exaggerates color of the image producing a vintage look.
CIPhotoEffectFadeA filter that reduces color of the image producing a vintage look.
CIPhotoEffectInstantA filter that that distorts colors in a style reminiscent of instant film.
CIPhotoEffectMonoA filter that produces a low-contrast black-and-white image.
CIPhotoEffectNoirA filter that produces a high-contrast black-and-white image.
CIPhotoEffectProcessA filter that produces a vintage look with exagerrated cool colors.
CIPhotoEffectTonalA filter that produces a black-and-white image with minimal contrast changes.
CIPhotoEffectTransferA filter that produces a vintage look with exagerrated warm colors.
CIPinchDistortionA CIDistortionFilter that pinches pixels towards a rectangular area.
CIPinLightBlendModeReplaces image colors with the bright colors from the background image.
CIPixellateA CIFilter that pixelates the original image.
CIQRCodeFeatureA detected QR code.
CIQRCodeGeneratorGenerates a QR code.
CIRadialGradientThe CIRadialGradient CoreImage filter
CIRandomGeneratorA CIFilter whose pixels are randomly colored.
CIRectangleFeatureA CIFeature an image space rectange that contains a detected physical rectangle.
CISaturationBlendModeThe CISaturationBlendMode CoreImage filter
CIScreenBlendModeThe CIScreenBlendMode CoreImage filter
CIScreenFilterA CIFilter that mimics halftone screens.
CISepiaToneThe CISepiaTone CoreImage filter
CISharpenLuminanceA CIFilter that sharpens the image.
CISixfoldReflectedTileA CITileFilter that applies 6-way reflected symmetry.
CISixfoldRotatedTileA CITileFilter that rotates the image in 60-degree increments.
CISmoothLinearGradientA filter that produces a gradient along a linear axis between two endpoints.
CISoftLightBlendModeThe CISoftLightBlendMode CoreImage filter
CISourceAtopCompositingThe CISourceAtopCompositing CoreImage filter
CISourceInCompositingThe CISourceInCompositing CoreImage filter
CISourceOutCompositingThe CISourceOutCompositing CoreImage filter
CISourceOverCompositingThe CISourceOverCompositing CoreImage filter
CISRGBToneCurveToLinearA filter that adjusts tone response in sRGB color space and then maps it to a linear gamma curve.
CIStarShineGeneratorA CIFilter that simulates lens flare.
CIStraightenFilterThe CIStraightenFilter CoreImage filter
CIStripesGeneratorThe CIStripesGenerator CoreImage filter
CISubtractBlendModeSubtracts the background image pixels from those in the CIFilter.Image.
CISwipeTransitionA CITransitionFilter that swipes from one image to the other.
CITemperatureAndTintThe CITemperatureAndTint CoreImage filter
CITileFilterA CIFilter that applies a filter and then tiles the results.
CIToneCurveThe CIToneCurve CoreImage filter
CITransitionFilterA CITransitionFilter that animates a transition between two images.
CITriangleKaleidoscopeA CIFilter that creates a kaleidoscopic effect.
CITwelvefoldReflectedTileA CITileFilter that applies 12-way reflected symmetry.
CITwirlDistortionA CIDistortionFilter that rotates pixels around a point.
CIUnsharpMaskA CIFilter that increases the contrast of edges in the image.
CIVectorA vector for use with Core Image objects such as CIFilter.
CIVibranceThe CIVibrance CoreImage filter
CIVignetteThe CIVignette CoreImage filter
CIVignetteEffectA filter that modifies the brightness of the outside of an image.
CIVortexDistortionA CIDistortionFilter that creates a tight spiraling distortion suggestive of a vortex.
CIWarpKernelA kernel for GPU transforms that operate only on geometry.
CIWhitePointAdjustThe CIWhitePointAdjust CoreImage filter
FaceDetectorAccuracyAn enumeration whose values specify the accuracy of face detection.