Python による生体医療画像解析
Stephen Bailey
Instructor

配列のデータ型が輝度値の範囲を決定する
| 型 | 範囲 | 値の数 |
|---|---|---|
| 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.v2 as 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 ndihist=ndi.histogram(im, min=0, max=255, bins=256)hist.shape
(256,)

分布は低輝度(背景値)に偏りやすい。
平均化:輝度範囲全体を最適に活用するよう値を再分配。
累積分布関数(CDF):範囲内のピクセルの割合を示す。

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] * 255fig, axes = plt.subplots(2, 1) axes[0].imshow(im) axes[1].imshow(im_equalized) plt.show()

Python による生体医療画像解析