1. 遇到无法将dcm格式转成jpg的错误
报错:AttributeError: module ‘scipy.misc’ has no attribute ‘imsave’
【解决】
删除:import scipy.misc
改成: import imageio
删除:save_image = scipy.misc.imsave(out_path, DATA)
改成:save_image = imageio.imsave(out_path, DATA)
2. dcm转成jpg格式后,图像全黑的问题
当时的代码:
ds = pydicom.read_file(dcm_path)
img = ds.pixel_array # Extract image information
imageio.imsave(out_path, img)
【解决】
ds = pydicom.read_file(dcm_path)
img = ds.pixel_array # Extract image information
# Get the number of pixel
lens = img.shape[0] * img.shape[1]
# Get the max and min of pixel
temp = np.reshape(img, (lens,))
max_val = max(temp)
min_val = min(temp)
# Image normalization
img = (img - min_val) / (max_val - min_val)
# Draw the image and save
plt.imshow(img)
imageio.imsave(out_path, img)
本文档详细介绍了在将dcm格式的医学影像文件转换为jpg格式时遇到的两个常见问题及其解决方案。第一个问题是由于`scipy.misc.imsave`已废弃,替换为`imageio.imsave`。第二个问题是在转换过程中图像显示全黑,通过像素值归一化和使用matplotlib显示解决了该问题。提供了解决这两个问题的具体代码片段。
27万+

被折叠的 条评论
为什么被折叠?



