How to use the histomicstk.annotations_and_masks.masks_to_annotations_handler.get_contours_from_mask function in histomicstk

To help you get started, we’ve selected a few histomicstk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DigitalSlideArchive / HistomicsTK / histomicstk / annotations_and_masks / polygon_merger.py View on Github external
- self.ordinary_contours: dict: indexed by maskname, each entry
        is a contours dataframe
        - self.edge_contours: dict: indexed by maskname, each entry is
        a contours dataframe
        - self.merged_contours: pandas DataFrame: single dataframe to
        save all merged contours

        """
        ordinary_contours = dict()
        edge_contours = dict()

        for midx, maskpath in enumerate(self.maskpaths):

            # extract contours
            MASK = imread(maskpath)
            contours_df = get_contours_from_mask(
                MASK=MASK,
                monitorPrefix="%s: mask %d of %d" % (
                    monitorPrefix, midx, len(self.maskpaths)),
                **self.contkwargs)

            # separate edge from non-edge contours
            edgeids = []
            for edge in ['top', 'left', 'bottom', 'right']:
                edgeids.extend(list(contours_df.loc[contours_df.loc[
                    :, 'touches_edge-%s' % edge] == 1, :].index))
            edgeids = list(set(edgeids))
            roiname = os.path.split(maskpath)[1]
            edge_contours[roiname] = contours_df.loc[edgeids, :].copy()
            ordinary_contours[roiname] = contours_df.drop(edgeids, axis=0)

        self.ordinary_contours = ordinary_contours
github DigitalSlideArchive / HistomicsTK / histomicstk / saliency / cellularity_detection.py View on Github external
def visualize_individual_superpixels(self):
        """Visualize individual spixels, color-coded by cellularity."""
        # Define GTCodes dataframe
        GTCodes_df = DataFrame(columns=['group', 'GT_code', 'color'])
        for spval, sp in self.fdata.iterrows():
            spstr = 'spixel-%d_cellularity-%d' % (
                spval, self.cluster_props[sp['cluster']]['cellularity'])
            GTCodes_df.loc[spstr, 'group'] = spstr
            GTCodes_df.loc[spstr, 'GT_code'] = spval
            GTCodes_df.loc[spstr, 'color'] = \
                self.cluster_props[sp['cluster']]['color']

        # get contours df
        contours_df = get_contours_from_mask(
            MASK=self.spixel_mask, GTCodes_df=GTCodes_df,
            get_roi_contour=False, MIN_SIZE=0, MAX_SIZE=None,
            verbose=self.cd.verbose == 3, monitorPrefix=self.monitorPrefix)
        contours_df.loc[:, "group"] = [
            j.split('_')[-1] for j in contours_df.loc[:, "group"]]

        # get annotation docs
        annprops = {
            'F': (self.ymax - self.ymin) / self.tissue_rgb.shape[0],
            'X_OFFSET': self.xmin,
            'Y_OFFSET': self.ymin,
            'opacity': self.cd.opacity,
            'lineWidth': self.cd.lineWidth,
        }
        annotation_docs = get_annotation_documents_from_contours(
            contours_df.copy(), docnamePrefix='spixel', annprops=annprops,
github DigitalSlideArchive / HistomicsTK / histomicstk / saliency / cellularity_detection_thresholding.py View on Github external
def visualize_results(self):
        """Visualize results in DSA."""
        # get contours
        contours_df = get_contours_from_mask(
            MASK=self.labeled, GTCodes_df=self.cdt.GTcodes.copy(),
            groups_to_get=self.cdt.groups_to_visualize,
            get_roi_contour=self.cdt.get_roi_contour, roi_group='roi',
            background_group='not_specified',
            discard_nonenclosed_background=True,
            MIN_SIZE=15, MAX_SIZE=None,
            verbose=self.cdt.verbose == 3,
            monitorPrefix=self.monitorPrefix + ": -- contours")

        # get annotation docs
        annprops = {
            'F': self.cdt.slide_info['magnification'] / self.cdt.MAG,
            'X_OFFSET': self.xmin,
            'Y_OFFSET': self.ymin,
            'opacity': self.cdt.opacity,
            'lineWidth': self.cdt.lineWidth,
github DigitalSlideArchive / HistomicsTK / histomicstk / saliency / cellularity_detection.py View on Github external
"""Visualize contiguous spixels, color-coded by cellularity."""
        # get cellularity cluster membership mask
        cellularity_mask = np.zeros(self.spixel_mask.shape)
        for spval, sp in self.fdata.iterrows():
            cellularity_mask[self.spixel_mask == spval] = sp['cluster']

        # Define GTCodes dataframe
        GTCodes_df = DataFrame(columns=['group', 'GT_code', 'color'])
        for spval, cp in self.cluster_props.items():
            spstr = 'cellularity-%d' % (cp['cellularity'])
            GTCodes_df.loc[spstr, 'group'] = spstr
            GTCodes_df.loc[spstr, 'GT_code'] = spval
            GTCodes_df.loc[spstr, 'color'] = cp['color']

        # get contours df
        contours_df = get_contours_from_mask(
            MASK=cellularity_mask, GTCodes_df=GTCodes_df,
            get_roi_contour=False, MIN_SIZE=0, MAX_SIZE=None,
            verbose=self.cd.verbose == 3, monitorPrefix=self.monitorPrefix)

        # get annotation docs
        annprops = {
            'F': (self.ymax - self.ymin) / self.tissue_rgb.shape[0],
            'X_OFFSET': self.xmin,
            'Y_OFFSET': self.ymin,
            'opacity': self.cd.opacity_contig,
            'lineWidth': self.cd.lineWidth,
        }
        annotation_docs = get_annotation_documents_from_contours(
            contours_df.copy(), docnamePrefix='contig', annprops=annprops,
            annots_per_doc=1000, separate_docs_by_group=True,
            verbose=self.cd.verbose == 3, monitorPrefix=self.monitorPrefix)
github DigitalSlideArchive / HistomicsTK / histomicstk / saliency / tissue_detection.py View on Github external
annprops = {
            'F': slide_info['sizeX'] / labeled.shape[1],  # relative to base
            'X_OFFSET': 0,
            'Y_OFFSET': 0,
            'opacity': 0,
            'lineWidth': 4.0,
        }

    # Define GTCodes dataframe
    GTCodes_df = DataFrame(columns=['group', 'GT_code', 'color'])
    GTCodes_df.loc['tissue', 'group'] = group
    GTCodes_df.loc['tissue', 'GT_code'] = 1
    GTCodes_df.loc['tissue', 'color'] = color

    # get annotation docs
    contours_tissue = get_contours_from_mask(
        MASK=0 + (labeled > 0), GTCodes_df=GTCodes_df,
        get_roi_contour=False, MIN_SIZE=0, MAX_SIZE=None, verbose=False,
        monitorPrefix="tissue: getting contours")
    annotation_docs = get_annotation_documents_from_contours(
        contours_tissue.copy(), docnamePrefix='test', annprops=annprops,
        verbose=False, monitorPrefix="tissue : annotation docs")

    return annotation_docs