keystoneCorrectionCombined()
Adjusts the image vertically and horizontally to remove distortion.
Declaration
class func keystoneCorrectionCombined() -> any CIFilter & CIKeystoneCorrectionCombinedReturn Value
The adjusted image.
Discussion
This method applies the keystone correction combined filter to an image. The effect applies a combined set of horizontal and vertical guides to adjust the shape of the input image. This effect is commonly used when cropping an image to correct distortion. In the figure below, both vertical and horizontal adjustments are made, resulting in a trapezoid-shaped image.
The keystone correction filter uses the following properties:
inputImageAn image with the type CIImage.
topLeftA CGPoint in the input image mapped to the top-left corner of the output image.
topRightA CGPoint in the input image mapped to the top-right corner of the output image.
bottomLeftA CGPoint in the input image mapped to the bottom-left corner of the output image.
bottomRightA CGPoint in the input image mapped to the bottom-right corner of the output image.
focalLengthA
floatrepresenting the simulated focal length as an NSNumber.
The following code creates a filter that distorts the image:
func keystoneCorrectionCombined(inputImage: CIImage) -> CIImage {
let keystoneCorrect = CIFilter.keystoneCorrectionCombined()
keystoneCorrect.inputImage = inputImage
keystoneCorrect.topLeft = CGPoint(x: 0, y: 2448)
keystoneCorrect.topRight = CGPoint(x: 3164, y: 2248)
keystoneCorrect.bottomLeft = CGPoint(x: 0, y: 0)
keystoneCorrect.bottomRight = CGPoint(x: 3164, y: 150)
keystoneCorrect.focalLength = 35
return keystoneCorrect.outputImage!
}[Image]