diff --git a/AutoscoperM/AutoscoperM.py b/AutoscoperM/AutoscoperM.py index f796b44..e930409 100644 --- a/AutoscoperM/AutoscoperM.py +++ b/AutoscoperM/AutoscoperM.py @@ -1264,16 +1264,6 @@ def generateVRGForCameras( :param filename: filename of the VRG """ self.createPathsIfNotExists(outputDir) - # Apply a thresh of 0 to the volume to remove air from the volume - thresholdScalarVolume = slicer.modules.thresholdscalarvolume - parameters = { - "InputVolume": volumeNode.GetID(), - "OutputVolume": volumeNode.GetID(), - "ThresholdValue": 0, - "ThresholdType": "Below", - "Lower": 0, - } - slicer.cli.runSync(thresholdScalarVolume, None, parameters) # write a temporary volume to disk volumeFileName = "AutoscoperM_VRG_GEN_TEMP.mhd" diff --git a/VirtualRadiographGeneration/VirtualRadiographGeneration.py b/VirtualRadiographGeneration/VirtualRadiographGeneration.py index 721155c..47d82f5 100644 --- a/VirtualRadiographGeneration/VirtualRadiographGeneration.py +++ b/VirtualRadiographGeneration/VirtualRadiographGeneration.py @@ -26,9 +26,19 @@ def generateVRG( :param height: Height of the output image """ + # Remove air and low-density materials by applying a threshold to the volume image data + # In CT scans, air has a value of -1000 HU and other low-density materials like fat range from -60 to -120 HU + thresholder = vtk.vtkImageThreshold() + thresholder.ThresholdByLower(0) + thresholder.ReplaceInOn() + thresholder.SetInValue(0) + thresholder.SetInputData(volumeImageData) + thresholder.Update() + thresholdedImageData = thresholder.GetOutput() + # find the min and max scalar values hist = vtk.vtkImageHistogramStatistics() - hist.SetInputData(volumeImageData) + hist.SetInputData(thresholdedImageData) hist.Update() minVal = hist.GetMinimum() maxVal = hist.GetMaximum() @@ -46,7 +56,7 @@ def generateVRG( # create the volume mapper volumeMapper = vtk.vtkGPUVolumeRayCastMapper() - volumeMapper.SetInputData(volumeImageData) + volumeMapper.SetInputData(thresholdedImageData) volumeMapper.SetBlendModeToComposite() volumeMapper.SetBlendModeToComposite() volumeMapper.SetUseJittering(False)