【发布时间】:2019-07-09 15:41:10
【问题描述】:
我在使用 PIL 将图像 I;16 转换为 JPEG 时遇到问题。 我的原始图像可以在here 找到(作为泡菜)。 原始图像来自 DICOM 文件。 这是要尝试的代码:
import pickle
import matplotlib.pyplot as plt
from PIL import Image
ims = pickle.load(open("pixel_array.pickle", "rb"))
img = Image.fromarray(ims)
print(img.mode)
rgb_im = img.convert("RGB")
print(rgb_im.mode)
fig, ax = plt.subplots(figsize=(20, 10))
ax.imshow(rgb_im, cmap=plt.cm.bone)
fig.show()
不幸的是,图像完全是白色的,而应该是胸部 X 光扫描图像。
我关注了 this 其他 stackoverflow 问题,并提出了以下问题
ims = pickle.load(open("pixel_array.pickle", "rb"))
img = Image.fromarray(ims)
print(img.mode)
img.mode = 'I'
rgb_im = img.point(lambda i:i*(1./256)).convert('L')
rgb_im.save('my.jpeg')
fig, ax = plt.subplots(figsize=(20, 10))
ax.imshow(rgb_im, cmap=plt.cm.bone)
fig.show()
我能够可视化图像,但不幸的是my.jpeg 是黑色图像。请帮忙!
【问题讨论】:
标签: python python-imaging-library jpeg tiff