CT图像中,每个器官的窗位窗宽都不同,有时我们需要着重观察某个器官,只需调整他们的窗位窗宽即可,以下为肺的窗位窗宽调整。
import numpy as np
import SimpleITK as sitk
def window(img):
win_min = -400
win_max = 1500
for i in range(img.shape[0]):
img[i] = 255.0*(img[i] - win_min)/(win_max - win_min)
min_index = img[i] < 0
img[i][min_index] = 0
max_index = img[i] > 255
img[i][max_index] = 255
img[i] = img[i] - img[i].min()
c = float(255)/img[i].max()
img[i] = img[i]*c
return img.astype(np.uint8)
img = sitk.ReadImage('./img.nii.gz')
img = sitk.GetArrayFromImage(img)
img = window(img)
out = sitk.GetImageFromArray(img)
sitk.WriteImage(out,'lung.nii.gz')