Reputation: 495
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?
Upvotes: 4
Views: 1519
Reputation: 69116
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.
Upvotes: 2