我尝试使用未知压缩(可能没有)访问DICOM文件的RGB像素数组。提取灰度像素阵列工作得非常好。在
但是,使用
import dicom
import numpy as np
data_set = dicom.read_file(path)
pixel_array = data_set.pixel_array
size_of_array = pixel_array.shape
if len(size_of_array ) == 3:
chanR = pixel_array[0][0:size_of_array[1], 0:size_of_array[2]]
chanG = pixel_array[1][0:size_of_array[1], 0:size_of_array[2]]
chanB = pixel_array[2][0:size_of_array[1], 0:size_of_array[2]]
output_array = (0.299 ** chanR) + (0.587 ** chanG) + (0.114 ** chanB)
目标是把它转换成一个普通的灰度数组。不幸的是,结果数组output_array
没有包含正确的像素数据。内容不是假标度,而是受到空间干扰。问题在哪里?在
您现在可能已经解决了这个问题,但我认为pydicom不能正确地解释planar configuration。在
您需要先执行以下操作:
从这里开始,您的图像将具有
[rows cols 3]
的形状,通道分开它不是RGB像素阵列,更好的方法是转换成灰度图像
获取CT图像的方法是在CT-dicom文件中获取像素阵列的属性。 CT-dicom文件像素数组中的元素类型都是uint16,但是python中的很多工具,比如OpenCV,一些人工智能的东西,都不能与之兼容。在
从CT-dicom文件中获取pixel_array(CT Image)后,需要将pixel_数组转换成灰度图像,这样您就可以通过python中的大量图像处理工具对该灰度图像进行处理。在
下面的代码是一个将pixel_数组转换为灰色图像的工作示例。
下面是我打印出来的结果。在
相关问题 更多 >
编程相关推荐