影像資料

Python 的生醫影像分析

Stephen Bailey

Instructor

生醫影像:超過一世紀的發現

$$1895$$

作者:Wilhelm Röntgen。- [1],公共領域,https://commons.wikimedia.org/w/index.php?curid=5059748

$$2017$$

作者:Mikael Häggström - 自製作品,CC0,https://commons.wikimedia.org/w/index.php?curid=61722886

Python 的生醫影像分析

課程目標

影像流程

工具箱

  • ImageIO
  • NumPy
  • SciPy
  • matplotlib
Python 的生醫影像分析

載入影像

  • imageio:讀取與儲存影像
  • Image 物件是 NumPy 陣列。
import imageio.v2 as imageio
im = imageio.imread('body-001.dcm')

type(im)
imageio.core.Image
im
Image([[125, 135, ..., 110],
       [100, 130, ..., 100],
        ...,
       [100, 150, ..., 100]], 
          dtype=uint8)
Python 的生醫影像分析

載入影像

  • 透過各維度的索引來切片陣列。
im[0, 0]
125
im[0:2, 0:2]
Image([[125, 135],
       [100, 130]], 
       dtype=uint8)
Python 的生醫影像分析

中繼資料

  • 「中繼資料」:影像擷取的對象、內容、時間、地點與方式

  • 可從 Image 物件的 meta 字典屬性存取

im.meta
im.meta['Modality']
im.meta.keys()
Dict([('StudyDate', '2017-01-01'),
      ('Modality', 'MR'),
      ('PatientSex', F),
      ...
      ('shape', (256, 256)])
'MR'
odict_keys(['StudyDate', 
            'SeriesDate', 
            'PatientSex',
             ...
             'shape'])
Python 的生醫影像分析

繪製影像

  • Matplotlib 的 imshow() 可顯示 2D 影像資料

  • 提供多種色圖,但常用灰階(cmap='gray'

  • 座標刻度與標籤對影像通常實用

import matplotlib.pyplot as plt

plt.imshow(im, cmap='gray')
plt.axis('off')
plt.show()

冠狀切面

Python 的生醫影像分析

一起來練習吧!

Python 的生醫影像分析

Preparing Video For Download...