Skip to content

Commit

Permalink
WIP: add more customization options
Browse files Browse the repository at this point in the history
Added LoG kernel size, resampling and wavelet, see AIM-Harvard#25

Dependent on AIM-Harvard/pyradiomics#280

Not working at the moment - feature calculation is failing - I am missing
something!
  • Loading branch information
fedorov committed Aug 1, 2017
1 parent c58dc9f commit 39121f4
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions SlicerRadiomics/SlicerRadiomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,31 @@ def setup(self):
self.labelSliderWidget.toolTip = 'Set the label to use for masking the image'
# optionsFormLayout.addRow('Label', self.labelSliderWidget)

filteringCollapsibleButton = ctk.ctkCollapsibleButton()
filteringCollapsibleButton.text = 'Filtering'
filteringCollapsibleButton.collapsed = True
optionsFormLayout.addRow(filteringCollapsibleButton)

# LoG kernel sizes. default to 5 (?)
self.logKernelSizes = qt.QLineEdit()
self.binWidthSliderWidget.toolTip = 'Laplacian of Gaussian filter kernel sizes, separated by comma. If empty, no LoG filtering will be applied.'
# Layout within the dummy collapsible button
filteringFormLayout = qt.QFormLayout(filteringCollapsibleButton)
filteringFormLayout.addRow('LoG kernel sizes', self.logKernelSizes)

# Resampling
self.resampledVoxelSize = qt.QLineEdit()
self.resampledVoxelSize.toolTip = 'Three floating-point numbers separated by comma defining the resampled pixel size.'
# Layout within the dummy collapsible button
filteringFormLayout.addRow('Resampled voxel size', self.resampledVoxelSize)

# Wavelet
self.waveletCheckBox = qt.QCheckBox()
self.waveletCheckBox.checked = 0
self.waveletCheckBox.toolTip = \
'If checked, PyRadiomics will calculate features on the image after applying wavelet transformation'
optionsFormLayout.addRow('Wavelet-based features', self.waveletCheckBox)

# debug logging flag, defaults to false
self.debuggingCheckBox = qt.QCheckBox()
self.debuggingCheckBox.checked = 0
Expand Down Expand Up @@ -273,10 +298,29 @@ def onApplyButton(self):
slicer.app.processEvents()

# Compute features
kwargs = {}
# Always compute features on the original image
kwargs = {'inputImage': { "Original": {} }}
kwargs['binWidth'] = int(self.binWidthSliderWidget.value)
kwargs['symmetricalGLCM'] = self.symmetricalGLCMCheckBox.checked
# kwargs['label'] = int(self.labelSliderWidget.value)

logKernelSizesValue = self.logKernelSizes.text
if logKernelSizesValue:
try:
kwargs['inputImage']['LoG'] = {'sigma': [float(i) for i in logKernelSizesValue.split(',')]}
except:
self.logger.error('Failed to parse LoG sigma value from string \"'+logKernelSizesValue+'\"')
return

resampledVoxelSizeValue = self.resampledVoxelSize.text
if resampledVoxelSizeValue:
try:
kwargs['resampledPixelSpacing'] = [float(i) for i in resampledVoxelSizeValue.split(',')]
except:
self.logger.error('Failed to parse resampled voxel spacing from string \"'+resampledVoxelSizeValue+'\"')
return

if self.waveletCheckBox.checked:
kwargs['inputImage']['Wavelet'] = {}

imageNode = self.inputVolumeSelector.currentNode()
labelNode = self.inputMaskSelector.currentNode()
Expand Down Expand Up @@ -472,7 +516,10 @@ def run(self, imageNode, labelNode, segmentationNode, featureClasses, **kwargs):
featuresDict = {}
for l in labelsDict.keys():
self.logger.debug("Calculating features for "+l)
featuresDict[l] = self.calculateFeatures(grayscaleImage, labelsDict[l], featureClasses, **kwargs)
try:
featuresDict[l] = self.calculateFeatures(grayscaleImage, labelsDict[l], featureClasses, **kwargs)
except:
self.logger.error('calculateFeatures() failed')

return featuresDict

Expand Down Expand Up @@ -550,6 +597,7 @@ def test_SlicerRadiomics1(self):
kwargs['symmetricalGLCM'] = False
kwargs['verbose'] = False
kwargs['label'] = 1
#kwargs['inputImage'] = {"Original": {}}

for segNode in [binaryNode, surfaceNode]:

Expand Down

0 comments on commit 39121f4

Please sign in to comment.