Skip to content

Commit

Permalink
BUG: Force label and label_channel to int
Browse files Browse the repository at this point in the history
Both label and label_channel are used in SimpleITK, which is more sensitive to datatypes (i.e. will fail when either parameter is int64_t). Therefore, force these values to int.
  • Loading branch information
JoostJM committed May 9, 2023
1 parent 7f49638 commit efb9756
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions radiomics/generalinfo.py
Expand Up @@ -113,8 +113,8 @@ def addMaskElements(self, image, mask, label, prefix='original'):
lssif = sitk.LabelShapeStatisticsImageFilter()
lssif.Execute(mask)

self.generalInfo[self.generalInfo_prefix + 'Mask-' + prefix + '_BoundingBox'] = lssif.GetBoundingBox(label)
self.generalInfo[self.generalInfo_prefix + 'Mask-' + prefix + '_VoxelNum'] = lssif.GetNumberOfPixels(label)
self.generalInfo[self.generalInfo_prefix + 'Mask-' + prefix + '_BoundingBox'] = lssif.GetBoundingBox(int(label))
self.generalInfo[self.generalInfo_prefix + 'Mask-' + prefix + '_VoxelNum'] = lssif.GetNumberOfPixels(int(label))

labelMap = (mask == label)
ccif = sitk.ConnectedComponentImageFilter()
Expand Down
8 changes: 4 additions & 4 deletions radiomics/imageoperations.py
Expand Up @@ -38,7 +38,7 @@ def getMask(mask, **kwargs):

logger.info('Extracting mask at index %i', label_channel)
selector = sitk.VectorIndexSelectionCastImageFilter()
selector.SetIndex(label_channel)
selector.SetIndex(int(label_channel))
mask = selector.Execute(mask)

logger.debug('Force casting mask to UInt32 to ensure correct datatype.')
Expand Down Expand Up @@ -216,7 +216,7 @@ def checkMask(imageNode, maskNode, **kwargs):

correctedMask = None

label = kwargs.get('label', 1)
label = int(kwargs.get('label', 1))
minDims = kwargs.get('minimumROIDimensions', 2)
minSize = kwargs.get('minimumROISize', None)

Expand Down Expand Up @@ -316,7 +316,7 @@ def _checkROI(imageNode, maskNode, **kwargs):
returned. Otherwise, a ValueError is raised.
"""
global logger
label = kwargs.get('label', 1)
label = int(kwargs.get('label', 1))

logger.debug('Checking ROI validity')

Expand Down Expand Up @@ -442,7 +442,7 @@ def resampleImage(imageNode, maskNode, **kwargs):
resampledPixelSpacing = kwargs['resampledPixelSpacing']
interpolator = kwargs.get('interpolator', sitk.sitkBSpline)
padDistance = kwargs.get('padDistance', 5)
label = kwargs.get('label', 1)
label = int(kwargs.get('label', 1))

logger.debug('Resampling image and mask')

Expand Down

0 comments on commit efb9756

Please sign in to comment.