python通过SimpleITK库预览.mha格式图片

python代码

import SimpleITK as sitk
import matplotlib.pyplot as plt
from pathlib import Path

def read_and_display_mha(file_path):
# 使用SimpleITK库读取MHA文件
image = sitk.ReadImage(str(file_path))
# 将SimpleITK图像转换为NumPy数组
image_array = sitk.GetArrayFromImage(image)
plt.imshow(image_array, cmap=‘gray’)
plt.axis(‘off’)
plt.show()

if name == “main”:
file_path = Path(“/Users/mark/ok.mha”) # 改为你的mha图片的路径地址
read_and_display_mha(file_path)

注意事项(Note)

路径可能不支持中文

猜你喜欢

转载自blog.csdn.net/crazyjinks/article/details/131167555