mask pixels output of roi
时间: 2023-10-15 20:05:31 浏览: 41
To mask the pixels output of a region of interest (ROI), you can use a binary mask that has the same dimensions as your image. The mask should have a value of 1 for pixels within the ROI and 0 for pixels outside the ROI. You can then multiply your image by the mask to set all pixels outside the ROI to zero:
```
import numpy as np
# Define your ROI
roi_x, roi_y, roi_width, roi_height = (100, 100, 50, 50)
# Create a binary mask for the ROI
mask = np.zeros((img.shape[0], img.shape[1]))
mask[roi_y:roi_y+roi_height, roi_x:roi_x+roi_width] = 1
# Mask the image
masked_img = img * mask
```
In the above code, `img` is your input image, and `roi_x`, `roi_y`, `roi_width`, and `roi_height` define the location and size of your ROI. The `mask` is created using `numpy.zeros()` and then setting the appropriate values to 1. Finally, the `img` is multiplied by the `mask` to produce the `masked_img`.