<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShaders",
  "identifier" : "/documentation/MetalPerformanceShaders/MPSImageMedian",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Metal Performance Shaders"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSImageMedian"
  },
  "title" : "MPSImageMedian"
}
-->

# MPSImageMedian

A filter that applies a median filter in a square region centered around each pixel in the source image.

```
class MPSImageMedian
```

## Overview

An [`MPSImageMedian`](/documentation/MetalPerformanceShaders/MPSImageMedian) filter finds the median color value for each channel within a `kernelDiameter * kernelDiameter` window surrounding the pixel of interest.  It is a common means of noise reduction and also as a smoothing filter with edge preserving qualities.

> Note:
> The ``doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSImageMedian`` filter supports only images with 8 or less bits per channel.

## Topics

### Initializers

[`-  initWithCoder:device:`](/documentation/MetalPerformanceShaders/MPSImageMedian/init(coder:device:))

### Methods

[`-  initWithDevice:kernelDiameter:`](/documentation/MetalPerformanceShaders/MPSImageMedian/init(device:kernelDiameter:))

Initializes a filter for a particular kernel size and device.

[`+  maxKernelDiameter`](/documentation/MetalPerformanceShaders/MPSImageMedian/maxKernelDiameter())

Queries the maximum diameter, in pixels, of the filter window supported by the median filter.

[`+  minKernelDiameter`](/documentation/MetalPerformanceShaders/MPSImageMedian/minKernelDiameter())

Queries the minimum diameter, in pixels, of the filter window supported by the median filter.

### Properties

[`kernelDiameter`](/documentation/MetalPerformanceShaders/MPSImageMedian/kernelDiameter)

The diameter, in pixels, of the filter window.

## Relationships

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`Hashable`](/documentation/Swift/Hashable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`MPSUnaryImageKernel`](/documentation/MetalPerformanceShaders/MPSUnaryImageKernel)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)