Contents

specifyHistogram(_:destination:)

Performs a histogram specification operation on a 32-bit-per-channel, 3-channel multiple-plane pixel buffer.

Declaration

func specifyHistogram(_ histogram: vImage.PixelBuffer<Format>.HistogramFFF, destination: vImage.PixelBuffer<Format>)

Parameters

  • histogram:

    The histogram.

  • destination:

    The destination pixel buffer.

Discussion

Histogram specification is a technique that allows you to calculate the histogram of a reference image and apply it to an input image.

The example below shows a source image (bottom left) and a histogram reference image (top left), with the histogram specification output on the right:

[Image]

The code below initializes the source and reference buffers from the CGImage instances sourceImage and referenceImage respectively:

var cgImageFormat = vImage_CGImageFormat(
    bitsPerComponent: 32,
    bitsPerPixel: 32 * 3,
    colorSpace: CGColorSpaceCreateDeviceRGB(),
    bitmapInfo: CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder32Little.rawValue |
                             CGBitmapInfo.floatComponents.rawValue |
                             CGImageAlphaInfo.none.rawValue))!

let interleavedSource = try vImage.PixelBuffer(
    cgImage: sourceImage,
    cgImageFormat: &cgImageFormat,
    pixelFormat: vImage.InterleavedFx3.self)
let multiplePlaneSource = vImage.PixelBuffer<vImage.PlanarFx3>(
    planarBuffers: interleavedSource.planarBuffers())

let interleavedReference = try vImage.PixelBuffer(
    cgImage: referenceImage,
    cgImageFormat: &cgImageFormat,
    pixelFormat: vImage.InterleavedFx3.self)
let multiplePlaneReference = vImage.PixelBuffer<vImage.PlanarFx3>(
    planarBuffers: interleavedReference.planarBuffers())

The following code calls histogram() to calculate the histogram of the reference image and passes the histogram to specifyHistogram(_:destination:) to generate the specification result. This function works in place, that is, the input and output can share the same underlying memory.

let histogram = multiplePlaneReference.histogram(binCount: 1024)

multiplePlaneSource.specifyHistogram(histogram,
                                     destination: multiplePlaneSource)

See Also

Related Documentation

Histogram specification