Exemplo n.º 1
0
 def handle_interaction(self, orig_labels, guide_image):
     from cellprofiler.gui.editobjectsdlg import EditObjectsDialog
     from wx import OK
     with EditObjectsDialog(guide_image, orig_labels, self.allow_overlap,
                            self.object_name.value) as dialog_box:
         result = dialog_box.ShowModal()
         if result != OK:
             raise self.InteractionCancelledException()
         return dialog_box.labels
Exemplo n.º 2
0
 def handle_interaction(self, orig_labels, guide_image, image_set_number):
     from cellprofiler.gui.editobjectsdlg import EditObjectsDialog
     from wx import OK
     title = "%s #%d, image cycle #%d: " % (
         self.module_name, self.module_num, image_set_number)
     title += "Create, remove and edit %s. Click Help for full instructions" % self.object_name.value
     with EditObjectsDialog(guide_image, orig_labels, self.allow_overlap,
                            title) as dialog_box:
         result = dialog_box.ShowModal()
         if result != OK:
             return None
         return dialog_box.labels
 def handle_interaction(self, pixel_data, image_set_number):
     '''Display a UI for editing'''
     from cellprofiler.gui.editobjectsdlg import EditObjectsDialog
     from wx import OK
     title = "%s #%d, image cycle #%d: " % (
         self.module_name, self.module_num, image_set_number)
     title += "Create, remove and edit %s. \n" % self.objects_name.value
     title += 'Press "F" to being freehand drawing.\n'
     title += "Click Help for full instructions."
     with EditObjectsDialog(pixel_data,
                            [np.zeros(pixel_data.shape[:2], np.uint32)],
                            False, title) as dialog_box:
         result = dialog_box.ShowModal()
         if result != OK:
             return None
         return dialog_box.labels[0]
Exemplo n.º 4
0
    def run_as_data_tool(self):
        from cellprofiler.gui.editobjectsdlg import EditObjectsDialog
        import wx
        from wx.lib.filebrowsebutton import FileBrowseButton
        from cellprofiler.modules.namesandtypes import ObjectsImageProvider
        from bioformats import load_image

        with wx.Dialog(None) as dlg:
            dlg.Title = "Choose files for editing"
            dlg.Sizer = wx.BoxSizer(wx.VERTICAL)
            sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
            dlg.Sizer.Add(sub_sizer, 0, wx.EXPAND | wx.ALL, 5)
            new_or_existing_rb = wx.RadioBox(dlg,
                                             style=wx.RA_VERTICAL,
                                             choices=("New", "Existing"))
            sub_sizer.Add(new_or_existing_rb, 0, wx.EXPAND)
            objects_file_fbb = FileBrowseButton(
                dlg,
                size=(300, -1),
                fileMask=
                "Objects file (*.tif, *.tiff, *.png, *.bmp, *.jpg)|*.tif;*.tiff;*.png;*.bmp;*.jpg",
                dialogTitle="Select objects file",
                labelText="Objects file:",
            )
            objects_file_fbb.Enable(False)
            sub_sizer.AddSpacer(5)
            sub_sizer.Add(objects_file_fbb, 0, wx.ALIGN_TOP | wx.ALIGN_RIGHT)

            def on_radiobox(event):
                objects_file_fbb.Enable(new_or_existing_rb.GetSelection() == 1)

            new_or_existing_rb.Bind(wx.EVT_RADIOBOX, on_radiobox)

            image_file_fbb = FileBrowseButton(
                dlg,
                size=(300, -1),
                fileMask=
                "Objects file (*.tif, *.tiff, *.png, *.bmp, *.jpg)|*.tif;*.tiff;*.png;*.bmp;*.jpg",
                dialogTitle="Select guide image file",
                labelText="Guide image:",
            )
            dlg.Sizer.Add(image_file_fbb, 0, wx.EXPAND | wx.ALL, 5)

            allow_overlap_checkbox = wx.CheckBox(dlg, -1,
                                                 "Allow objects to overlap")
            allow_overlap_checkbox.Value = True
            dlg.Sizer.Add(allow_overlap_checkbox, 0, wx.EXPAND | wx.ALL, 5)

            buttons = wx.StdDialogButtonSizer()
            dlg.Sizer.Add(buttons, 0,
                          wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL,
                          5)
            buttons.Add(wx.Button(dlg, wx.ID_OK))
            buttons.Add(wx.Button(dlg, wx.ID_CANCEL))
            buttons.Realize()
            dlg.Fit()
            result = dlg.ShowModal()
            if result != wx.ID_OK:
                return
            self.allow_overlap.value = allow_overlap_checkbox.Value
            fullname = objects_file_fbb.GetValue()
            guidename = image_file_fbb.GetValue()

        if new_or_existing_rb.GetSelection() == 1:
            provider = ObjectsImageProvider("InputObjects",
                                            pathname2url(fullname), None, None)
            image = provider.provide_image(None)
            pixel_data = image.pixel_data
            shape = pixel_data.shape[:2]
            labels = [pixel_data[:, :, i] for i in range(pixel_data.shape[2])]
        else:
            labels = None
        #
        # Load the guide image
        #
        guide_image = load_image(guidename)
        if np.min(guide_image) != np.max(guide_image):
            guide_image = (guide_image - np.min(guide_image)) / (
                np.max(guide_image) - np.min(guide_image))
        if labels is None:
            shape = guide_image.shape[:2]
            labels = [np.zeros(shape, int)]
        with EditObjectsDialog(guide_image, labels, self.allow_overlap,
                               self.object_name.value) as dialog_box:
            result = dialog_box.ShowModal()
            if result != wx.OK:
                return
            labels = dialog_box.labels
        n_frames = len(labels)
        with wx.FileDialog(None,
                           style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as dlg:

            dlg.Path = fullname
            dlg.Wildcard = ("Object image file (*.tif,*.tiff)|*.tif;*.tiff|"
                            "Ilastik project file (*.ilp)|*.ilp")
            result = dlg.ShowModal()
            fullname = dlg.Path
            if result == wx.ID_OK:
                if fullname.endswith(".ilp"):
                    self.save_into_ilp(fullname, labels, guidename)
                else:
                    from bioformats.formatwriter import write_image
                    from bioformats.omexml import PT_UINT16

                    if os.path.exists(fullname):
                        os.unlink(fullname)
                    for i, l in enumerate(labels):
                        write_image(fullname,
                                    l,
                                    PT_UINT16,
                                    t=i,
                                    size_t=len(labels))