Biomedical Image Analysis in Python
Stephen Bailey
Instructor
Raw image

Image mask

Logical operations result in True / False at each pixel
mat = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])mat > 5
np.array([[False, False, False],
[False, False, True ],
[True, True, True ]])
Sample Operations
| Operation | Example |
|---|---|
| Greater | im > 0 |
| Equal to | im == 1 |
| X and Y | (im > 0) & (im < 5) |
| X or Y | (im > 10) | (im < 5) |
hist=ndi.histogram(im, 0, 255, 256)
mask1 = im > 32


mask2 = im > 64
mask3 = mask1 & ~mask2


np.where(condition, x, y)
controls what data passes through the mask.
import numpy as npim_bone = np.where(im > 64, im, 0)
plt.imshow(im_bone, cmap='gray')
plt.axis('off')
plt.show()

m = np.where(im > 64, 1, 0)

ndi.binary_dilation(m,iterations=5)

ndi.binary_erosion(m,iterations=5)

Biomedical Image Analysis in Python