applyLookup(_:destination:)
Applies a lookup table to transform an 8-bit planar image to a 32-bit-per-channel, three-channel interleaved image.
Declaration
func applyLookup(_ lookupTable: [Pixel_FFFF], destination: vImage.PixelBuffer<vImage.InterleavedFx3>)Parameters
- lookupTable:
A lookup table that contains 256 Pixel_ffff 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_FFFF] = (0 ..< 256).map { i in
let red = window[ max(0, min(127 - i, 255))]
let green = window[i]
let blue = window[ max(0, min(382 - i, 255))]
return Pixel_FFFF(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.InterleavedFx3 destination buffer:
let destinationBuffer = vImage.PixelBuffer (
size: sourceBuffer.size,
pixelFormat: vImage.InterleavedFx3.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]