question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with volume Threshold and Slicer

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rafaelmarch3commented, Mar 15, 2021

Many thanks Marco! Will give it a go now.

0reactions
marcomusycommented, Mar 24, 2021

I close this for the moment, reopen it if needed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Threshold fail for Segment Editor - 3D Slicer Community
It is very large. Try resample by a spacing factor of 4 in Crop volume module and see if you still have issues....
Read more >
Unable to use Volume module Threshold widget in a meaningful ...
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
Read more >
Threshold Scalar Volume - 3D Slicer documentation
Overview. Threshold an image. Set image values to a user-specified outside value if they are below, above, or between simple threshold values. ThresholdAbove: ......
Read more >
3D Slicer Documentation - Read the Docs
Threshold will not work with non-scalar volume background volumes. • Mouse wheel can be used to move slice through volume, but on some...
Read more >
Threshold Performance of Suboptimum PPM Receivers
The threshold performance of a pulse position modulation (PPM) telemetry system which uses a slicer for a detector, suboptimum technique, is investigated, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found