---
title: "contrastStretch(binCount:destination:)"
framework: accelerate
role: symbol
role_heading: Instance Method
path: "accelerate/vimage/pixelbuffer/contraststretch(bincount:destination:)-704t6"
---

# contrastStretch(binCount:destination:)

Stretches the histogram of a 32-bit-per-channel, 4-channel interleaved pixel buffer.

## Declaration

```swift
func contrastStretch(binCount: Int, destination: vImage.PixelBuffer<vImage.InterleavedFx4>)
```

## Parameters

- `binCount`: The number of histogram entries for each channel.
- `destination`: The destination pixel buffer.

## Discussion

Discussion Use this function to evenly distributes a histogram’s pixel values across the full range of available pixel values. For example, the following code stretches the contrast of an image: let srcImage =  imageLiteral(resourceName: " ... ").cgImage(     forProposedRect: nil,     context: nil,     hints: nil)!

var cgImageFormat = vImage_CGImageFormat(     bitsPerComponent: 32,     bitsPerPixel: 32 * 4,     colorSpace: CGColorSpaceCreateDeviceRGB(),     bitmapInfo: CGBitmapInfo(rawValue: kCGBitmapByteOrder32Host.rawValue |                              CGBitmapInfo.floatComponents.rawValue |                              CGImageAlphaInfo.noneSkipFirst.rawValue))!

let buffer = try vImage.PixelBuffer(     cgImage: srcImage,     cgImageFormat: &cgImageFormat,     pixelFormat: vImage.InterleavedFx4.self)

buffer.contrastStretch(binCount: 1024,                        destination: buffer)

let outputImage = buffer.makeCGImage(cgImageFormat: cgImageFormat)

## See Also

### Related Documentation

- [Enhancing image contrast with histogram manipulation](accelerate/enhancing-image-contrast-with-histogram-manipulation.md)

### Contrast stretching

- [contrastStretch(destination:)](accelerate/vimage/pixelbuffer/contraststretch(destination:)-6usbh.md)
- [contrastStretch(binCount:destination:)](accelerate/vimage/pixelbuffer/contraststretch(bincount:destination:)-3bo13.md)
- [contrastStretch(destination:)](accelerate/vimage/pixelbuffer/contraststretch(destination:)-7zo9.md)
- [contrastStretch(destination:)](accelerate/vimage/pixelbuffer/contraststretch(destination:)-2nsx9.md)
- [contrastStretch(binCount:destination:)](accelerate/vimage/pixelbuffer/contraststretch(bincount:destination:)-81vq2.md)
