Exemple #1
0
    def _calculateMatrix(self):
        P_gldm, angles = cMatrices.calculate_gldm(
            self.matrix, self.maskArray,
            numpy.array(self.settings.get('distances', [1])),
            self.coefficients['Ng'], self.gldm_a,
            self.settings.get('force2D', False),
            self.settings.get('force2Ddimension', 0))

        jvector = numpy.arange(1, P_gldm.shape[1] + 1, dtype='float64')

        # Delete rows and columns that specify gray levels not present in the ROI
        pd = numpy.sum(P_gldm, 0)
        pg = numpy.sum(P_gldm, 1)

        P_gldm = numpy.delete(P_gldm, numpy.where(pg == 0), 0)
        P_gldm = numpy.delete(P_gldm, numpy.where(pd == 0), 1)

        jvector = numpy.delete(jvector, numpy.where(pd == 0))

        pg = numpy.delete(pg, numpy.where(pg == 0))
        pd = numpy.delete(pd, numpy.where(pd == 0))

        self.coefficients['pd'] = pd
        self.coefficients['pg'] = pg

        self.coefficients['ivector'] = self.coefficients['grayLevels']
        self.coefficients['jvector'] = jvector

        return P_gldm
    def _calculateCMatrix(self):
        angles = imageoperations.generateAngles(self.boundingBoxSize,
                                                **self.kwargs)
        Ng = self.coefficients['Ng']

        P_gldm = cMatrices.calculate_gldm(self.matrix, self.maskArray, angles,
                                          Ng, self.gldm_a)

        jvector = numpy.arange(1, P_gldm.shape[1] + 1, dtype='float64')

        # Delete rows and columns that specify gray levels not present in the ROI
        sumP_gldm = numpy.sum(P_gldm)
        pd = numpy.sum(P_gldm, 0)
        pg = numpy.sum(P_gldm, 1)

        P_gldm = numpy.delete(P_gldm, numpy.where(pg == 0), 0)
        P_gldm = numpy.delete(P_gldm, numpy.where(pd == 0), 1)

        jvector = numpy.delete(jvector, numpy.where(pd == 0))

        pg = numpy.delete(pg, numpy.where(pg == 0))
        pd = numpy.delete(pd, numpy.where(pd == 0))

        self.coefficients['sumP_gldm'] = sumP_gldm
        self.coefficients['pd'] = pd
        self.coefficients['pg'] = pg

        self.coefficients['ivector'] = self.coefficients['grayLevels']
        self.coefficients['jvector'] = jvector

        return P_gldm
Exemple #3
0
    def _calculateMatrix(self, voxelCoordinates=None):
        self.logger.debug('Calculating GLDM matrix in C')

        Ng = self.coefficients['Ng']

        matrix_args = [
            self.imageArray, self.maskArray,
            numpy.array(self.settings.get('distances', [1])), Ng, self.gldm_a,
            self.settings.get('force2D', False),
            self.settings.get('force2Ddimension', 0)
        ]
        if self.voxelBased:
            matrix_args += [
                self.settings.get('kernelRadius', 1), voxelCoordinates
            ]

        P_gldm = cMatrices.calculate_gldm(*matrix_args)  # shape (Nv, Ng, Nd)

        # Delete rows that specify gray levels not present in the ROI
        NgVector = range(1, Ng + 1)  # All possible gray values
        GrayLevels = self.coefficients[
            'grayLevels']  # Gray values present in ROI
        emptyGrayLevels = numpy.array(
            list(set(NgVector) - set(GrayLevels)),
            dtype=int)  # Gray values NOT present in ROI

        if list(emptyGrayLevels):
            P_gldm = numpy.delete(P_gldm, emptyGrayLevels - 1, 1)

        jvector = numpy.arange(1, P_gldm.shape[2] + 1, dtype='float64')

        # shape (Nv, Nd)
        pd = numpy.sum(P_gldm, 1)
        # shape (Nv, Ng)
        pg = numpy.sum(P_gldm, 2)

        # Delete columns that dependence sizes not present in the ROI
        empty_sizes = numpy.sum(pd, 0)
        P_gldm = numpy.delete(P_gldm, numpy.where(empty_sizes == 0), 2)
        jvector = numpy.delete(jvector, numpy.where(empty_sizes == 0))
        pd = numpy.delete(pd, numpy.where(empty_sizes == 0), 1)

        Nz = numpy.sum(pd, 1)  # Nz per kernel, shape (Nv, )
        Nz[Nz == 0] = 1  # set sum to numpy.spacing(1) if sum is 0?

        self.coefficients['Nz'] = Nz

        self.coefficients['pd'] = pd
        self.coefficients['pg'] = pg

        self.coefficients['ivector'] = self.coefficients['grayLevels'].astype(
            float)
        self.coefficients['jvector'] = jvector

        return P_gldm
Exemple #4
0
    def _calculateMatrix(self):
        self.logger.debug('Calculating GLDM matrix in C')

        Ng = self.coefficients['Ng']
        P_gldm = cMatrices.calculate_gldm(
            self.matrix, self.maskArray,
            numpy.array(self.settings.get('distances', [1])), Ng, self.gldm_a,
            self.settings.get('force2D', False),
            self.settings.get('force2Ddimension', 0))

        # Delete rows that specify gray levels not present in the ROI
        NgVector = range(1, Ng + 1)  # All possible gray values
        GrayLevels = self.coefficients[
            'grayLevels']  # Gray values present in ROI
        emptyGrayLevels = numpy.array(
            list(set(NgVector) -
                 set(GrayLevels)))  # Gray values NOT present in ROI

        P_gldm = numpy.delete(P_gldm, emptyGrayLevels - 1, 0)

        jvector = numpy.arange(1, P_gldm.shape[1] + 1, dtype='float64')

        pd = numpy.sum(P_gldm, 0)
        pg = numpy.sum(P_gldm, 1)

        # Delete columns that dependence sizes not present in the ROI
        P_gldm = numpy.delete(P_gldm, numpy.where(pd == 0), 1)
        jvector = numpy.delete(jvector, numpy.where(pd == 0))
        pd = numpy.delete(pd, numpy.where(pd == 0))

        self.coefficients['pd'] = pd
        self.coefficients['pg'] = pg

        self.coefficients['ivector'] = self.coefficients['grayLevels']
        self.coefficients['jvector'] = jvector

        return P_gldm