Contents

MPSImageHistogram

A filter that computes the histogram of an image.

Declaration

class MPSImageHistogram

Overview

Typically, you use an MPSImageHistogram filter to calculate an image’s histogram that is passed to a subsequent filter such as MPSImageHistogramEqualization or MPSImageHistogramSpecification.

The following listing shows how you can create a histogram filter to calculate the histogram of the MTLTexture, sourceTexture. The filter is passed an instance of MPSImageHistogramInfo that specifies information to compute the histogram for the channels of an image. After encoding, histogramInfoBuffer contains the histogram information and can be used for further operations such as equalization or specification.

Listing 1. Creating a histogram filter

var histogramInfo = MPSImageHistogramInfo(
    numberOfHistogramEntries: 256,
    histogramForAlpha: false,
    minPixelValue: vector_float4(0,0,0,0),
    maxPixelValue: vector_float4(1,1,1,1))
     
let calculation = MPSImageHistogram(device: device,
                                    histogramInfo: &histogramInfo)
let bufferLength = calculation.histogramSize(forSourceFormat: sourceTexture.pixelFormat)
let histogramInfoBuffer = device.makeBuffer(length: bufferLength, 
                                            options: [.storageModePrivate])
     
calculation.encode(to: commandBuffer,
                   sourceTexture: sourceTexture,
                   histogram: histogramInfoBuffer,
                   histogramOffset: 0)

Topics

Initializers

Methods

Properties

See Also

Histogram Image Filters