Contents

equalizeHistogram(destination:)

Equalizes the histogram of an 8-bit planar pixel buffer.

Declaration

func equalizeHistogram(destination: vImage.PixelBuffer<vImage.Planar8>)

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 * 1,
    colorSpace: CGColorSpaceCreateDeviceGray(),
    bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue))!

let buffer = try vImage.PixelBuffer(
    cgImage: srcImage,
    cgImageFormat: &cgImageFormat,
    pixelFormat: vImage.Planar8.self)

buffer.equalizeHistogram(destination: buffer)

let outputImage = buffer.makeCGImage(cgImageFormat: cgImageFormat)

See Also

Related Documentation

Equalization