<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vImage/PixelBuffer/colorThreshold(_:destination:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate6vImageO11PixelBufferVA2A06StaticC6FormatRzSf13ComponentTypeRtzrlE14colorThreshold_11destinationySf_AEy_xGtF"
  },
  "title" : "colorThreshold(_:destination:)"
}
-->

# colorThreshold(_:destination:)

Creates a binary image from a 32-bit pixel buffer.

```
func colorThreshold(_ threshold: Float, destination: vImage.PixelBuffer<Format>)
```

## Parameters

`threshold`

The threshold value.

`destination`

The destination pixel buffer.

## Discussion

This function generates an image with source values that are less than `threshold` set to `0`, and source values that are greater than `threshold` set to `1`.

Use this function to binarize an image. For example, the following code applies a threshold of `0.5` to a pixel buffer. The source values `0.0`, `0.2`, and `0.4` are less than the threshold and the function returns `0.0` for the first three elements. The source values `0.6`, `0.8`, and `1.0` are greater than the threshold and the function returns `1.0` for the last three elements.

```swift
let buffer = vImage.PixelBuffer<vImage.PlanarF>(
    pixelValues: [0.0, 0.2, 0.4, 0.6, 0.8, 1.0],
    size: vImage.Size(width: 6,
                      height: 1))

buffer.colorThreshold(0.5,
                      destination: buffer)

// Prints "[0.0, 0.0, 0.0, 1.0, 1.0, 1.0]".
print(buffer.array)
```

---

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)