areaHistogram()
Returns a histogram of a specified area of the image.
Declaration
class func areaHistogram() -> any CIFilter & CIAreaHistogramReturn Value
A 1 pixel high image containing the calculated histogram.
Discussion
This filter calculates histograms of the red, green, blue, and alpha colors in the region defined by extent. The count property controls the number of bins (or width) of the histogram. The filter scales the histogram so that the total of all the counts in the bins equals scale.
The area histogram filter uses the following properties:
inputImageAn image with the type CIImage.
extentA CGRect that specifies the subregion of the image that you want to process.
scaleThe scale value to use for the histogram values. If the scale is 1, then the total of all the counts in the histogram equals 1.
countThe number of bins for the histogram. This value determines the width of the output image. Minimum value 1, maximum value 2048.
The following code creates a filter that results in an image that has a height of 1 pixel and a width of 256 pixels. The pixel color components contain the histogram values.
func areaHistogram(inputImage: CIImage) -> CIImage {
let filter = CIFilter.areaHistogram()
filter.inputImage = inputImage
filter.count = 256
filter.scale = 50
filter.extent = CGRect(
x: inputImage.extent.width/2-250,
y: inputImage.extent.height/2-250,
width: 500,
height: 500)
return filter.outputImage!
}To display the histogram, you can use the histogramDisplay() filter:
func histogramDisplay(inputImage: CIImage) -> CIImage {
let filter = CIFilter.histogramDisplay()
filter.inputImage = areaHistogram(inputImage: inputImage)
filter.highLimit = 1
filter.height = 100
filter.lowLimit = 0
return filter.outputImage!
}
[Image]