vImage.PixelBuffer
An image buffer that stores an image’s pixel data, dimensions, bit depth, and number of channels.
Declaration
struct PixelBuffer<Format> where Format : PixelFormatMentioned in
- Enhancing image contrast with histogram manipulation
- Applying vImage operations to regions of interest
- Building a basic image conversion workflow
- Applying color transforms to images with a multidimensional lookup table
- Converting bitmap data between Core Graphics images and vImage buffers
- Converting chroma-subsampled images
- Optimizing image-processing performance
Overview
Use a vImage.PixelBuffer to represent an image from a CGImage instance, a CVPixelBuffer structure, or a collection of raw pixel values. Pixel buffers are typed by their bits per channel and number of channels. For example, vImage.Interleaved8x4 indicates a 4-channel, 8-bit-per-channel pixel buffer that contains image data such as RGBA or CMYK.
Pixel buffers expose methods that are available for the buffer’s pixel format. For example, the fast box convolution functions are only available for one- and four-channel 8-bit per channel buffers:
let src = vImage.PixelBuffer<vImage.Interleaved8x4>(cgImage: cgImage,
cgImageFormat: &cgImageFormat)
let dest = vImage.PixelBuffer<vImage.Interleaved8x4>(src.size)
src.boxConvolve(kernelSize: vImage.Size(width: 64, height: 64),
edgeMode: .truncateKernel,
destination: dest)Typed pixel buffers provide a simple API to convert between pixel formats. For example, the following code converts 8-bit unsigned integer pixels to 32-bit floating point pixels:
let src = vImage.PixelBuffer<vImage.Interleaved8x4>(cgImage: cgImage,
cgImageFormat: &cgImageFormat)
let dest = vImage.PixelBuffer<vImage.InterleavedFx4>(size: src.size)
src.convert(to: dest)vImage pixel buffers manage their memory, therefore, you don’t need to call deallocate() when you’re finished with the buffer.
Topics
Pixel buffer essentials
Inspecting a pixel buffer
Pixel buffer methods
copy(to:)copy(to:cvImageFormat:cgImageFormat:)makeCGImage(cgImageFormat:)withCVPixelBuffer(readOnly:body:)
Pixel buffer operations
Applying geometric operations to pixel buffersApplying color transforms to pixel buffersBlending and compositing pixel buffersConvolving and applying morphologyThresholding and clipping pixel buffer valuesCalculating and transforming histogramsConverting pixel buffersInterleaving and deinterleaving pixel buffersCropping and working with regions of interestApplying channel operationsApplying arithmetic operations
Instance Properties
Instance Methods
applyLookup(_:destination:)applyLookup(_:destination:)applyLookup(_:destination:)applyMorphology(operation:destination:)applyMorphology(operation:destination:)convolve(with:bias:edgeMode:destination:)separableConvolve(horizontalKernel:verticalKernel:bias:edgeMode:destination:)withBNNSTensor(_:)