myfirstorder.py 2.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy
from scipy import ndimage

from radiomics.firstorder import RadiomicsFirstOrder
from .mybase import MyRadiomicsFeaturesBase


class MyRadiomicsFirstOrder(MyRadiomicsFeaturesBase):
    def __init__(self, inputImage, inputMask, **kwargs):
        super().__init__(inputImage, inputMask, **kwargs)

        self.pixelSpacing = inputImage.GetSpacing()
        self.voxelArrayShift = kwargs.get('voxelArrayShift', 0)

    def _initCalculation(self):
        return super()._initSegmentBasedCalculation()

        self.targetVoxelArray = self.imageArray[self.labelledVoxelCoordinates].astype(
            'float'
        )
        self.discretizedTargetVoxelArray = None  # Lazy instantiation

        self.logger.debug('First order feature class initialized')

    def _moment(self, a, moment=1, axis=0):
        return RadiomicsFirstOrder._moment(self, a, moment, axis)

    def _getDiscretizedTargetVoxelArray(self):
        return RadiomicsFirstOrder._getDiscretizedTargetVoxelArray(self)

    def getSuvMaxFeatureValue(self):
        r"""
        **20. SUV max**

        Implemented as one of the intensity features extracted by Vallieres et al.
        Maximum SUV of the tumour region. 

        - input: 3D array representing the PET volume in SUV format

        .. note::
        Extracted from PET scans and not used in the CT feature set.
        """
        ROIPet = self.imageArray
        mask = self.maskArray
        ROIPet[~mask] = numpy.nan

        return numpy.max(ROIPet[~numpy.isnan(ROIPet)])

    def getSuvMeanFeatureValue(self):
        r"""
        **21. SUV mean**

        Implemented as one of the intensity features extracted by valieres et al.
        Average SUV of the tumour region. 

        - input: 3D array representing the PET volume in SUV format

        .. note::
        Extracted from PET scans and not used in the CT feature set.
        """
        ROIPet = self.imageArray
        mask = self.maskArray
        ROIPet[~mask] = numpy.nan

        return numpy.mean(ROIPet[~numpy.isnan(ROIPet)])

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    def getTLGFeatureValue(self):
        r"""
        **21. TLG**

        Total lesion glycolysis. 
        Defined as 
        
        .. math::
        \textit{SUVMean}\times \textit{total volume of the tumour region}
    
        - input: 3D array representing the PET volume in SUV format, with 
                voxels outside the ROI set to NaNs.
    
        .. note::
        Extracted from PET scans and not used in the CT feature set.
        """
        z, y, x = self.pixelSpacing
        Np = len(self.labelledVoxelCoordinates[0])
        volume = Np * (z * x * y)

        ROIPet = self.imageArray
        mask = self.maskArray
        ROIPet[~mask] = numpy.nan

        return numpy.mean(ROIPet[~numpy.isnan(ROIPet)]) * volume