Esempio n. 1
0
    def get_chest_regions(self):
        """Get the explicit list of chest regions in the data set.

        Returns
        -------
        chest_regions : array, shape ( N )
            Explicit list of the N chest regions in the data set
        """
        conventions = ChestConventions()

        tmp = []
        for l in self.labels_:
            tmp.append(conventions.GetChestRegionFromValue(l))

        chest_regions = np.unique(np.array(tmp, dtype=int))
        return chest_regions
Esempio n. 2
0
    def get_all_chest_regions(self):
        """Get all the chest regions in the data set, including those
        implicitly present as a result of the region hierarchy.

        Returns
        -------
        chest_regions : array, shape ( N )
            All chest regions in the data set
        """
        c = ChestConventions()
        num_regions = c.GetNumberOfEnumeratedChestRegions()

        tmp = []
        for l in self.labels_:
            r = c.GetChestRegionFromValue(l)

            for sup in xrange(0, num_regions):
                if c.CheckSubordinateSuperiorChestRegionRelationship(r, sup):
                    tmp.append(sup)

        chest_regions = np.unique(np.array(tmp, dtype=int))
        return chest_regions
Esempio n. 3
0
    def get_all_pairs(self):
        """Get all the region-type pairs, including implied pairs

        Returns
        -------
        pairs : array, shape ( N, 2 )
            All N chest-region chest-type pairs in the data set, including
            those implied by the region hierarchy. The first column indicates
            the chest region, and the second column represents the chest type.
        """
        c = ChestConventions()
        num_regions = c.GetNumberOfEnumeratedChestRegions()

        tmp = []
        for l in self.labels_:
            t = c.GetChestTypeFromValue(l)
            r = c.GetChestRegionFromValue(l)
            for sup in xrange(0, num_regions):
                if c.CheckSubordinateSuperiorChestRegionRelationship(r, sup):
                    if not (sup, t) in tmp:
                        tmp.append((sup, t))

        pairs = np.array(tmp, dtype=int)
        return pairs
Esempio n. 4
0
    def get_mask(self, chest_region=None, chest_type=None):
        """Get's boolean mask of all data indices that match the chest-region
        chest-type query.

        If only a chest region is specified, then all voxels in that region
        will be included in the mask, regardless of the voxel's chest type
        value (chest region hierarchy is honored). If only a type is specified,
        then all voxels having that type will be included in the mask,
        regardless of the voxel's chest region. If both a region and type are
        speficied, then only those voxels matching both the region and type
        will be included in the mask (the chest region hierarchy is honored).

        Parameters
        ----------
        chest_region : int
            Integer value in the interval [0, 255] that indicates the chest
            region

        chest_type : int
            Integer value in the interval [0, 255] that indicates the chest
            type

        Returns
        -------
        mask : array, shape ( X, Y, Z )
            Boolean mask of all data indices that match the chest-region
            chest-type query. The chest region hierarchy is honored.
        """
        if chest_region is not None:
            if type(chest_region) != int and type(chest_region) != np.int64:
                raise ValueError(
                    'chest_region must be an int between 0 and 255 inclusive')
        if chest_type is not None:
            if type(chest_type) != int and type(chest_type) != np.int64:
                raise ValueError(
                    'chest_type must be an int between 0 and 255 inclusive')

        conventions = ChestConventions()

        mask_labels = []
        for l in self.labels_:
            r = conventions.GetChestRegionFromValue(l)
            t = conventions.GetChestTypeFromValue(l)

            if chest_region is not None and chest_type is not None:
                if t==chest_type and \
                  conventions.CheckSubordinateSuperiorChestRegionRelationship(\
                  r, chest_region):
                    mask_labels.append(l)
            elif t == chest_type:
                mask_labels.append(l)
            elif chest_region is not None:
                if conventions.\
                    CheckSubordinateSuperiorChestRegionRelationship(r, \
                    chest_region):
                    mask_labels.append(l)

        mask = np.empty(self._data.shape, dtype=bool)
        mask[:] = False

        for ml in mask_labels:
            mask = np.logical_or(mask, self._data == ml)

        return mask