<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Vision",
  "identifier" : "/documentation/Vision/VNInstanceMaskObservation/generateMaskedImage(ofInstances:from:croppedToInstancesExtent:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Vision"
    ],
    "preciseIdentifier" : "c:objc(cs)VNInstanceMaskObservation(im)generateMaskedImageOfInstances:fromRequestHandler:croppedToInstancesExtent:error:"
  },
  "title" : "generateMaskedImage(ofInstances:from:croppedToInstancesExtent:)"
}
-->

# generateMaskedImage(ofInstances:from:croppedToInstancesExtent:)

Creates a high-resolution image where everything becomes transparent black, except for the instances you specify.

```
func generateMaskedImage(ofInstances instances: IndexSet, from requestHandler: VNImageRequestHandler, croppedToInstancesExtent cropResult: Bool) throws -> CVPixelBuffer
```

## Parameters

`instances`

The collection of instances.

`requestHandler`

The image request callback.

`cropResult`

A Boolean value that indicates whether to crop the image to the smallest rectangle that contains all instances.

## Return Value

The pixel buffer that contains the image.

## Discussion

---

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)