英文:
How to mask a DICOM image?
问题
我想要分析从头部CT中提取的"Bone"区域。
为此,我读取了DICOM文件,并对像素值小于200的区域进行了掩蔽,用"0"来填充。
然而,因为在DICOM图像中"0"代表"水",我不知道这是否是一种适当的方式。
英文:
I would like to analyze only "Bone" regions extracted from Head CT.
For that, I read the DICOM files and masked regions where pixel values were less than 200 by filling in "0".
However, because "0" means "water" in the DICOM image, I don't know whether this is an appropriate way or not.
import pydicom
import numpy as np
dcm_img = pydicom.dcmread("0000200.dcm")
dcm_arr = dcm_img.pixel_array
masked_arr = np.where(dcm_arr < 200, 0, dcm_arr)
答案1
得分: 3
根据你的问题,我不太清楚你想如何分析CT图像中的骨骼区域,所以很难提供一个定制的答案。一般来说,我不会将图像中的值设为零,因为正如你所说,CT图像中的每个值都与特定的组织属性相关联(而且在图像处理中,通常不将图像和掩模信息混为一谈通常是不明智的)。
相反,我可能会使用掩蔽数组,屏蔽掉所有低于骨阈值的值,如下所示:
from numpy.ma import masked_array
...
masked_arr = masked_array(data=dcm_arr, mask=dcm_arr < 200)
有了这个,你可以使用掩蔽数组提供的操作,例如masked_arr.mean()
,它计算所有未被掩蔽掉的体素的平均值(这就是为什么我们屏蔽了低于阈值的值)。
或者,但非常类似,我可能会创建一个新的(常规的)Numpy数组,其中包含一个布尔掩码,标记所有位于骨阈值之上的值(例如is_bone = dcm_arr >= 200
),我稍后会在分析中使用它来过滤值。
无论如何,我会尽量保持掩蔽值和实际CT体素值分开。
英文:
From your question, it is not quite clear to me how exactly you want to analyze the bone regions in your CT image, so it is hard to provide a tailored answer. Generally though, I would not set values to zero in the image, because – as you said – each value in a CT image is associated with specific tissue properties (also, very generally in image processing, it is usually not a good idea to conflate image and masking information).
Instead, I would probably work with a masked array, masking out all the values that lie below the bone threshold, like so:
from numpy.ma import masked_array
...
masked_arr = masked_array(data=dcm_arr, mask=dcm_arr < 200)
With this, you could then use the operations that a masked array provides, such as masked_arr.mean()
, which calculates the mean of all voxels that have not been masked out (which is why we masked the values below the threshold).
Alternatively, but very similar, I would probably create a new (regular) Numpy array, containing a boolean mask that marks all the values that do lie above the bone threshold (e.g. is_bone = dcm_arr >= 200
), which I would later use for filtering values in my analyses.
In any case, I would try to keep the mask values and the actual CT voxel values separate.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论