I am trying to just make an SimpleITK image where I want specific voxel values to be 1 and the rest to be 0. I am new to SimpleITK so I feel I am missing out on something.
Anyway, I have some indices that I have generated that I assign the voxel value of as 1. However, I want to be able to visualise how these samples are oriented with respect to each other in space. I have tried multiple ways from transforming an array full of zeroes with required indices as 1 to a NIFTI image however I am still not able to visualise it and see how these points look
Below is a basic code snippet I have tried
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
However when I try to view it on paraview even after setting the threshold, I still get nothing. What could be the reason for this? Is there a way to circumvent this problem?
Your voxel type is Int16 which has a range of -32768 to 32767. But you're setting your voxels to 1. Given the intensity range, that's not that different from 0 so it's pretty much going to be the same as 0, visually.
Try setting your on voxels to 32767. Also you might want to dilate your image after setting the voxels. A one voxel dot will be very small and difficult to see. Run the BinaryDilateFilter to grow the size of your dots.
UPDATE: ok, here's a example that I've written. It creates a UInt8 volume and sets random dots in it to 255. Then it creates a distance map volume from the dots volume.
For the SignedMaurierDistanceMap, the voxels can be any value, as long as it's not the background value.