強度(Intensity)
在本章中,我們將使用 2017 年 Radiological Society of North America 競賽中的一張手部放射線影像。X 光在像骨頭這類高密度組織中的吸收最高,因此對應的像素強度應該較高。基於這點,這類影像可用來預測孩童的「骨齡」。
先從載入影像並檢查其強度範圍開始。
影像的資料型別會決定可能的強度範圍;例如,8 位元無正負號整數(uint8)的數值範圍是 0 到 255。色彩條有助於把這些數值和畫面上看到的影像對應起來。
本章所有練習都已匯入下列模組:
import imageio.v2 as imageio
import numpy as np
import matplotlib.pyplot as plt
本練習屬於課程
Python 的生醫影像分析
練習說明
- 使用
imageio載入影像「hand-xray.jpg」。 - 列印影像的資料型別(
dtype)、最小值(min())與最大強度(max())。 - 使用
plt.imshow()繪製影像。用參數vmin與vmax明確將色彩映射的最小值(0)與最大值(255)設好。 - 使用
plt.colorbar()加上色彩條,然後呼叫自訂函式format_and_render_plot()繪出圖表。這部分已為你完成。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load the hand radiograph
im = ____
print('Data type:', ____)
print('Min. value:', ____)
print('Max value:', ____)
# Plot the grayscale image
____
plt.colorbar()
format_and_render_plot()