depthOfField()
Simulates a depth of field effect.
Declaration
class func depthOfField() -> any CIFilter & CIDepthOfFieldReturn Value
The modified image.
Discussion
This method applies the depth of field filter to an image. The effect simulates changing the focus of the camera before taking a photograph.
The depth of field filter uses the following properties:
inputImageAn image with the type CIImage.
radiusA
floatrepresenting the area of effect as an NSNumber.point0A set of coordinates marking the first point to be focused on as a CGPoint.
point1A set of coordinates marking the second point to be focused on as a CGPoint.
unsharpMaskRadiusA
floatrepresenting the radius of the unsharpened mask effect applied to the in-focus area of effect as an NSNumber.unsharpMaskIntensityA
floatrepresenting the intensity of the unsharp mask effect as an NSNumber.
The following code creates a filter that results in the center cilantro being in focus while gradually blurring to the top and bottom of the image:
func depthOfField(inputImage: CIImage) -> CIImage {
let depthOfFieldFilter = CIFilter.depthOfField()
depthOfFieldFilter.inputImage = inputImage
depthOfFieldFilter.radius = 5
depthOfFieldFilter.point0 = CGPoint(x: 2349, y: 846)
depthOfFieldFilter.point1 = CGPoint(x: 571, y: 3121)
depthOfFieldFilter.unsharpMaskRadius = 7
depthOfFieldFilter.unsharpMaskIntensity = 10
return depthOfFieldFilter.outputImage!
}[Image]