示例#1
0
    def display(self, workspace, figure):
        '''Show an informative display'''
        import matplotlib
        import cellprofiler.gui.figure

        figure.set_subplots((2, 1))
        assert isinstance(figure, cellprofiler.gui.figure.Figure)

        i = workspace.display_data.i
        j = workspace.display_data.j
        angles = workspace.display_data.angle
        mask = workspace.display_data.mask
        labels = workspace.display_data.labels
        count = workspace.display_data.count

        color_image = np.zeros((mask.shape[0], mask.shape[1], 4))
        #
        # We do the coloring using alpha values to let the different
        # things we draw meld together.
        #
        # The binary mask is white.
        #
        color_image[mask, :] = MASK_ALPHA
        if count > 0:
            mappable = matplotlib.cm.ScalarMappable(
                cmap=matplotlib.cm.get_cmap(cpprefs.get_default_colormap()))
            np.random.seed(0)
            colors = mappable.to_rgba(np.random.permutation(np.arange(count)))

            #
            # The labels
            #
            color_image[labels > 0, :] += colors[labels[labels > 0] -
                                                 1, :] * LABEL_ALPHA
            #
            # Do each diamond individually (because the angles are almost certainly
            # different for each
            #
            lcolors = colors * .5 + .5  # Wash the colors out a little
            for ii in range(count):
                diamond = self.get_diamond(angles[ii])
                hshape = ((np.array(diamond.shape) - 1) / 2).astype(int)
                iii = i[ii]
                jjj = j[ii]
                color_image[iii - hshape[0]:iii + hshape[0] + 1,
                jjj - hshape[1]:jjj + hshape[1] + 1, :][diamond, :] += \
                    lcolors[ii, :] * WORM_ALPHA
        #
        # Do our own alpha-normalization
        #
        color_image[:, :, -1][color_image[:, :, -1] == 0] = 1
        color_image[:, :, :-1] = (color_image[:, :, :-1] /
                                  color_image[:, :, -1][:, :, np.newaxis])
        plot00 = figure.subplot_imshow_bw(0, 0, mask, self.image_name.value)
        figure.subplot_imshow_color(1,
                                    0,
                                    color_image[:, :, :-1],
                                    title=self.object_name.value,
                                    normalize=False,
                                    sharexy=plot00)
    def display(self, workspace, figure):
        '''Show an informative display'''
        import matplotlib
        import cellprofiler.gui.figure

        figure.set_subplots((2, 1))
        assert isinstance(figure, cellprofiler.gui.figure.Figure)

        i = workspace.display_data.i
        j = workspace.display_data.j
        angles = workspace.display_data.angle
        mask = workspace.display_data.mask
        labels = workspace.display_data.labels
        count = workspace.display_data.count

        color_image = np.zeros((mask.shape[0], mask.shape[1], 4))
        #
        # We do the coloring using alpha values to let the different
        # things we draw meld together.
        #
        # The binary mask is white.
        #
        color_image[mask, :] = MASK_ALPHA
        if count > 0:
            mappable = matplotlib.cm.ScalarMappable(
                    cmap=matplotlib.cm.get_cmap(cpprefs.get_default_colormap()))
            np.random.seed(0)
            colors = mappable.to_rgba(np.random.permutation(np.arange(count)))

            #
            # The labels
            #
            color_image[labels > 0, :] += colors[labels[labels > 0] - 1, :] * LABEL_ALPHA
            #
            # Do each diamond individually (because the angles are almost certainly
            # different for each
            #
            lcolors = colors * .5 + .5  # Wash the colors out a little
            for ii in range(count):
                diamond = self.get_diamond(angles[ii])
                hshape = ((np.array(diamond.shape) - 1) / 2).astype(int)
                iii = i[ii]
                jjj = j[ii]
                color_image[iii - hshape[0]:iii + hshape[0] + 1,
                jjj - hshape[1]:jjj + hshape[1] + 1, :][diamond, :] += \
                    lcolors[ii, :] * WORM_ALPHA
        #
        # Do our own alpha-normalization
        #
        color_image[:, :, -1][color_image[:, :, -1] == 0] = 1
        color_image[:, :, :-1] = (color_image[:, :, :-1] /
                                  color_image[:, :, -1][:, :, np.newaxis])
        plot00 = figure.subplot_imshow_bw(0, 0, mask, self.image_name.value)
        figure.subplot_imshow_color(1, 0, color_image[:, :, :-1],
                                    title=self.object_name.value,
                                    normalize=False,
                                    sharexy=plot00)