強度值

Python 的生醫影像分析

Stephen Bailey

Instructor

像素與體素

  • Pixels 是 2D 影像像素
  • Voxels 是 3D 體素
  • 兩個屬性:強度與位置

foot-xray

Python 的生醫影像分析

資料型別與影像大小

陣列的資料型別決定可能的強度範圍

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.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
Python 的生醫影像分析

直方圖

  • 直方圖(Histogram):統計各強度值的像素數。
  • 實作於 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,)

Histogram

Python 的生醫影像分析

均衡化

  • 分佈常偏向低強度(背景值)。

  • 均衡化:重分配數值以利用完整強度範圍。

  • 累積分佈函數(CDF):顯示區間內像素比例。

Hist+CDF

Python 的生醫影像分析

均衡化

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()

equalized-image

Python 的生醫影像分析

一起來練習吧!

Python 的生醫影像分析

Preparing Video For Download...