예제 #1
0
 def finalize(self, result):
     try:
         import imagej.ijbridge as ijbridge
         if ijbridge.inter_proc_ij_bridge._isInstantiated():
             ijbridge.get_ij_bridge().quit()
     except:
         pass
     try:
         from cellprofiler.utilities.jutil import kill_vm
         kill_vm()
         os._exit(0)
     except:
         pass
예제 #2
0
 def finalize(self, result):
     try:
         import imagej.ijbridge as ijbridge
         if ijbridge.inter_proc_ij_bridge._isInstantiated():
             ijbridge.get_ij_bridge().quit()
     except:
         pass
     try:
         from cellprofiler.utilities.jutil import kill_vm
         kill_vm()
         os._exit(0)
     except:
         pass
예제 #3
0
 def run(self, workspace):
     '''Run the imageJ command'''
     import imagej.ijbridge as ijbridge
     
     J.attach()
     ijb = None
     try:
         ijb = ijbridge.get_ij_bridge()
         
         image_set = workspace.image_set
         assert isinstance(image_set, cpi.ImageSet)
         d = self.get_dictionary(workspace.image_set_list)
         if self.wants_to_set_current_image:
             input_image_name = self.current_input_image_name.value
             img = image_set.get_image(input_image_name,
                                       must_be_grayscale = True)
         else:
             img = None
         
         #
         # Run a command or macro on the first image of the set
         #
         if d[D_FIRST_IMAGE_SET] == image_set.number + 1:
             self.do_imagej(ijb, workspace, D_FIRST_IMAGE_SET)
         #
         # Install the input image as the current image
         #
         if img is not None:
             ijb.inject_image(img.pixel_data, input_image_name)
 
         self.do_imagej(ijb, workspace)
         #
         # Get the output image
         #
         if self.wants_to_get_current_image:
             output_image_name = self.current_output_image_name.value
             pixel_data = ijb.get_current_image()
             image = cpi.Image(pixel_data)
             image_set.add(output_image_name, image)
         #
         # Execute the post-group macro or command
         #
         if d[D_LAST_IMAGE_SET] == image_set.number + 1:
             self.do_imagej(ijb, workspace, D_LAST_IMAGE_SET)
             #
             # Save the current ImageJ image after executing the post-group
             # command or macro
             #
             if (self.post_group_choice != CM_NOTHING and
                 self.wants_post_group_image):
                 output_image_name = self.post_group_output_image.value
                 pixel_data = ijb.get_current_image()
                 image = cpi.Image(pixel_data)
                 image_set.add(output_image_name, image)
         if self.is_interactive():
             self.display(workspace)
     finally:
         if ijb is not None:
             del(ijb)
         J.detach()
예제 #4
0
    def run(self, workspace):
        '''Run the imageJ command'''
        import imagej.ijbridge as ijbridge

        J.attach()
        ijb = None
        try:
            ijb = ijbridge.get_ij_bridge()

            image_set = workspace.image_set
            assert isinstance(image_set, cpi.ImageSet)
            d = self.get_dictionary(workspace.image_set_list)
            if self.wants_to_set_current_image:
                input_image_name = self.current_input_image_name.value
                img = image_set.get_image(input_image_name,
                                          must_be_grayscale=True)
            else:
                img = None

            #
            # Run a command or macro on the first image of the set
            #
            if d[D_FIRST_IMAGE_SET] == image_set.number + 1:
                self.do_imagej(ijb, workspace, D_FIRST_IMAGE_SET)
            #
            # Install the input image as the current image
            #
            if img is not None:
                ijb.inject_image(img.pixel_data, input_image_name)

            self.do_imagej(ijb, workspace)
            #
            # Get the output image
            #
            if self.wants_to_get_current_image:
                output_image_name = self.current_output_image_name.value
                pixel_data = ijb.get_current_image()
                image = cpi.Image(pixel_data)
                image_set.add(output_image_name, image)
            #
            # Execute the post-group macro or command
            #
            if d[D_LAST_IMAGE_SET] == image_set.number + 1:
                self.do_imagej(ijb, workspace, D_LAST_IMAGE_SET)
                #
                # Save the current ImageJ image after executing the post-group
                # command or macro
                #
                if (self.post_group_choice != CM_NOTHING
                        and self.wants_post_group_image):
                    output_image_name = self.post_group_output_image.value
                    pixel_data = ijb.get_current_image()
                    image = cpi.Image(pixel_data)
                    image_set.add(output_image_name, image)
            if self.is_interactive():
                self.display(workspace)
        finally:
            if ijb is not None:
                del (ijb)
            J.detach()
예제 #5
0
 def on_show_imagej(self):
     '''Show the ImageJ user interface
     
     This method shows the ImageJ user interface when the user presses
     the Show ImageJ button.
     '''
     import imagej.ijbridge as ijbridge
     ijb = ijbridge.get_ij_bridge()
     ijb.show_imagej()
예제 #6
0
 def on_show_imagej(self):
     '''Show the ImageJ user interface
     
     This method shows the ImageJ user interface when the user presses
     the Show ImageJ button.
     '''
     if bioformats.USE_IJ2:
         J.run_in_main_thread(
             lambda: RunImageJ.get_context().loadService(
                 "imagej.ui.UIService"), True)
     else:
         import imagej.ijbridge as ijbridge
         ijb = ijbridge.get_ij_bridge()
         J.run_in_main_thread(lambda: ijb.show_imagej(), True)
예제 #7
0
 def on_show_imagej(self):
     '''Show the ImageJ user interface
     
     This method shows the ImageJ user interface when the user presses
     the Show ImageJ button.
     '''
     if bioformats.USE_IJ2:
         J.run_in_main_thread(
             lambda :
             RunImageJ.get_context().loadService("imagej.ui.UIService"),
             True)
     else:
         import imagej.ijbridge as ijbridge
         ijb = ijbridge.get_ij_bridge()
         ijb.show_imagej()
예제 #8
0
 def get_cached_commands():
     global cached_commands
     if cached_commands is None:
         import cellprofiler.utilities.jutil as J
         import imagej.ijbridge as ijbridge
         ijb = ijbridge.get_ij_bridge()
         commands = ijb.get_commands()
         if hasattr(commands, 'values'):
             values = commands.values
         else:
             values = [None] * len(commands)
         cached_commands = {}
         for key, value in zip(commands, values):
             cached_commands[key] = value
     return cached_commands
예제 #9
0
 def get_cached_commands():
     global cached_commands
     global ij2_module_service
     if cached_commands is None:
         import imagej.ijbridge as ijbridge
         ijb = ijbridge.get_ij_bridge()
         import cellprofiler.utilities.jutil as J
         commands = ijb.get_commands()
         if hasattr(commands, 'values'):
             values = commands.values
         else:
             values = [None] * len(commands)
         cached_commands = {}
         for key, value in zip(commands, values):
             cached_commands[key] = value
     return cached_commands
예제 #10
0
 def get_context():
     import imagej.ijbridge as ijbridge
     ijb = ijbridge.get_ij_bridge()
     return ijb.context
예제 #11
0
            if measurements is not None:
                del measurements  # clean up
except Exception, e:
    logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True)
    raise
finally:
    import gc
    gc.collect(
    )  # This will clean up any remaining objects, calling their __del__ methods.

    # Smokey, my friend, you are entering a world of pain.
    # No $#!+ sherlock.
    try:
        import imagej.ijbridge as ijbridge
        if ijbridge.inter_proc_ij_bridge._isInstantiated():
            ijbridge.get_ij_bridge().quit()
    except:
        logging.root.warning("Caught exception while killing ijbridge.",
                             exc_info=True)

    try:
        if hasattr(sys, 'flags'):
            if sys.flags.interactive:
                assert False, "Don't kill JVM in interactive mode, because it calls exit()"
        import cellprofiler.utilities.jutil as jutil
        jutil.kill_vm()
    except:
        logging.root.warning("Caught exception while killing VM.",
                             exc_info=True)
os._exit(0)
예제 #12
0
                fd = open(options.done_file, "wt")
                fd.write("%s\n"%done_text)
                fd.close()
            if measurements is not None:
                del measurements  # clean up
except Exception, e:
    logging.root.fatal("Uncaught exception in CellProfiler.py", exc_info=True)
    raise
finally:
    import gc
    gc.collect()  # This will clean up any remaining objects, calling their __del__ methods.

    # Smokey, my friend, you are entering a world of pain.
    # No $#!+ sherlock.
    try:
        import imagej.ijbridge as ijbridge
        if ijbridge.inter_proc_ij_bridge._isInstantiated():
            ijbridge.get_ij_bridge().quit()
    except:
        logging.root.warning("Caught exception while killing ijbridge.", exc_info=True)

    try:
        if hasattr(sys, 'flags'):
            if sys.flags.interactive:
                assert False, "Don't kill JVM in interactive mode, because it calls exit()"
        import cellprofiler.utilities.jutil as jutil
        jutil.kill_vm()
    except:
        logging.root.warning("Caught exception while killing VM.", exc_info=True)
os._exit(0)
예제 #13
0
 def get_context():
     import imagej.ijbridge as ijbridge
     ijb = ijbridge.get_ij_bridge()
     return ijb.context