def display(self, workspace):
     '''Display the results of relabeling
     
     workspace - workspace containing saved display data
     '''
     from cellprofiler.gui.cpfigure import renumber_labels_for_display
     import matplotlib.cm as cm
     
     figure = workspace.create_or_find_figure(title="UnifyObjectsByShape, image cycle #%d"%(
             workspace.measurements.image_set_number),subplots=(1,2))
     figure.subplot_imshow_labels(0,0, workspace.display_data.orig_labels,
                                  title = self.objects_name.value)
     
     output_labels = renumber_labels_for_display(
             workspace.display_data.output_labels)
     objects = workspace.object_set.get_objects(self.objects_name.value)
     labels = objects.segmented
     image = labels.astype(float) / (1.0 if np.max(labels) == 0 else np.max(labels))
     image = (stretch(image) * 255).astype(np.uint8)  
     
     image = np.dstack((image,image,image))
     my_cm = cm.get_cmap(cpprefs.get_default_colormap())
     my_cm.set_bad((0,0,0))
     sm = cm.ScalarMappable(cmap=my_cm)
     m_output_labels = np.ma.array(output_labels,
                                 mask = output_labels == 0)
     output_image = sm.to_rgba(m_output_labels, bytes=True)[:,:,:3]
     image[output_labels > 0 ] = (
         image[output_labels > 0] / 4 * 3 +
         output_image[output_labels > 0,:] / 4)
 
     figure.subplot_imshow(0,1, image,
                           title = self.output_objects_name.value,
                           sharex = figure.subplot(0,0),
                           sharey = figure.subplot(0,0))
示例#2
0
    def display(self, workspace, figure):
        '''Display the results of relabeling
        
        workspace - workspace containing saved display data
        '''
        from cellprofiler.gui.cpfigure import renumber_labels_for_display
        import matplotlib.cm as cm

        figure.set_subplots((1, 2))
        figure.subplot_imshow_labels(0,
                                     0,
                                     workspace.display_data.orig_labels,
                                     title=self.objects_name.value)

        output_labels = renumber_labels_for_display(
            workspace.display_data.output_labels)
        if self.relabel_option == OPTION_UNIFY and (
            (self.unify_option == UNIFY_DISTANCE and self.wants_image) or
            (self.unify_option == UNIFY_PARENT)):
            if self.unify_option == UNIFY_DISTANCE and self.wants_image:
                #
                # Make a nice picture which superimposes the labels on the
                # guiding image
                #
                image = (stretch(workspace.display_data.image) * 255).astype(
                    np.uint8)
            elif self.unify_option == UNIFY_PARENT:
                parent_objects = workspace.object_set.get_objects(
                    self.parent_object.value)
                labels = parent_objects.segmented
                image = labels.astype(float) / (1.0 if np.max(labels) == 0 else
                                                np.max(labels))
                image = (stretch(image) * 255).astype(np.uint8)

            image = np.dstack((image, image, image))
            my_cm = cm.get_cmap(cpprefs.get_default_colormap())
            my_cm.set_bad((0, 0, 0))
            sm = cm.ScalarMappable(cmap=my_cm)
            m_output_labels = np.ma.array(output_labels,
                                          mask=output_labels == 0)
            output_image = sm.to_rgba(m_output_labels, bytes=True)[:, :, :3]
            image[output_labels > 0] = (image[output_labels > 0] / 4 * 3 +
                                        output_image[output_labels > 0, :] / 4)

            figure.subplot_imshow(0,
                                  1,
                                  image,
                                  title=self.output_objects_name.value,
                                  sharexy=figure.subplot(0, 0))
        else:
            figure.subplot_imshow_labels(0,
                                         1,
                                         workspace.display_data.output_labels,
                                         title=self.output_objects_name.value,
                                         sharexy=figure.subplot(0, 0))
    def display(self, workspace):
        """Display the results of relabeling
        
        workspace - workspace containing saved display data
        """
        from cellprofiler.gui.cpfigure import renumber_labels_for_display
        import matplotlib.cm as cm

        figure = workspace.create_or_find_figure(
            title="ReassignObjectNumbers, image cycle #%d" % (workspace.measurements.image_set_number), subplots=(1, 2)
        )
        figure.subplot_imshow_labels(0, 0, workspace.display_data.orig_labels, title=self.objects_name.value)

        output_labels = renumber_labels_for_display(workspace.display_data.output_labels)
        if self.relabel_option == OPTION_UNIFY:
            if self.unify_option == UNIFY_DISTANCE and self.wants_image:
                #
                # Make a nice picture which superimposes the labels on the
                # guiding image
                #
                image = (stretch(workspace.display_data.image) * 255).astype(np.uint8)
            elif self.unify_option == UNIFY_PARENT:
                parent_objects = workspace.object_set.get_objects(self.parent_object.value)
                labels = parent_objects.segmented
                image = labels.astype(float) / (1.0 if np.max(labels) == 0 else np.max(labels))
                image = (stretch(image) * 255).astype(np.uint8)

            image = np.dstack((image, image, image))
            my_cm = cm.get_cmap(cpprefs.get_default_colormap())
            my_cm.set_bad((0, 0, 0))
            sm = cm.ScalarMappable(cmap=my_cm)
            m_output_labels = np.ma.array(output_labels, mask=output_labels == 0)
            output_image = sm.to_rgba(m_output_labels, bytes=True)[:, :, :3]
            image[output_labels > 0] = image[output_labels > 0] / 4 * 3 + output_image[output_labels > 0, :] / 4

            figure.subplot_imshow(
                0,
                1,
                image,
                title=self.output_objects_name.value,
                sharex=figure.subplot(0, 0),
                sharey=figure.subplot(0, 0),
            )
        else:
            figure.subplot_imshow_labels(
                0,
                1,
                workspace.display_data.output_labels,
                title=self.output_objects_name.value,
                sharex=figure.subplot(0, 0),
                sharey=figure.subplot(0, 0),
            )
示例#4
0
        def display():
            if len(orig_axes.images) > 0:
                # Save zoom and scale if coming through here a second time
                x0, x1 = orig_axes.get_xlim()
                y0, y1 = orig_axes.get_ylim()
                set_lim = True
            else:
                set_lim = False
            for axes, labels, title in ((orig_axes, orig_labels,
                                         "Original: %s" % orig_objects_name),
                                        (keep_axes, orig_labels * mask,
                                         "Objects to keep"),
                                        (remove_axes, orig_labels * (~mask),
                                         "Objects to remove")):

                assert isinstance(axes, matplotlib.axes.Axes)
                labels = renumber_labels_for_display(labels)
                axes.clear()
                if np.all(labels == 0):
                    use_cm = matplotlib.cm.gray
                    is_blank = True
                else:
                    use_cm = cm
                    is_blank = False
                if wants_image_display[0]:
                    outlines = outline(labels)
                    image = workspace.image_set.get_image(
                        self.image_name.value)
                    image = image.pixel_data.astype(np.float)
                    image, _ = cpo.size_similarly(labels, image)
                    if image.ndim == 2:
                        image = np.dstack((image, image, image))
                    if not is_blank:
                        mappable = matplotlib.cm.ScalarMappable(cmap=use_cm)
                        mappable.set_clim(1, labels.max())
                        limage = mappable.to_rgba(labels)[:, :, :3]
                        image[outlines != 0, :] = limage[outlines != 0, :]
                    axes.imshow(image)

                else:
                    axes.imshow(labels, cmap=use_cm)
                axes.set_title(title,
                               fontname=cpprefs.get_title_font_name(),
                               fontsize=cpprefs.get_title_font_size())
            if set_lim:
                orig_axes.set_xlim((x0, x1))
                orig_axes.set_ylim((y0, y1))
            figure.canvas.draw()
            panel.Refresh()
示例#5
0
    def display(self, workspace):
        '''Display the results of relabeling
        
        workspace - workspace containing saved display data
        '''
        from cellprofiler.gui.cpfigure import renumber_labels_for_display
        import matplotlib.cm as cm

        figure = workspace.create_or_find_figure(
            title="ReassignObjectNumbers, image cycle #%d" %
            (workspace.measurements.image_set_number),
            subplots=(1, 2))
        figure.subplot_imshow_labels(0,
                                     0,
                                     workspace.display_data.orig_labels,
                                     title=self.objects_name.value)
        if self.wants_image:
            #
            # Make a nice picture which superimposes the labels on the
            # guiding image
            #
            output_labels = renumber_labels_for_display(
                workspace.display_data.output_labels)
            image = (stretch(workspace.display_data.image) * 255).astype(
                np.uint8)
            image = np.dstack((image, image, image))
            my_cm = cm.get_cmap(cpprefs.get_default_colormap())
            my_cm.set_bad((0, 0, 0))
            sm = cm.ScalarMappable(cmap=my_cm)
            m_output_labels = np.ma.array(output_labels,
                                          mask=output_labels == 0)
            output_image = sm.to_rgba(m_output_labels, bytes=True)[:, :, :3]
            image[output_labels > 0] = (image[output_labels > 0] / 4 * 3 +
                                        output_image[output_labels > 0, :] / 4)
            figure.subplot_imshow(0,
                                  1,
                                  image,
                                  title=self.output_objects_name.value,
                                  sharex=figure.subplot(0, 0),
                                  sharey=figure.subplot(0, 0))
        else:
            figure.subplot_imshow_labels(0,
                                         1,
                                         workspace.display_data.output_labels,
                                         title=self.output_objects_name.value,
                                         sharex=figure.subplot(0, 0),
                                         sharey=figure.subplot(0, 0))
示例#6
0
    def display(self, workspace, figure):
        '''Create an informative display for the module'''
        import matplotlib
        from cellprofiler.gui.cpfigure 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))
 def display():
     if len(orig_axes.images) > 0:
         # Save zoom and scale if coming through here a second time
         x0, x1 = orig_axes.get_xlim()
         y0, y1 = orig_axes.get_ylim()
         set_lim = True
     else:
         set_lim = False
     for axes, labels, title in (
         (orig_axes, orig_labels, "Original: %s"%orig_objects_name),
         (keep_axes, orig_labels * mask,"Objects to keep"),
         (remove_axes, orig_labels * (~ mask), "Objects to remove")):
         
         assert isinstance(axes, matplotlib.axes.Axes)
         labels = renumber_labels_for_display(labels)
         axes.clear()
         if np.all(labels == 0):
             use_cm = matplotlib.cm.gray
             is_blank = True
         else:
             use_cm = cm
             is_blank = False
         if wants_image_display[0]:
             outlines = outline(labels)
             image = workspace.image_set.get_image(self.image_name.value)
             image = image.pixel_data.astype(np.float)
             image, _ = cpo.size_similarly(labels, image)
             if image.ndim == 2:
                 image = np.dstack((image, image, image))
             if not is_blank:
                 mappable = matplotlib.cm.ScalarMappable(cmap=use_cm)
                 mappable.set_clim(1,labels.max())
                 limage = mappable.to_rgba(labels)[:,:,:3]
                 image[outlines != 0,:] = limage[outlines != 0, :]
             axes.imshow(image)
             
         else:
             axes.imshow(labels, cmap = use_cm)
         axes.set_title(title,
                        fontname=cpprefs.get_title_font_name(),
                        fontsize=cpprefs.get_title_font_size())
     if set_lim:
         orig_axes.set_xlim((x0, x1))
         orig_axes.set_ylim((y0, y1))
     figure.canvas.draw()
     panel.Refresh()
示例#8
0
 def display(self, workspace):
     '''Create an informative display for the module'''
     import matplotlib
     from cellprofiler.gui.cpfigure 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 = workspace.create_or_find_figure(title="MaskObjects, image cycle #%d"%(
             workspace.measurements.image_set_number),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,
                                 sharex = figure.subplot(0,0),
                                 sharey = figure.subplot(0,0))
 def display(self, workspace):
     '''Display the results of relabeling
     
     workspace - workspace containing saved display data
     '''
     from cellprofiler.gui.cpfigure import renumber_labels_for_display
     import matplotlib.cm as cm
     
     figure = workspace.create_or_find_figure(title="ReassignObjectNumbers, image cycle #%d"%(
             workspace.measurements.image_set_number),subplots=(1,2))
     figure.subplot_imshow_labels(0,0, workspace.display_data.orig_labels,
                                  title = self.objects_name.value)
     if self.wants_image:
         #
         # Make a nice picture which superimposes the labels on the
         # guiding image
         #
         output_labels = renumber_labels_for_display(
             workspace.display_data.output_labels)
         image = (stretch(workspace.display_data.image) * 255).astype(np.uint8)
         image = np.dstack((image,image,image))
         my_cm = cm.get_cmap(cpprefs.get_default_colormap())
         my_cm.set_bad((0,0,0))
         sm = cm.ScalarMappable(cmap=my_cm)
         m_output_labels = np.ma.array(output_labels,
                                     mask = output_labels == 0)
         output_image = sm.to_rgba(m_output_labels, bytes=True)[:,:,:3]
         image[output_labels > 0 ] = (
             image[output_labels > 0] / 4 * 3 +
             output_image[output_labels > 0,:] / 4)
         figure.subplot_imshow(0,1, image,
                               title = self.output_objects_name.value,
                               sharex = figure.subplot(0,0),
                               sharey = figure.subplot(0,0))
     else:
         figure.subplot_imshow_labels(0,1, 
                                      workspace.display_data.output_labels,
                                      title = self.output_objects_name.value,
                                      sharex = figure.subplot(0,0),
                                      sharey = figure.subplot(0,0))
 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 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 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)
        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) / 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 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)
示例#13
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 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)