<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIFilter-swift.class/depthOfField()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Image",
      "CoreImage"
    ],
    "preciseIdentifier" : "c:objc(cs)CIFilter(cm)depthOfFieldFilter"
  },
  "title" : "depthOfField()"
}
-->

# depthOfField()

Simulates a depth of field effect.

```
class func depthOfField() -> any CIFilter & CIDepthOfField
```

## Return 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:

- `inputImage`: An image with the type [`CIImage`](/documentation/CoreImage/CIImage).
- `radius`: A `float` representing the area of effect as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `point0`: A set of coordinates marking the first point to be focused on as a <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint>.
- `point1`: A set of coordinates marking the second point to be focused on as a <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint>.
- `unsharpMaskRadius`: A `float` representing the radius of the unsharpened mask effect applied to the in-focus area of effect as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `unsharpMaskIntensity`: A `float` representing the intensity of the unsharp mask effect as an <doc://com.apple.documentation/documentation/Foundation/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:

```swift
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!
}
```

![Two photographs of a pile of cilantro. The photo on the left is clear and crisp with good lighting. In the photo on the right, a depth of field filter is applied, resulting in the cilantro in the image’s periphery becoming blurred while the center remains in focus.](images/com.apple.coreimage/media-3599997@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)