【问题标题】:Visualize SimpleITK coordinates on Paraview在 Paraview 上可视化 SimpleITK 坐标
【发布时间】:2021-05-05 20:09:36
【问题描述】:

我正在尝试制作一个 SimpleITK 图像,我希望特定体素值为 1,其余为 0。我是 SimpleITK 的新手,所以我觉得我错过了一些东西。

无论如何,我已经生成了一些索引,我将体素值分配为 1。但是,我希望能够可视化这些样本在空间中相对于彼此的方向。我尝试了多种方法,将一个充满零且所需索引为 1 的数组转换为 NIFTI 图像,但我仍然无法将其可视化并查看这些点的外观

下面是我试过的基本代码sn-p

 def WriteSampleToDisk():
"""Creates an empty image, assigns generated samples with voxel value 1 and writes it to disk.

returns image written to disk"""

img = sitk.Image(512, 512, 416, sitk.sitkInt16)
img.SetOrigin((0, 0, 0))
img.SetSpacing((1, 1, 1))

#Some code to get indices 
for i in range(len(dimx)): #Same number of elements in every index dimension
    img.SetPixel(dimz[i], dimy[i], dimx[i], 1)#Sitk convention takes z axis as the first axis
arr = sitk.GetArrayFromImage(img)
print(np.argwhere(arr == 1)) --> It's giving me the indices where I have Set the voxel value as 1
sitk.WriteImage(img, "image.nii")
return img

但是,即使设置了阈值,当我尝试在 paraview 上查看它时,我仍然一无所获。这可能是什么原因?有没有办法规避这个问题?

【问题讨论】:

    标签: python paraview itk simpleitk medical-imaging


    【解决方案1】:

    您的体素类型是 Int16,其范围为 -32768 到 32767。但您将体素设置为 1。鉴于强度范围,这与 0 没有太大区别,因此几乎与 0 相同,视觉上。

    尝试将您的体素设置为 32767。此外,您可能希望在设置体素后放大图像。一个体素点将非常小且难以看到。运行 BinaryDilateFilter 以增大点的大小。

    更新:好的,这是我写的一个例子。它创建一个 UInt8 体积并将其中的随机点设置为 255。然后它从点体积创建一个距离图体积。

    import random
    import SimpleITK as sitk
    
    random.seed()
    
    img = sitk.Image([512,512,512], sitk.sitkUInt8)
    
    for i in range(1000):
        x = random.randrange(512)
        y = random.randrange(512)
        z = random.randrange(512)
        print(x,y,z)
    
        img[x,y,z] = 255
    
    sitk.WriteImage(img, "dots.nrrd")
    
    dist = sitk.SignedMaurerDistanceMap(img)
    sitk.WriteImage(dist, "dots.dist.nrrd")
    
    sitk.Show(dist)
    

    对于 SignedMaurierDistanceMap,体素可以是任何值,只要不是背景值即可。

    【讨论】:

    • 您好,非常感谢您的回复。我对 SimpleITK 有点陌生。你能帮我写下这方面的代码吗?实际上,稍后我必须找到这张图像的 Maurer 距离图,所以我需要相应地设置体素强度类型并在其上查询我的样本。
    猜你喜欢
    • 1970-01-01
    • 2022-07-28
    • 2017-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-16
    • 2016-06-24
    • 1970-01-01
    相关资源
    最近更新 更多