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

# MPSCNNLocalContrastNormalization

A local-contrast normalization kernel.

```
class MPSCNNLocalContrastNormalization
```

## Overview

The local contrast normalization kernel is quite similar to the spatial normalization kernel, described in the [`MPSCNNSpatialNormalization`](/documentation/MetalPerformanceShaders/MPSCNNSpatialNormalization) class, in that it applies the kernel over local regions which extend spatially, but are in separate feature channels (i.e., they have the shape `1 x kernel width x kernel height`). However, instead of dividing by the local “energy” of the feature, the denominator uses the local variance of the feature - effectively the mean value of the feature is subtracted from the signal. For each feature channel, the function computes the variance `VAR(i,j)` and mean `M(i,j)` of `X(i,j)` inside each rectangle around the spatial point `(i,j)`. Then the result is computed for each element of `X` as follows:

![Y(i,j) = pm + ps * ( X(i,j) - p0 * M(i,j)) / (delta + alpha * VAR(i,j))^beta](images/com.apple.metalperformanceshaders/media-2903532@2x.png)

Where `kw` and `kh` are the values of the `kernelWidth` and the `kernelHeight` properties, respectively, and the values of the [`pm`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/pm), [`ps`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/ps), and [`p0`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/p0) properties can be used to offset and scale the result in various ways. For example setting `pm=0`, `ps=1`, `p0=1`, `delta=0`, `alpha=1.0` and `beta=0.5` scales input data so that the result has unit variance and zero mean, provided that input variance is positive.

It is your responsibility to ensure that the combination of the values of the [`delta`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/delta) and [`alpha`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/alpha) properties does not result in a situation where the denominator becomes zero - in such situations the resulting pixel-value is undefined. A good way to guard against tiny variances is to regulate the expression with a small delta value, for example `delta=1/1024`.

> Tip:
> The encoding methods in the ``doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSUnaryImageKernel`` class can be used to encode an ``doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization`` object to a <doc://com.apple.documentation/documentation/Metal/MTLCommandBuffer> object.

## Topics

### Initializers

[`init(coder:device:)`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/init(coder:device:))

Initializes a local contrast normalization kernel.

[`init(device:kernelWidth:kernelHeight:)`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/init(device:kernelWidth:kernelHeight:))

Initializes a local contrast normalization kernel.

### Instance Properties

[`alpha`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/alpha)

The “alpha” variable of the kernel function.

[`beta`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/beta)

The “beta” variable of the kernel function.

[`delta`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/delta)

The “delta” variable of the kernel function.

[`p0`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/p0)

The “p0” variable of the kernel function.

[`pm`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/pm)

The “pm” variable of the kernel function.

[`ps`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/ps)

The “ps” variable of the kernel function.

### Instance Methods

[`init(device:kernelWidth:kernelHeight:)`](/documentation/MetalPerformanceShaders/MPSCNNLocalContrastNormalization/init(device:kernelWidth:kernelHeight:))

Initializes a local contrast normalization kernel.



---

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)