Example #1
0
 def display(self, workspace):
     from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
     figure = workspace.create_or_find_figure(subplots=(2,2))
     renumbered_parent_labels = renumber_labels_for_display(
         workspace.display_data.parent_labels)
     child_labels = workspace.display_data.child_labels
     parents_of = workspace.display_data.parents_of
     #
     # discover the mapping so that we can apply it to the children
     #
     mapping = np.arange(workspace.display_data.parent_count+1)
     mapping[workspace.display_data.parent_labels.flatten()] = \
         renumbered_parent_labels.flatten()
     parent_labeled_children = np.zeros(child_labels.shape, int)
     mask = child_labels > 0
     parent_labeled_children[mask] = \
         mapping[parents_of[child_labels[mask] - 1]]
     
     figure.subplot_imshow_labels(
         0, 0, renumbered_parent_labels,
         title = self.parent_name.value,
         renumber=False)
     figure.subplot_imshow_labels(
         1, 0, child_labels,
         title = self.sub_object_name.value,
         sharex = figure.subplot(0,0),
         sharey = figure.subplot(0,0))
     figure.subplot_imshow_labels(
         0, 1, parent_labeled_children,
         "%s labeled by %s"%
         (self.sub_object_name.value,
          self.parent_name.value),
         renumber=False,
         sharex = figure.subplot(0,0),
         sharey = figure.subplot(0,0))
    def display(self, workspace, figure):
        '''Create an informative display for the module'''
        import matplotlib
        from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
        original_labels = workspace.display_data.original_labels
        final_labels = workspace.display_data.final_labels
        mask = workspace.display_data.mask
        #
        # Create a composition of the final labels and mask
        #
        final_labels = renumber_labels_for_display(final_labels)
        outlines = outline(original_labels) > 0

        cm = matplotlib.cm.get_cmap(cpprefs.get_default_colormap())
        sm = matplotlib.cm.ScalarMappable(cmap=cm)
        #
        # Paint the labels in color
        #
        image = sm.to_rgba(final_labels)[:, :, :3]
        image[final_labels == 0, :] = 0
        #
        # Make the mask a dark gray
        #
        image[(final_labels == 0) & mask, :] = .25
        #
        # Make the outlines of the kept objects the primary color
        # and the outlines of removed objects red.
        #
        final_outlines = outline(final_labels) > 0
        original_color = np.array(cpprefs.get_secondary_outline_color(),
                                  float) / 255
        final_color = np.array(cpprefs.get_primary_outline_color(),
                               float) / 255
        image[outlines, :] = original_color[np.newaxis, :]
        image[final_outlines, :] = final_color[np.newaxis, :]

        figure.set_subplots((2, 1))
        figure.subplot_imshow_labels(0,
                                     0,
                                     original_labels,
                                     title=self.object_name.value)
        figure.subplot_imshow_color(1,
                                    0,
                                    image,
                                    title=self.remaining_objects.value,
                                    sharexy=figure.subplot(0, 0))
Example #3
0
    def display(self, workspace, figure):
        if not self.show_window:
            return
        from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
        figure.set_subplots((2, 2))
        renumbered_parent_labels = renumber_labels_for_display(
            workspace.display_data.parent_labels)
        child_labels = workspace.display_data.child_labels
        parents_of = workspace.display_data.parents_of
        #
        # discover the mapping so that we can apply it to the children
        #
        mapping = np.arange(workspace.display_data.parent_count + 1)
        mapping[workspace.display_data.parent_labels.flatten()] = \
            renumbered_parent_labels.flatten()
        parent_labeled_children = np.zeros(child_labels.shape, int)
        mask = child_labels > 0
        parent_labeled_children[mask] = \
            mapping[parents_of[child_labels[mask] - 1]]

        figure.subplot_imshow_labels(0,
                                     0,
                                     renumbered_parent_labels,
                                     title=self.parent_name.value,
                                     renumber=False)
        figure.subplot_imshow_labels(1,
                                     0,
                                     child_labels,
                                     title=self.sub_object_name.value,
                                     sharex=figure.subplot(0, 0),
                                     sharey=figure.subplot(0, 0))
        figure.subplot_imshow_labels(
            0,
            1,
            parent_labeled_children,
            "%s labeled by %s" %
            (self.sub_object_name.value, self.parent_name.value),
            renumber=False,
            sharex=figure.subplot(0, 0),
            sharey=figure.subplot(0, 0))
Example #4
0
    def display(self, workspace, figure):
        '''Create an informative display for the module'''
        import matplotlib
        from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
        original_labels = workspace.display_data.original_labels
        final_labels = workspace.display_data.final_labels
        mask = workspace.display_data.mask
        #
        # Create a composition of the final labels and mask
        #
        final_labels = renumber_labels_for_display(final_labels)
        outlines = outline(original_labels) > 0

        cm = matplotlib.cm.get_cmap(cpprefs.get_default_colormap())
        sm = matplotlib.cm.ScalarMappable(cmap=cm)
        #
        # Paint the labels in color
        #
        image = sm.to_rgba(final_labels)[:, :, :3]
        image[final_labels == 0, :] = 0
        #
        # Make the mask a dark gray
        #
        image[(final_labels == 0) & mask, :] = .25
        #
        # Make the outlines of the kept objects the primary color
        # and the outlines of removed objects red.
        #
        final_outlines = outline(final_labels) > 0
        original_color = np.array(cpprefs.get_secondary_outline_color(), float) / 255
        final_color = np.array(cpprefs.get_primary_outline_color(), float) / 255
        image[outlines, :] = original_color[np.newaxis, :]
        image[final_outlines, :] = final_color[np.newaxis, :]

        figure.set_subplots((2, 1))
        figure.subplot_imshow_labels(0, 0, original_labels,
                                     title=self.object_name.value)
        figure.subplot_imshow_color(1, 0, image,
                                    title=self.remaining_objects.value,
                                    sharexy=figure.subplot(0, 0))
Example #5
0
    def overlay(self):
        '''Return a color image of the segmentation as an overlay
        '''
        if self.__overlay is not None:
            return self.__overlay
        sm = matplotlib.cm.ScalarMappable(cmap = self.colormap)
        sm.set_clim(vmin=1, vmax=np.max([np.max(l) for l in self.labels])+1)

        img = None
        lmin = 0
        for l in self.labels:
            if self.scramble:
                lmin = np.min(l[l!=0])
            l[l!=0] = renumber_labels_for_display(l)[l!=0]+lmin
            lmin = np.max(l)
            if img is None:
                img = sm.to_rgba(l)
                img[l==0, :] = 0
            else:
                img[l!=0, :] = sm.to_rgba(l[l!=0])
        self.__overlay = img
        return img
Example #6
0
    def overlay(self):
        '''Return a color image of the segmentation as an overlay
        '''
        if self.__overlay is not None:
            return self.__overlay
        sm = matplotlib.cm.ScalarMappable(cmap=self.colormap)
        sm.set_clim(vmin=1, vmax=np.max([np.max(l) for l in self.labels]) + 1)

        img = None
        lmin = 0
        for l in self.labels:
            if self.scramble:
                lmin = np.min(l[l != 0])
            l[l != 0] = renumber_labels_for_display(l)[l != 0] + lmin
            lmin = np.max(l)
            if img is None:
                img = sm.to_rgba(l)
                img[l == 0, :] = 0
            else:
                img[l != 0, :] = sm.to_rgba(l[l != 0])
        self.__overlay = img
        return img
    def draw_outlines(self, pixel_data, labels):
        '''Draw a color image that shows the objects

        pixel_data - image, either b & w or color
        labels - labels for image

        returns - color image of same size as pixel_data
        '''
        from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
        import matplotlib

        labels = renumber_labels_for_display(labels)
        outlines = outline(labels)

        if pixel_data.ndim == 3:
            image = pixel_data.copy()
        else:
            image = np.dstack([pixel_data] * 3)
        #
        # make labeled pixels a grayscale times the label color
        #
        cm = matplotlib.cm.get_cmap(cpprefs.get_default_colormap())
        sm = matplotlib.cm.ScalarMappable(cmap=cm)
        labels_image = sm.to_rgba(labels)[:, :, :3]

        lmask = labels > 0
        gray = (image[lmask, 0] + image[lmask, 1] + image[lmask, 2]) / 3

        for i in range(3):
            image[lmask, i] = gray * labels_image[lmask, i]
        #
        # Make the outline pixels a solid color
        #
        outlines_image = sm.to_rgba(outlines)[:, :, :3]
        image[outlines > 0, :] = outlines_image[outlines > 0, :]
        return image
    def draw_outlines(self, pixel_data, labels):
        '''Draw a color image that shows the objects

        pixel_data - image, either b & w or color
        labels - labels for image

        returns - color image of same size as pixel_data
        '''
        from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
        import matplotlib

        labels = renumber_labels_for_display(labels)
        outlines = outline(labels)

        if pixel_data.ndim == 3:
            image = pixel_data.copy()
        else:
            image = np.dstack([pixel_data] * 3)
        #
        # make labeled pixels a grayscale times the label color
        #
        cm = matplotlib.cm.get_cmap(cpprefs.get_default_colormap())
        sm = matplotlib.cm.ScalarMappable(cmap=cm)
        labels_image = sm.to_rgba(labels)[:, :, :3]

        lmask = labels > 0
        gray = (image[lmask, 0] + image[lmask, 1] + image[lmask, 2]) / 3

        for i in range(3):
            image[lmask, i] = gray * labels_image[lmask, i]
        #
        # Make the outline pixels a solid color
        #
        outlines_image = sm.to_rgba(outlines)[:, :, :3]
        image[outlines > 0, :] = outlines_image[outlines > 0, :]
        return image
 def run(self, workspace):
     objects = workspace.object_set.get_objects(self.object_name.value)
     alpha = np.zeros(objects.shape)
     if self.image_mode == IM_BINARY:
         pixel_data = np.zeros(objects.shape, bool)
     elif self.image_mode == IM_GRAYSCALE:
         pixel_data = np.zeros(objects.shape)
     elif self.image_mode == IM_UINT16:
         pixel_data = np.zeros(objects.shape, np.int32)
     else:
         pixel_data = np.zeros((objects.shape[0], objects.shape[1], 3))
     convert = True
     for labels, indices in objects.get_labels():
         mask = labels != 0
         if np.all(~ mask):
             continue
         if self.image_mode == IM_BINARY:
             pixel_data[mask] = True
             alpha[mask] = 1
         elif self.image_mode == IM_GRAYSCALE:
             pixel_data[mask] = labels[mask].astype(float) / np.max(labels)
             alpha[mask] = 1
         elif self.image_mode == IM_COLOR:
             import matplotlib.cm
             from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
             if self.colormap.value == DEFAULT_COLORMAP:
                 cm_name = cpprefs.get_default_colormap()
             elif self.colormap.value == COLORCUBE:
                 # Colorcube missing from matplotlib
                 cm_name = "gist_rainbow"
             elif self.colormap.value == LINES:
                 # Lines missing from matplotlib and not much like it,
                 # Pretty boring palette anyway, hence
                 cm_name = "Pastel1"
             elif self.colormap.value == WHITE:
                 # White missing from matplotlib, it's just a colormap
                 # of all completely white... not even different kinds of
                 # white. And, isn't white just a uniform sampling of
                 # frequencies from the spectrum?
                 cm_name = "Spectral"
             else:
                 cm_name = self.colormap.value
             cm = matplotlib.cm.get_cmap(cm_name)
             mapper = matplotlib.cm.ScalarMappable(cmap=cm)
             pixel_data[mask, :] += \
                 mapper.to_rgba(renumber_labels_for_display(labels))[mask, :3]
             alpha[mask] += 1
         elif self.image_mode == IM_UINT16:
             pixel_data[mask] = labels[mask]
             alpha[mask] = 1
             convert = False
     mask = alpha > 0
     if self.image_mode == IM_BINARY:
         pass
     elif self.image_mode == IM_COLOR:
         pixel_data[mask, :] = pixel_data[mask, :] / alpha[mask][:, np.newaxis]
     else:
         pixel_data[mask] = pixel_data[mask] / alpha[mask]
     image = cpi.Image(pixel_data, parent_image = objects.parent_image,
                       convert = convert)
     workspace.image_set.add(self.image_name.value, image)
     if self.show_window:
         workspace.display_data.ijv = objects.ijv
         workspace.display_data.pixel_data = pixel_data
Example #10
0
 def run(self, workspace):
     objects = workspace.object_set.get_objects(self.object_name.value)
     alpha = np.zeros(objects.shape)
     if self.image_mode == IM_BINARY:
         pixel_data = np.zeros(objects.shape, bool)
     elif self.image_mode == IM_GRAYSCALE:
         pixel_data = np.zeros(objects.shape)
     elif self.image_mode == IM_UINT16:
         pixel_data = np.zeros(objects.shape, np.int32)
     else:
         pixel_data = np.zeros((objects.shape[0], objects.shape[1], 3))
     convert = True
     for labels, indices in objects.get_labels():
         mask = labels != 0
         if np.all(~mask):
             continue
         if self.image_mode == IM_BINARY:
             pixel_data[mask] = True
             alpha[mask] = 1
         elif self.image_mode == IM_GRAYSCALE:
             pixel_data[mask] = labels[mask].astype(float) / np.max(labels)
             alpha[mask] = 1
         elif self.image_mode == IM_COLOR:
             import matplotlib.cm
             from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
             if self.colormap.value == DEFAULT_COLORMAP:
                 cm_name = cpprefs.get_default_colormap()
             elif self.colormap.value == COLORCUBE:
                 # Colorcube missing from matplotlib
                 cm_name = "gist_rainbow"
             elif self.colormap.value == LINES:
                 # Lines missing from matplotlib and not much like it,
                 # Pretty boring palette anyway, hence
                 cm_name = "Pastel1"
             elif self.colormap.value == WHITE:
                 # White missing from matplotlib, it's just a colormap
                 # of all completely white... not even different kinds of
                 # white. And, isn't white just a uniform sampling of
                 # frequencies from the spectrum?
                 cm_name = "Spectral"
             else:
                 cm_name = self.colormap.value
             cm = matplotlib.cm.get_cmap(cm_name)
             mapper = matplotlib.cm.ScalarMappable(cmap=cm)
             pixel_data[mask, :] += \
                 mapper.to_rgba(renumber_labels_for_display(labels))[mask, :3]
             alpha[mask] += 1
         elif self.image_mode == IM_UINT16:
             pixel_data[mask] = labels[mask]
             alpha[mask] = 1
             convert = False
     mask = alpha > 0
     if self.image_mode == IM_BINARY:
         pass
     elif self.image_mode == IM_COLOR:
         pixel_data[mask, :] = pixel_data[mask, :] / alpha[mask][:,
                                                                 np.newaxis]
     else:
         pixel_data[mask] = pixel_data[mask] / alpha[mask]
     image = cpi.Image(pixel_data,
                       parent_image=objects.parent_image,
                       convert=convert)
     workspace.image_set.add(self.image_name.value, image)
     if self.show_window:
         workspace.display_data.ijv = objects.ijv
         workspace.display_data.pixel_data = pixel_data
Example #11
0
 def run(self, workspace):
     objects = workspace.object_set.get_objects(self.object_name.value)
     labels = objects.segmented
     convert = True
     if not workspace.frame is None:
         figure = workspace.create_or_find_figure(
             title="ConvertObjectsToImage, image cycle #%d" %
             (workspace.measurements.image_set_number),
             subplots=(2, 1))
         figure.subplot_imshow_labels(
             0, 0, labels, "Original: %s" % self.object_name.value)
     if self.image_mode == IM_BINARY:
         pixel_data = labels != 0
         if not workspace.frame is None:
             figure.subplot_imshow_bw(1,
                                      0,
                                      pixel_data,
                                      self.image_name.value,
                                      sharex=figure.subplot(0, 0),
                                      sharey=figure.subplot(0, 0))
     elif self.image_mode == IM_GRAYSCALE:
         pixel_data = labels.astype(float) / (1.0 if np.max(labels) == 0
                                              else np.max(labels))
         if not workspace.frame is None:
             figure.subplot_imshow_grayscale(1,
                                             0,
                                             pixel_data,
                                             self.image_name.value,
                                             sharex=figure.subplot(0, 0),
                                             sharey=figure.subplot(0, 0))
     elif self.image_mode == IM_COLOR:
         import matplotlib.cm
         from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
         if self.colormap.value == DEFAULT_COLORMAP:
             cm_name = cpprefs.get_default_colormap()
         elif self.colormap.value == COLORCUBE:
             # Colorcube missing from matplotlib
             cm_name = "gist_rainbow"
         elif self.colormap.value == LINES:
             # Lines missing from matplotlib and not much like it,
             # Pretty boring palette anyway, hence
             cm_name = "Pastel1"
         elif self.colormap.value == WHITE:
             # White missing from matplotlib, it's just a colormap
             # of all completely white... not even different kinds of
             # white. And, isn't white just a uniform sampling of
             # frequencies from the spectrum?
             cm_name = "Spectral"
         else:
             cm_name = self.colormap.value
         cm = matplotlib.cm.get_cmap(cm_name)
         mapper = matplotlib.cm.ScalarMappable(cmap=cm)
         pixel_data = mapper.to_rgba(renumber_labels_for_display(labels))
         pixel_data = pixel_data[:, :, :3]
         pixel_data[labels == 0, :] = 0
         if not workspace.frame is None:
             figure.subplot_imshow(1,
                                   0,
                                   pixel_data,
                                   self.image_name.value,
                                   sharex=figure.subplot(0, 0),
                                   sharey=figure.subplot(0, 0))
     elif self.image_mode == IM_UINT16:
         pixel_data = labels.copy()
         if not workspace.frame is None:
             figure.subplot_imshow_grayscale(1,
                                             0,
                                             pixel_data,
                                             self.image_name.value,
                                             sharex=figure.subplot(0, 0),
                                             sharey=figure.subplot(0, 0))
         convert = False
     image = cpi.Image(pixel_data,
                       parent_image=objects.parent_image,
                       convert=convert)
     workspace.image_set.add(self.image_name.value, image)
 def run(self, workspace):
     objects = workspace.object_set.get_objects(self.object_name.value)
     labels = objects.segmented
     convert = True
     if not workspace.frame is None:
         figure = workspace.create_or_find_figure(title="ConvertObjectsToImage, image cycle #%d"%(
             workspace.measurements.image_set_number),subplots=(2,1))
         figure.subplot_imshow_labels(0,0,labels,
                                      "Original: %s"%self.object_name.value)
     if self.image_mode == IM_BINARY:
         pixel_data = labels != 0
         if not workspace.frame is None:
             figure.subplot_imshow_bw(1,0,pixel_data,self.image_name.value,
                                      sharex=figure.subplot(0,0),
                                      sharey=figure.subplot(0,0))
     elif self.image_mode == IM_GRAYSCALE:
         pixel_data = labels.astype(float) / (1.0 if np.max(labels) == 0 else np.max(labels))
         if not workspace.frame is None:
             figure.subplot_imshow_grayscale(1,0,pixel_data,self.image_name.value,
                                             sharex=figure.subplot(0,0),
                                             sharey=figure.subplot(0,0))
     elif self.image_mode == IM_COLOR:
         import matplotlib.cm
         from cellprofiler.gui.cpfigure_tools import renumber_labels_for_display
         if self.colormap.value == DEFAULT_COLORMAP:
             cm_name = cpprefs.get_default_colormap()
         elif self.colormap.value == COLORCUBE:
             # Colorcube missing from matplotlib
             cm_name = "gist_rainbow"
         elif self.colormap.value == LINES:
             # Lines missing from matplotlib and not much like it,
             # Pretty boring palette anyway, hence
             cm_name = "Pastel1"
         elif self.colormap.value == WHITE:
             # White missing from matplotlib, it's just a colormap
             # of all completely white... not even different kinds of
             # white. And, isn't white just a uniform sampling of
             # frequencies from the spectrum?
             cm_name = "Spectral"
         else:
             cm_name = self.colormap.value
         cm = matplotlib.cm.get_cmap(cm_name)
         mapper = matplotlib.cm.ScalarMappable(cmap=cm)
         pixel_data = mapper.to_rgba(renumber_labels_for_display(labels))
         pixel_data = pixel_data[:,:,:3]
         pixel_data[labels == 0,:] = 0
         if not workspace.frame is None:
             figure.subplot_imshow(1, 0, pixel_data, self.image_name.value,
                                   sharex=figure.subplot(0,0),
                                   sharey=figure.subplot(0,0))
     elif self.image_mode == IM_UINT16:
         pixel_data = labels.copy()
         if not workspace.frame is None:
             figure.subplot_imshow_grayscale(1, 0, pixel_data,
                                             self.image_name.value,
                                             sharex=figure.subplot(0,0),
                                             sharey=figure.subplot(0,0))
         convert = False
     image = cpi.Image(pixel_data, parent_image = objects.parent_image,
                       convert = convert)
     workspace.image_set.add(self.image_name.value, image)