areaAverage()
Returns a 1 x 1 pixel image that contains the average color for the region of interest.
Declaration
class func areaAverage() -> any CIFilter & CIAreaAverageReturn Value
A 1 x 1 pixel image containing the average color for the region of interest.
Discussion
This filter calculates the average color of the area defined by extent and creates a 1 x 1 pixel image with the result. The filter processes each color component (red, green, blue, alpha) of the input image independently.
The area average filter uses the following properties:
inputImageThe CIImage containing the image you want to process.
extentA CGRect that specifies the region of the image that you want to process.
The following code creates a filter that calculates the average color of a 500 x 500 set of pixels from the center of the image:
func averageArea(inputImage: CIImage) -> CIImage {
let filter = CIFilter.areaAverage()
filter.inputImage = inputImage
filter.extent = CGRect(
x: inputImage.extent.width/2-250,
y: inputImage.extent.height/2-250,
width: 500,
height: 500)
return filter.outputImage!
}[Image]