equalizeHistogram(destination:)
Equalizes the histogram of an 8-bit-per-channel, 4-channel interleaved pixel buffer.
Declaration
func equalizeHistogram(destination: vImage.PixelBuffer<Format>)Parameters
- destination:
The destination pixel buffer.
Discussion
Use this function to transform an image so that its histogram is more uniformly distributed across the entire range of values.
For example, the following code equalizes the histogram of an image:
let srcImage = imageLiteral(resourceName: " ... ").cgImage(
forProposedRect: nil,
context: nil,
hints: nil)!
var cgImageFormat = vImage_CGImageFormat(
bitsPerComponent: 8,
bitsPerPixel: 8 * 4,
colorSpace: CGColorSpaceCreateDeviceRGB(),
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipFirst.rawValue))!
let buffer = try vImage.PixelBuffer(
cgImage: srcImage,
cgImageFormat: &cgImageFormat,
pixelFormat: vImage.Interleaved8x4.self)
buffer.equalizeHistogram(destination: buffer)
let outputImage = buffer.makeCGImage(cgImageFormat: cgImageFormat)