医学图像预处理Python
- CT图像加窗显示
算法如下,
如果需要显示高对比度的图像,那么根据上述算法,将CT值映射到指定范围,即可获取清晰的图像了。python代码如下,
def map2win(image_arr, window_level=-400, window_width=1500):
"""
window_level = -450~-600
window_width = 1500~2000
"""
window_max = window_level + 0.5*window_width
window_min = window_level - 0.5*window_width
index_min = image_arr < window_min
index_max = image_arr > window_max
# index_mid = np.where((image >= window_min)&(image <= window_max))
image_arr = (image_arr - window_min) / (window_width/256) - 1
image_arr[index_min] = 0
image_arr[index_max] = 255
return image_arr