'How do I select values from one array based on a boolean array?
Let's say I have 2 numpy arrays, with the same 1200x1200 shape.
The first one contains boolean values. The second one is an image, that was converted to boolean as well via binary thresholding.
Now lets say I want to use the area determined by the TRUE values in the first array to perform operations in the same area in the second array.
I'm stumped. How could I do that? I've attached a diagram for what I want to do.
Minimal reproducible example:
img = io.imread("sample image.jpeg")
thresh = threshold_isodata(img)
binary = img <= thresh
Now I have this binary image that I have dilated by x amount (maintains the shape of 1200x1200), stored in another array, and computed the difference, thus forming the rings in array 1.
binary_dilated = binary_dilation(binary)
binary_ring = binary_dilated - binary
Now I want to perform mathematical operations only in the binary ring zone of the original binary image (fraction of true boolean values only in that ring area).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|