---
title: MPSImageHistogram
framework: metalperformanceshaders
role: symbol
role_heading: Class
path: metalperformanceshaders/mpsimagehistogram
---

# MPSImageHistogram

A filter that computes the histogram of an image.

## Declaration

```swift
class MPSImageHistogram
```

## Overview

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

- [init(coder:device:)](metalperformanceshaders/mpsimagehistogram/init(coder:device:).md)

### Methods

- [init(device:histogramInfo:)](metalperformanceshaders/mpsimagehistogram/init(device:histograminfo:).md)
- [MPSImageHistogramInfo](metalperformanceshaders/mpsimagehistograminfo.md)
- [encode(to:sourceTexture:histogram:histogramOffset:)](metalperformanceshaders/mpsimagehistogram/encode(to:sourcetexture:histogram:histogramoffset:).md)
- [histogramSize(forSourceFormat:)](metalperformanceshaders/mpsimagehistogram/histogramsize(forsourceformat:).md)

### Properties

- [clipRectSource](metalperformanceshaders/mpsimagehistogram/cliprectsource.md)
- [zeroHistogram](metalperformanceshaders/mpsimagehistogram/zerohistogram.md)
- [histogramInfo](metalperformanceshaders/mpsimagehistogram/histograminfo.md)
- [minPixelThresholdValue](metalperformanceshaders/mpsimagehistogram/minpixelthresholdvalue.md)

## Relationships

### Inherits From

- [MPSKernel](metalperformanceshaders/mpskernel.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Histogram Image Filters

- [MPSImageHistogramEqualization](metalperformanceshaders/mpsimagehistogramequalization.md)
- [MPSImageHistogramSpecification](metalperformanceshaders/mpsimagehistogramspecification.md)
