applyLookup(_:destination:)
Applies a lookup table to transform an 8-bit planar image to an 8-bit-per-channel, three-channel interleaved image.
Declaration
func applyLookup(_ lookupTable: [Pixel_8888], destination: vImage.PixelBuffer<vImage.Interleaved8x3>)Parameters
- lookupTable:
A lookup table that contains 256 Pixel_8888 ARGB values. The function discards the alpha component.
- destination:
The destination pixel buffer.
Discussion
You can use this function to create pseudo-color images by transforming a grayscale image to an RGB image.
The following code creates a simple lookup table with a high red response for low values, a high green response for middle values, and a high blue response for large values:
let window = vDSP.window(ofType: Float.self,
usingSequence: .blackman,
count: 256,
isHalfWindow: false)
let lookup: [Pixel_8888] = (0 ..< 256).map { i in
let red = Pixel_8(window[ max(0, min(127 - i, 255))] * 255)
let green = Pixel_8(window[i] * 255)
let blue = Pixel_8(window[ max(0, min(382 - i, 255))] * 255)
return Pixel_8888(0, red, green, blue)
}The graph below visualizes the values in the lookup table:
[Image]
Use the following code to apply the lookup table to a vImage.Planar8 source buffer with a vImage.Interleaved8x3 destination buffer:
let destinationBuffer = vImage.PixelBuffer (
size: sourceBuffer.size,
pixelFormat: vImage.Interleaved8x3.self)
sourceBuffer.applyLookup(lookup, destination: destinationBuffer)The images below show an example grayscale source image on the left and the pseudo-color result on the right. The operation converts dark areas in the source to red in the destination, and light areas in the source to blue in the destination.
[Image]