transform(_:interpolation:backgroundColor:destination:)
Applies a perspective warp to a floating-point 16-bit planar image.
Declaration
func transform(_ transform: vImage_PerpsectiveTransform, interpolation: vImage_PerpsectiveTransform.Interpolation, backgroundColor: Pixel_16F, destination: vImage.PixelBuffer<Format>)Parameters
- transform:
The projective-transformation matrix that the function applies.
- interpolation:
An enumeration that specifies the interpolation mode.
- backgroundColor:
The background color.
- destination:
The destination pixel buffer.
Discussion
Use this function to apply a projective-transformation structure to a pixel buffer. Projective transformations warp an image in 3D and allow you to, for example, map a 2D asset to an image of a billboard or television screen.
The following code defines source and destination quadrilaterals that specify a projective-transformation structure:
let sourceQuadrilateral = (CGPoint(x: 0, y: 0), // Top-left.
CGPoint(x: 1000, y: 0), // Top-right.
CGPoint(x: 1000, y: 1000), // Bottom-right.
CGPoint(x: 0, y: 1000)) // Bottom-left.
let destinationQuadrilateral = (CGPoint(x: 300, y: 375), // Top-left.
CGPoint(x: 700, y: 125), // Top-right.
CGPoint(x: 700, y: 875), // Bottom-right.
CGPoint(x: 300, y: 625)) // Bottom-left.
guard let warp = vImage_PerpsectiveTransform(
source: sourceQuadrilateral,
destination: destinationQuadrilateral) else {
return
}You pass the vImage_PerpsectiveTransform structure to this function to apply the warp to the source pixel buffer and write the result to the destination buffer.
sourceBuffer.transform(warp,
interpolation: .linear,
backgroundColor: backgroundColor,
destination: destinationBuffer)The illustration below shows the original image on the left and the warped image on the right:
[Image]