Biomedical Image Analysis in Python
Stephen Bailey
Instructor
Array's data type controls range of possible intensities
Type | Range | No. Val. |
---|---|---|
uint8 | 0, 255 | 256 |
int8 | - 128, 127 | 256 |
uint16 | 0, 2$^{16}$ | 2$^{16}$ |
int16 | -2$^{15}$, 2$^{15}$ | 2$^{16}$ |
float16 | ~-2$^{16}$, ~2$^{16}$ | >>2$^{16}$ |
import imageio im=imageio.imread('foot-xray.jpg') im.dtype dtype('uint8')
im.size
153600
im_int64 = im.astype(np.uint64)
im_int64.size
1228800
scipy.ndimage
scikit-image
.plt.plot(hist)
plt.show()
import scipy.ndimage as ndi
hist=ndi.histogram(im, min=0, max=255, bins=256)
hist.shape
(256,)
Distributions often skewed toward low intensities (background values).
Equalization: redistribute values to optimize full intensity range.
Cumulative distribution function: (CDF) shows proportion of pixels in range.
import scipy.ndimage as ndi hist = ndi.histogram(im, min=0, max=255, bins=256)
cdf = hist.cumsum() / hist.sum() cdf.shape
(256,)
im_equalized = cdf[im] * 255
fig, axes = plt.subplots(2, 1) axes[0].imshow(im) axes[1].imshow(im_equalized) plt.show()
Biomedical Image Analysis in Python