Contents

separableConvolve(horizontalKernel:verticalKernel:bias:edgeMode:destination:)

Performs separable convolution on an 8-bit planar pixel buffer.

Declaration

func separableConvolve(horizontalKernel: [Float], verticalKernel: [Float], bias: Float = 0, edgeMode: vImage.EdgeMode<Pixel_16U>, destination: vImage.PixelBuffer<Format>)

Parameters

  • horizontalKernel:

    The 1D horizontal convolution kernel.

  • verticalKernel:

    The 1D vertical convolution kernel.

  • bias:

    A value that the operation adds to each element in the convolution result, before performing any clipping.

  • edgeMode:

    The convolution edge mode. The background color must be a single Pixel_16u value.

  • destination:

    The destination pixel buffer.

Discussion

The following code shows how to apply a Gaussian blur using separable convolution to a planar buffer:

let srcImage = imageLiteral(resourceName: " ... ").cgImage(
    forProposedRect: nil,
    context: nil,
    hints: nil)!

var cgImageFormat = vImage_CGImageFormat(
    bitsPerComponent: 8,
    bitsPerPixel: 8 * 1,
    colorSpace: CGColorSpaceCreateDeviceGray(),
    bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue))!

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

let dest = vImage.PixelBuffer(
    size: src.size,
    pixelFormat: vImage.Planar8.self)

src.separableConvolve(
    horizontalKernel: vImage.ConvolutionKernel.gaussian1Dx7,
    verticalKernel:  vImage.ConvolutionKernel.gaussian1Dx7,
    edgeMode: .truncateKernel,
    destination: dest)

let outputImage = dest.makeCGImage(cgImageFormat: cgImageFormat)

See Also

Related Documentation

Separable convolution