I have an numpy array with dimensions (200, 200, 3). It is an RGB image.
I also have the (xmin,ymin,xmax,ymax) coordinates of a region of this image that I would like to set to zero. This region should be zero in all three channels.
I can of course solve this with a loop, but that would be wasteful.
Is there a simple way to mask the array using numpy?
Use array slicing. If xmin, xmax, ymin and ymax are the indices of area of the array you want to set to zero, then:
a[xmin:xmax,ymin:ymax,:] = 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With