Issues with volume Threshold and Slicer
See original GitHub issueI have been trying to threshold a volume coming from a VTI image file (structured data). This 3D array contains segmented data, meaning each voxel has a label (0 to 5). I can easily visualize this volume using either show() or Slicer(). I would like to replace classes by 0’s and 1’s depending on the threshold range and visualize the output using Slicer().
Approach 1: using standard vtk
filename = 'test.vti'
vol = load(filename)
# vtkImageThreshold filter
thresholdFilter = vtk.vtkImageThreshold()
thresholdFilter.SetInputData(vol.imagedata())
thresholdFilter.SetInValue(1)
thresholdFilter.SetOutValue(0)
thresholdFilter.ThresholdBetween(0, 2)
thresholdFilter.Update()
thresholdedImage = thresholdFilter.GetOutput()
# Create volume from vtkImageData (output of thresholdFilter.GetOutput())
thresVol = Volume(inputobj=thresholdedImage)
# Show results
show(thresVol)
Result: I see exactly what I expected to see, the right voxels are show in blue color.
Approach 2: using standard vtk, but trying to use Slicer to see the data
filename = 'test.vti'
vol = load(filename)
# vtkImageThreshold filter
thresholdFilter = vtk.vtkImageThreshold()
thresholdFilter.SetInputData(vol.imagedata())
thresholdFilter.SetInValue(1)
thresholdFilter.SetOutValue(0)
thresholdFilter.ThresholdBetween(0, 2)
thresholdFilter.Update()
thresholdedImage = thresholdFilter.GetOutput()
# Create volume from vtkImageData (output of thresholdFilter.GetOutput())
thresVol = Volume(inputobj=thresholdedImage)
# Show results
plt = Slicer(thresVol,
bg='white', bg2='lightblue',
cmaps=("gist_ncar_r", "jet", "Spectral_r", "hot_r", "bone_r"),
useSlider3D=False,
showIcon=False,
draggable=False)
plt.show()
Result: Slicer comes empty, all the voxels are with label 0. Note that I only changed the way to visualize the data from Approach 1 (Slicer() instead of show())
Approach 3: using vedo Volume thresholding
filename = 'test.vti'
vol = load(filename)
# Thresholding
vol = vol.threshold(above = 0.0, below=2.0, replaceWith=1)
# Show results
show(vol)
Result: I do not see what I expected to see, just some blue voxels, as if the threshold is keeping only few voxels
I honestly do not see what I might be doing wrong…I would appreciate any help.
Thanks! Rafael.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Many thanks Marco! Will give it a go now.
I close this for the moment, reopen it if needed!