Masks

Biomedical Image Analysis in Python

Stephen Bailey

Instructor

Masks

Raw image

FullBrain

Image mask

Mask

Biomedical Image Analysis in Python

Creating masks

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)
Biomedical Image Analysis in Python

Creating masks

 

hist=ndi.histogram(im, 0, 255, 256)

 

mask1 = im > 32

foot-histogram

foot mask 1

Biomedical Image Analysis in Python

Creating masks

 

mask2 = im > 64

 

mask3 = mask1 & ~mask2

foot mask 2

foot mask 1 and 2

Biomedical Image Analysis in Python

Applying masks

np.where(condition, x, y)  controls what data passes through the mask.

import numpy as np

im_bone = np.where(im > 64, im, 0)
plt.imshow(im_bone, cmap='gray')
plt.axis('off')
plt.show()

image-with-non-bone-removed

Biomedical Image Analysis in Python

Tuning masks

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

foot mask 1

ndi.binary_dilation(m,iterations=5)

foot mask binary dilation

Biomedical Image Analysis in Python

Tuning masks

ndi.binary_erosion(m,iterations=5)

foot mask binary erosion

Biomedical Image Analysis in Python

Let's practice!

Biomedical Image Analysis in Python

Preparing Video For Download...