【发布时间】:2018-07-05 08:59:09
【问题描述】:
我有一堆图像。堆栈上的第一个看起来像这样:
import dicom as dc
dcm = dc.read_file('full_stack.dcm')
dcm = dcm.pixel_array
print type(dcm)
print dcm.shape
这给了我
<type 'numpy.ndarray'>
(3, 180, 480, 640)
所以看起来有:
- 3 个频道
- 180 张图片
- 宽度为480
- 身高640
太棒了。
我的目标是在堆栈中提取图像。然后,我想显示该图像。听起来很简单。
这是我的策略。我希望对此有任何想法/反馈:
1) 获取一张图片。使用基本切片获取堆栈中的第 10 个图像
dcm1 = dcm[0:, 10:11]
dcm1.shape
(3, 1, 480, 640)
2) 要使用plt.imshow 在 pyplot 中实际绘制它,我们需要这个形状:(r, c, channels)。所以我猜想用蛮力把图像打掉。
dcm2 = np.squeeze(dcm1, axis=1) # throw away the '1'...this makes me nervous
print 'threw away the "1": ', dcm2.shape
dcm3 = np.swapaxes(dcm2, 0,2)
print 'swapped the first and last dim: ', dcm3.shape
dcm4 = np.swapaxes(dcm3, 0,1)
print 'swapped the first and second dim:', dcm4.shape
现在,我已经把这张糟糕的图片改成了这样:
threw away the "1": (3, 480, 640)
swapped the first and last dim: (640, 480, 3)
swapped the first and second dim: (480, 640, 3)
是时候策划了!什么可能会出错?
imgplot = plt.imshow(dcm4)
这是我得到的:
不知何故,我的图像现在有各种颜色,看起来很糟糕。
我的问题从这里开始——有人知道发生了什么吗?显然,我的方法不成熟且不令人满意。但我不确定该去哪里。
额外的东西,可能并不相关
此时,我尝试将频道缩减为一个,然后复制到三个,以便imshow 可以阅读它,我会为您保存详细信息,但它给了我这个:
【问题讨论】:
-
Stackoverflow 上的问题应该是可重现的,请参阅minimal reproducible example。因此,在提供一些示例数据或至少链接到它时,您可能会找到更多帮助,以便人们可以对此进行测试
-
如果我没记错的话,dicom 图像通常以 hounsfield 为单位。您确定只在数组中加载
uint8值吗? -
仅用于 CT 还是也用于超声?我得调查一下!谢谢!
标签: python image numpy matplotlib imshow