Commit 5273a89d authored by Andrea Bizzego's avatar Andrea Bizzego
Browse files

binMode added

parent 2bab8540
......@@ -69,9 +69,9 @@ class RadiomicsFeaturesBase(object):
# Although binCount is available, we advise use of binWidth!
# See documentation/FAQ/Input-Customization for more details.
self.binCount = kwargs.get('binCount', None)
#@@
self.binEdges = kwargs.get('binEdges', [-1, 0, 1])
#@@
#@@@
self.binMode = kwargs.get('binMode', 'uniform')
#@@@
self.label = kwargs.get('label', 1)
self.voxelBased = kwargs.get('voxelBased', False)
self.initValue = kwargs.get('initValue', 0)
......@@ -184,7 +184,7 @@ class RadiomicsFeaturesBase(object):
self.imageArray,
self.maskArray,
self.settings.get('binCount', None),
self.settings.get('binEdges', None))
self.settings.get('binMode', 'uniform'))
self.coefficients['grayLevels'] = numpy.unique(self.matrix[self.maskArray])
self.coefficients['Ng'] = int(numpy.max(self.coefficients['grayLevels'])) # max gray level in the ROI
......@@ -301,7 +301,7 @@ class RadiomicsFeaturesBase(object):
yield True, feature, getattr(self, 'get%sFeatureValue' % feature)()
except DeprecationWarning as deprecatedFeature:
# Add a debug log message, as a warning is usually shown and would entail a too verbose output
self.logger.debug('Feature %s is deprecated: %s', feature, deprecatedFeature.message)
self.logger.debug('Feature %s is deprecated: %s', feature, '')#deprecatedFeature.message) #@@@
except Exception:
self.logger.error('FAILED: %s', traceback.format_exc())
yield False, feature, numpy.nan
......@@ -368,10 +368,10 @@ class RadiomicsFeaturesExtractor:
self.logger.debug('Enabled features: %s', self._enabledFeatures)
self.logger.debug('Current settings: %s', self.settings)
if self.settings.get('binCount', None) is not None:
self.logger.warning('Fixed bin Count enabled! However, we recommend using a fixed bin Width. See '
'http://pyradiomics.readthedocs.io/en/latest/faq.html#radiomics-fixed-bin-width for more '
'details')
# if self.settings.get('binCount', None) is not None:
# self.logger.warning('Fixed bin Count enabled! However, we recommend using a fixed bin Width. See '
# 'http://pyradiomics.readthedocs.io/en/latest/faq.html#radiomics-fixed-bin-width for more '
# 'details')
# 1. Load the image and mask
featureVector = collections.OrderedDict()
......
......@@ -37,7 +37,7 @@ def getBinEdges(binwidth, parameterValues):
lowBound = min(parameterValues) - (min(parameterValues) % binwidth)
# Add + binwidth to ensure the maximum value is included in the range generated by numpu.arange
highBound = max(parameterValues) + binwidth
binEdges = numpy.arange(lowBound, highBound, binwidth)
# if min(parameterValues) % binWidth = 0 and min(parameterValues) = max(parameterValues), binEdges will only contain
......@@ -52,7 +52,7 @@ def getBinEdges(binwidth, parameterValues):
return binEdges # numpy.histogram(parameterValues, bins=binedges)
def binImage(binwidth, parameterMatrix, parameterMatrixCoordinates=None, bincount=None, binedges=None): #@@@ bincount=None):
def binImage(binwidth, parameterMatrix, parameterMatrixCoordinates=None, bincount=None, mode='uniform'): #@@@ bincount=None):
r"""
Discretizes the parameterMatrix (matrix representation of the gray levels in the ROI) using the binEdges calculated
using :py:func:`getBinEdges`. Only voxels defined by parameterMatrixCoordinates (defining the segmentation) are used
......@@ -85,17 +85,21 @@ def binImage(binwidth, parameterMatrix, parameterMatrixCoordinates=None, bincoun
if parameterMatrixCoordinates is None:
if bincount is not None:
binEdges = numpy.histogram(parameterMatrix[:], bincount)[1]
elif binedges is not None:
binEdges = binedges
if mode == 'uniform':
binEdges = numpy.histogram(parameterMatrix[:], bincount)[1]
elif mode == 'equal':
binEdges = numpy.percentile(parameterMatrix[:], numpy.arange(0, 1, 1/bincount))
binEdges = numpy.r_[binEdges, numpy.max(parameterMatrix[:])]
else:
binEdges = getBinEdges(binwidth, parameterMatrix[:])
parameterMatrix = numpy.digitize(parameterMatrix, binEdges)
else:
if bincount is not None:
binEdges = numpy.histogram(parameterMatrix[parameterMatrixCoordinates], bincount)[1]
elif binedges is not None:
binEdges = binedges
if mode == 'uniform':
binEdges = numpy.histogram(parameterMatrix[parameterMatrixCoordinates], bincount)[1]
elif mode == 'equal':
binEdges = numpy.percentile(parameterMatrix[parameterMatrixCoordinates], numpy.arange(0, 1, 1/bincount))
binEdges = numpy.r_[binEdges, numpy.max(parameterMatrix[:])]
else:
binEdges = getBinEdges(binwidth, parameterMatrix[parameterMatrixCoordinates])
parameterMatrix[parameterMatrixCoordinates] = numpy.digitize(parameterMatrix[parameterMatrixCoordinates], binEdges)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment