Class

MPSImageHistogram

A filter that computes the histogram of an image.

Declaration

@interface MPSImageHistogram : MPSKernel

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.

Listing 1 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

Methods

- initWithDevice:histogramInfo:

Initializes a histogram with specific information.

MPSImageHistogramInfo

The information used to compute the histogram channels of an image.

- encodeToCommandBuffer:sourceTexture:histogram:histogramOffset:

Encodes the filter to a command buffer using a compute command encoder.

- histogramSizeForSourceFormat:

The amount of space the histogram will take up in the output buffer.

Properties

clipRectSource

The source rectangle to use when reading data.

zeroHistogram

Determines whether to zero-initialize the histogram results.

histogramInfo

A structure describing the histogram content.

Relationships

Inherits From

See Also

Histogram Image Filters

MPSImageHistogramEqualization

A filter that equalizes the histogram of an image.

MPSImageHistogramSpecification

A filter that performs a histogram specification operation on an image.