### Fix Contrast feature

parent bd126a71
 from .mybase import MyRadiomicsFeaturesBase import numpy from radiomics.ngtdm import RadiomicsNGTDM from .mybase import MyRadiomicsFeaturesBase class MyRadiomicsNGTDM(RadiomicsNGTDM, MyRadiomicsFeaturesBase): def __init__(self, inputImage, inputMask, **kwargs): super().__init__(inputImage, inputMask, **kwargs) def getContrastFeatureValue(self): r""" Calculate and return the contrast. :math:Contrast = \left(\frac{1}{N_{g,p}(N_{g,p}-1)}\displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{p_{i}p_{j}(i-j)^2}\right) \left(\frac{1}{N_{v,p}}\displaystyle\sum^{N_g}_{i=1}{s_i}\right)\text{, where }p_i \neq 0, p_j \neq 0 Contrast is a measure of the spatial intensity change, but is also dependent on the overall gray level dynamic range. Contrast is high when both the dynamic range and the spatial change rate are high, i.e. an image with a large range of gray levels, with large changes between voxels and their neighbourhood. N.B. In case of a completely homogeneous image, :math:N_{g,p} = 1, which would result in a division by 0. In this case, an arbitray value of 0 is returned. """ Ngp = self.coefficients['Ngp'] Nvp = self.coefficients['Nvp'] p_i = self.coefficients['p_i'] s_i = self.coefficients['s_i'] i = self.coefficients['ivector'] div = Ngp * (Ngp - 1) if div != 0: contrast = ( numpy.sum(p_i[:, None] * p_i[None, :] * (i[:, None] - i[None, :]) ** 2) / div ) * ((numpy.sum(s_i)) / Nvp) else: contrast = 0 return contrast
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!