コード例 #1
0
 def test_01_08_get_current_image(self):
     file_name = os.path.join(self.root_dir, "ExampleSBSImages",
                              "Channel1-01-A-01.tif")
     ip = I.load_imageplus(file_name)
     W.set_current_image(ip)
     ip_out = W.get_current_image()
     self.assertEqual(ip.getID(), ip_out.getID())
コード例 #2
0
 def test_01_08_get_current_image(self):
     file_name = os.path.join(self.root_dir, 
                              "ExampleSBSImages", "Channel1-01-A-01.tif")
     ip = I.load_imageplus(file_name)
     W.set_current_image(ip)
     ip_out = W.get_current_image()
     self.assertEqual(ip.getID(), ip_out.getID())
コード例 #3
0
    def run(self, workspace):
        """Run the imageJ command"""
        image_set = workspace.image_set
        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)
            if self.show_window:
                workspace.display_data.image_sent_to_ij = img.pixel_data
        else:
            img = None
        display_service = ij2.get_display_service(get_context())
        #
        # Run a command or macro on the first image of the set
        #
        if d.get(D_FIRST_IMAGE_SET) == image_set.image_number:
            self.do_imagej(workspace, D_FIRST_IMAGE_SET)
        ij1_mode = self.command_or_macro == CM_MACRO
        #
        # Install the input image as the current image
        #
        if img is not None:
            ijpixels = img.pixel_data * IMAGEJ_SCALE
            if ij1_mode:
                ij_processor = ijiproc.make_image_processor(ijpixels.astype("float32"))
                image_plus = ijip.make_imageplus_from_processor(input_image_name, ij_processor)
                ijwm.set_current_image(image_plus)
            else:
                dataset = ij2.create_dataset(get_context(), ijpixels, input_image_name)
                display = display_service.createDisplay(input_image_name, dataset)
                display_service.setActiveDisplay(display)

        self.do_imagej(workspace)
        #
        # Get the output image
        #
        if self.wants_to_get_current_image:
            output_image_name = self.current_output_image_name.value
            if ij1_mode:
                image_plus = ijwm.get_current_image()
                ij_processor = image_plus.getProcessor()
                pixels = ijiproc.get_image(ij_processor).astype("float32") / IMAGEJ_SCALE
                image = cpi.Image(pixels)
                workspace.image_set.add(output_image_name, image)
            else:
                for attempt in range(4):
                    display = display_service.getActiveImageDisplay()
                    if display.o is not None:
                        break
                    #
                    # Possible synchronization problem with ImageJ 1.0
                    # Possible error involving user changing window focus
                    #
                    import time

                    time.sleep(0.25)
                else:
                    raise ValueError("Failed to retrieve active display")
                pixels = self.save_display_as_image(workspace, display, output_image_name)
            if self.show_window:
                workspace.display_data.image_acquired_from_ij = pixels
        #
        # Execute the post-group macro or command
        #
        if d.get(D_LAST_IMAGE_SET) == image_set.image_number:
            self.do_imagej(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
                if ij1_mode:
                    image_plus = ijwm.get_current_image()
                    ij_processor = image_plus.getProcessor()
                    pixels = ijiproc.get_image(ij_processor).astype("float32") / IMAGEJ_SCALE
                    image = cpi.Image(pixels, mask=mask)
                    workspace.image_set.add(output_image_name, image)
                else:
                    display = display_service.getActiveImageDisplay()
                    self.save_display_as_image(workspace, display, output_image_name)
コード例 #4
0
 def test_01_08_get_current_image(self):
     ip = I.load_imageplus(self.file_name)
     W.set_current_image(ip)
     ip_out = W.get_current_image()
     self.assertEqual(ip.getID(), ip_out.getID())
コード例 #5
0
ファイル: ijbridge.py プロジェクト: braniti/CellProfiler
 def get_current_image(self):
     '''returns the WindowManager's current image as a numpy float array'''
     image_plus = ijwm.get_current_image()
     ij_processor = image_plus.getProcessor()
     pixels = ijiproc.get_image(ij_processor).astype('float32') / 255.0
     return pixels
コード例 #6
0
    def run(self, workspace):
        '''Run the imageJ command'''
        image_set = workspace.image_set
        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)
            if self.show_window:
                workspace.display_data.image_sent_to_ij = img.pixel_data
        else:
            img = None
        display_service = ij2.get_display_service(get_context())
        #
        # Run a command or macro on the first image of the set
        #
        if d.get(D_FIRST_IMAGE_SET) == image_set.image_number:
            self.do_imagej(workspace, D_FIRST_IMAGE_SET)
        ij1_mode = self.command_or_macro == CM_MACRO
        #
        # Install the input image as the current image
        #
        if img is not None:
            ijpixels = img.pixel_data * IMAGEJ_SCALE
            if ij1_mode:
                ij_processor = ijiproc.make_image_processor(
                    ijpixels.astype('float32'))
                image_plus = ijip.make_imageplus_from_processor(
                    input_image_name, ij_processor)
                ijwm.set_current_image(image_plus)
            else:
                dataset = ij2.create_dataset(get_context(), ijpixels,
                                             input_image_name)
                display = display_service.createDisplay(
                    input_image_name, dataset)
                display_service.setActiveDisplay(display)

        self.do_imagej(workspace)
        #
        # Get the output image
        #
        if self.wants_to_get_current_image:
            output_image_name = self.current_output_image_name.value
            if ij1_mode:
                image_plus = ijwm.get_current_image()
                ij_processor = image_plus.getProcessor()
                pixels = ijiproc.get_image(ij_processor).\
                    astype('float32') / IMAGEJ_SCALE
                image = cpi.Image(pixels)
                workspace.image_set.add(output_image_name, image)
            else:
                for attempt in range(4):
                    display = display_service.getActiveImageDisplay()
                    if display.o is not None:
                        break
                    #
                    # Possible synchronization problem with ImageJ 1.0
                    # Possible error involving user changing window focus
                    #
                    import time
                    time.sleep(.25)
                else:
                    raise ValueError("Failed to retrieve active display")
                pixels = self.save_display_as_image(workspace, display,
                                                    output_image_name)
            if self.show_window:
                workspace.display_data.image_acquired_from_ij = pixels
        #
        # Execute the post-group macro or command
        #
        if d.get(D_LAST_IMAGE_SET) == image_set.image_number:
            self.do_imagej(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
                if ij1_mode:
                    image_plus = ijwm.get_current_image()
                    ij_processor = image_plus.getProcessor()
                    pixels = ijiproc.get_image(ij_processor).\
                        astype('float32') / IMAGEJ_SCALE
                    image = cpi.Image(pixels, mask=mask)
                    workspace.image_set.add(output_image_name, image)
                else:
                    display = display_service.getActiveImageDisplay()
                    self.save_display_as_image(workspace, display,
                                               output_image_name)
コード例 #7
0
 def get_current_image(self):
     '''returns the WindowManager's current image as a numpy float array'''
     image_plus = ijwm.get_current_image()
     ij_processor = image_plus.getProcessor()
     pixels = ijiproc.get_image(ij_processor).astype('float32') / 255.0
     return pixels
コード例 #8
0
 def test_01_08_get_current_image(self):
     ip = I.load_imageplus(self.file_name)
     W.set_current_image(ip)
     ip_out = W.get_current_image()
     self.assertEqual(ip.getID(), ip_out.getID())