Exemple #1
0
    def run(self, workspace):
        image_name = self.image_name.value
        measurements = workspace.measurements
        image_set = workspace.image_set

        M_FILE_NAME = cpmeas.C_FILE_NAME + "_" + image_name
        M_PATH_NAME = cpmeas.C_PATH_NAME + "_" + image_name
        #
        # Use measurements.get_measurement to get the file name and path name
        # for this cycle
        #
        path_name = measurements.get_measurement(cpmeas.IMAGE, M_PATH_NAME)
        file_name = measurements.get_measurement(cpmeas.IMAGE, M_FILE_NAME)
        #
        # use os.path.join(pathname, filename) to get the name for BioFormats
        #
        path = os.path.join(path_name, file_name)
        #
        # call load_using_bioformats(path) to load the file into a numpy array
        #
        pixel_data = load_using_bioformats(path)
        #
        # make a cpi.Image for the image data
        #
        image = cpi.Image(pixel_data, path_name=path_name, file_name=file_name)
        #
        # call image_set.add to add the image to the image set
        #
        image_set.add(image_name, image)
 def run(self, workspace):
     image_name = self.image_name.value
     measurements = workspace.measurements
     image_set = workspace.image_set
     
     M_FILE_NAME = cpmeas.C_FILE_NAME + "_" + image_name
     M_PATH_NAME = cpmeas.C_PATH_NAME + "_" + image_name
     #
     # Use measurements.get_measurement to get the file name and path name
     # for this cycle
     #
     path_name = measurements.get_measurement(cpmeas.IMAGE, M_PATH_NAME)
     file_name = measurements.get_measurement(cpmeas.IMAGE, M_FILE_NAME)
     #
     # use os.path.join(pathname, filename) to get the name for BioFormats
     #
     path = os.path.join(path_name, file_name)
     #
     # call load_using_bioformats(path) to load the file into a numpy array
     #
     pixel_data = load_using_bioformats(path)
     #
     # make a cpi.Image for the image data
     #
     image = cpi.Image(pixel_data, path_name = path_name, file_name = file_name)
     #
     # call image_set.add to add the image to the image set
     #
     image_set.add(image_name, image)
def read_test_image(file_name, **kwargs):
    '''Read an image from the test directory
    
    file_name - name of the file within the test directory
    
    **kwargs - arguments passe into load_using_bioformats
    '''
    from bioformats import load_using_bioformats
    path = os.path.join(testimages_directory, file_name)
    return load_using_bioformats(path, **kwargs)
Exemple #4
0
def read_test_image(file_name, **kwargs):
    '''Read an image from the test directory
    
    file_name - name of the file within the test directory
    
    **kwargs - arguments passe into load_using_bioformats
    '''
    from bioformats import load_using_bioformats
    path = os.path.join(testimages_directory, file_name)
    return load_using_bioformats(path, **kwargs)
def read_example_image(folder, file_name, **kwargs):
    '''Read an example image from one of the example image directories
    
    folder - folder containing images, e.g. "ExampleFlyImages"
    
    file_name - the name of the file within the folder
    
    **kwargs - any keyword arguments are passed onto load_using_bioformats
    '''
    from bioformats import load_using_bioformats
    path = os.path.join(example_images_directory(), folder, file_name)
    return load_using_bioformats(path, **kwargs)
Exemple #6
0
def read_example_image(folder, file_name, **kwargs):
    '''Read an example image from one of the example image directories
    
    folder - folder containing images, e.g. "ExampleFlyImages"
    
    file_name - the name of the file within the folder
    
    **kwargs - any keyword arguments are passed onto load_using_bioformats
    '''
    from bioformats import load_using_bioformats
    path = os.path.join(example_images_directory(), folder, file_name)
    return load_using_bioformats(path, **kwargs)
    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_using_bioformats

        with wx.Dialog(None) as dlg:
            dlg.Title = "Choose files for editing"
            dlg.Sizer = wx.BoxSizer(wx.VERTICAL)
            box = wx.StaticBox(dlg, -1, "Choose or create new objects file")
            sub_sizer = wx.StaticBoxSizer(box, 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_using_bioformats(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))
    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_using_bioformats
        
        with wx.Dialog(None) as dlg:
            dlg.Title = "Choose files for editing"
            dlg.Sizer = wx.BoxSizer(wx.VERTICAL)
            box = wx.StaticBox(dlg, -1, "Choose or create new objects file")
            sub_sizer = wx.StaticBoxSizer(box, 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_using_bioformats(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))