---
title: "generateMaskedImage(ofInstances:from:croppedToInstancesExtent:)"
framework: vision
role: symbol
role_heading: Instance Method
path: "vision/vninstancemaskobservation/generatemaskedimage(ofinstances:from:croppedtoinstancesextent:)"
---

# generateMaskedImage(ofInstances:from:croppedToInstancesExtent:)

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

## Declaration

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

Return Value The pixel buffer that contains the image.

## See Also

### Creating a Mask

- [generateMask(forInstances:)](vision/vninstancemaskobservation/generatemask(forinstances:).md)
- [generateScaledMaskForImage(forInstances:from:)](vision/vninstancemaskobservation/generatescaledmaskforimage(forinstances:from:).md)
