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

# MPSCNNSpatialNormalization

A spatial normalization kernel.

```
class MPSCNNSpatialNormalization
```

## Overview

The spatial normalization for a feature channel 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`).

For each feature channel, the function computes the sum of squares of `X` inside each rectangle, `N2(i,j)`. It then divides each element of `X` as follows:

![Y(i,j) = X(i,j) / (delta + alpha/(kw*kh) * N2(i,j))^beta](images/com.apple.metalperformanceshaders/media-2903551@2x.png)

Where `kw` and `kh` are the values of the `kernelWidth` and `kernelHeight` properties, respectively. It is your responsibility to ensure that the combination of the values of the [`delta`](/documentation/MetalPerformanceShaders/MPSCNNSpatialNormalization/delta) and [`alpha`](/documentation/MetalPerformanceShaders/MPSCNNSpatialNormalization/alpha) `kernelWidth` `kernelHeight` properties does not result in a situation where the denominator becomes zero (in such situations the resulting pixel-value is undefined).

> Note:
> 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/MPSCNNSpatialNormalization`` object to a <doc://com.apple.documentation/documentation/Metal/MTLCommandBuffer> object.

## Topics

### Initializers

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

Initializes a spatial normalization kernel.

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

Initializes a spatial normalization kernel.

### Instance Properties

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

The “alpha” variable of the kernel function.

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

The “beta” variable of the kernel function.

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

The “delta” variable of the kernel function.

### Instance Methods

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

Initializes a spatial 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)