python 使用sitk.ConnectedThresholdImageFilter()的SimpleITK过滤错误输出

kt06eoxx  于 2023-05-16  发布在  Python
关注(0)|答案(2)|浏览(179)

我已经尝试了很多事情来分割gray_matter,白色_matter和cs_fluid图像使用sitk.ConnectedThresholdImageFilter()。很不幸我不能请让我知道我做错了什么。
下面是示例代码:

data_dir = "<path to data dir>"
image_dir = data_dir + "images/" 
image_filenames = sorted(glob.glob(image_dir + '*.nii.gz'))

mask_dir = data_dir + "masks/" 
mask_filenames = sorted(glob.glob(mask_dir + '*.nii.gz'))

image_filename = image_filenames[0]
mask_filename = mask_filenames[0]

image = sitk.ReadImage(image_filename)
mask = sitk.ReadImage(mask_filename)

print("image_filename:", image_filename)
print("Image:")
display_image(image)
print("Mask:")
display_image(mask)

masked_image = sitk.Mask(image, mask)
print("Masked image:")
display_image(masked_image)

gm_filter = sitk.ConnectedThresholdImageFilter()
gm_filter.SetLower(1)  # Lower threshold for GM intensities
gm_filter.SetUpper(100)  # Upper threshold for GM intensities
gm_image = gm_filter.Execute(masked_image)
print("GM image:")
display_image(gm_image)

下面是输出:
图像:

掩模:

掩蔽图像:

GM图像:

这一切都很好,直到“通用汽车公司的形象”。我真的不知道我在sitk.ConnectedThresholdImageFilter()方法上做错了什么。先谢谢你了。

bis0qfac

bis0qfac1#

尚未指定区域生长的种子点,请在感兴趣区域内提供种子点。
您可以使用ConnectedThresholdImageFilterAddSeed方法来实现这一点。
edit:让我们尝试AddSeed方法
例如:

from glob import glob
import SimpleITK as sitk

data_dir = "<path to data dir>"
image_dir = data_dir + "images/" 
image_filenames = sorted(glob(image_dir + '*.nii.gz'))

mask_dir = data_dir + "masks/" 
mask_filenames = sorted(glob(mask_dir + '*.nii.gz'))

image_filename = image_filenames[0]
mask_filename = mask_filenames[0]

image = sitk.ReadImage(image_filename)
mask = sitk.ReadImage(mask_filename)

masked_image = sitk.Mask(image, mask)

gm_filter = sitk.ConnectedThresholdImageFilter()
gm_filter.SetLower(1)
gm_filter.SetUpper(100)
gm_filter.AddSeed((50, 50, 50))
gm_image = gm_filter.Execute(masked_image)
xqkwcwgp

xqkwcwgp2#

我可以通过同时使用名为sitk.BinaryThreshold()sitk.And()的方法来完成类似于我所需要的工作。

lower_threshold, upper_threshold = 100, 200 # Thresholds for gray matter
gm_image = sitk.BinaryThreshold(image, lower_threshold, upper_threshold, 1, 0)
gm_image = sitk.And(gm_image, mask)

print("GM image:")
display_image(gm_image)

下面是GM图像的结果:

我仍然想知道sitk.ConnectedThresholdImageFilter()的问题是什么。

相关问题