Contents

equalizeHistogram(binCount:destination:)

Equalizes the histogram of a multiple-plane 32-bit pixel buffer.

Declaration

func equalizeHistogram(binCount: Int, destination: vImage.PixelBuffer<Format>)

Parameters

  • binCount:

    The number of histogram entries for each channel.

  • 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: 32,
    bitsPerPixel: 32 * 3,
    colorSpace: CGColorSpaceCreateDeviceRGB(),
    bitmapInfo: CGBitmapInfo(rawValue: kCGBitmapByteOrder32Host.rawValue |
                             CGBitmapInfo.floatComponents.rawValue |
                             CGImageAlphaInfo.none.rawValue))!

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

let multiplaneBuffer = vImage.PixelBuffer<vImage.PlanarFx3>(
    interleavedBuffer: interleavedBuffer)

multiplaneBuffer.equalizeHistogram(binCount: 1024,
                                   destination: multiplaneBuffer)

multiplaneBuffer.convert(to: interleavedBuffer)

let outputImage = interleavedBuffer.makeCGImage(cgImageFormat: cgImageFormat)

See Also

Related Documentation

Equalization