示例#1
0
 def test_03_02_command_service_run(self):
     svc = ij2.get_command_service(self.context)
     module_infos = ij2.get_module_service(self.context).getModules()
     for module_info in module_infos:
         if module_info.getClassName() == \
            'imagej.core.commands.display.ShowLUT':
             d = J.get_map_wrapper(J.make_instance('java/util/HashMap', '()V'))
             future = svc.run(module_info.o, d.o)
             module = future.get()
             module = ij2.wrap_module(module)
             module.getOutput('output')
             break
     else:
         raise AssertionError("Could not find target module")
示例#2
0
    def execute_advanced_command(self, workspace, command, d):
        '''Execute an advanced command

        command - name of the command
        d - dictionary to be used to find settings
        '''
        context = get_context()
        self.get_command_settings(command, d)
        wants_display = self.show_window
        if wants_display:
            workspace.display_data.input_images = input_images = []
            workspace.display_data.output_images = output_images = []
        key = command.get_unicode_value()
        node = command.get_selected_leaf()
        module_info = node[2]
        
        input_dictionary = J.get_map_wrapper(
            J.make_instance('java/util/HashMap', "()V"))
        display_dictionary = {}
        display_service = ij2.get_display_service(context)
        for setting, module_item in d[key]:
            if isinstance(setting, cps.ImageNameProvider):
                continue
            field_name = module_item.getName()
            field_type = module_item.getType()
            raw_type = J.call(module_item.o, "getType", "()Ljava/lang/Class;")
            if field_type in (ij2.FT_BOOL, ij2.FT_INTEGER, ij2.FT_FLOAT,
                              ij2.FT_STRING):
                input_dictionary.put(field_name, J.box(setting.value, raw_type))
            elif field_type == ij2.FT_COLOR:
                assert isinstance(setting, cps.Color)
                red, green, blue = setting.to_rgb()
                jobject = J.make_instance(
                    "imagej/util/ColorRGB", "(III)V", red, green, blue)
                input_dictionary.put(field_name, jobject)
            elif field_type == ij2.FT_IMAGE:
                image_name = setting.value
                image = workspace.image_set.get_image(image_name)
                pixel_data = image.pixel_data * IMAGEJ_SCALE
                
                dataset = ij2.create_dataset(
                    context, pixel_data, image_name)
                display = display_service.createDisplay(image_name, dataset)
                display_dictionary[module_item.getName()] = display 
                if image.has_mask:
                    #overlay_name = "X" + uuid.uuid4().get_hex()
                    #image_dictionary[overlay_name] = image.mask
                    overlay = ij2.create_overlay(context, image.mask)
                    overlay_service = ij2.get_overlay_service(context)
                    overlay_service.addOverlays(
                        display.o, J.make_list([overlay]))
                    ij2.select_overlay(display.o, overlay)
                input_dictionary.put(field_name, display.o)
                if wants_display:
                    input_images.append((image_name, image.pixel_data))
            elif field_type == ij2.FT_TABLE:
                table_name = setting.value
                table = workspace.object_set.get_type_instance(
                    IJ_TABLE_TYPE, table_name)
                input_dictionary.put(field_name, table)
            elif field_type == ij2.FT_FILE:
                jfile = J.make_instance(
                    "java/io/File", "(Ljava/lang/String;)V", setting.value)
                input_dictionary.put(field_name, jfile)
        command_service = ij2.get_command_service(get_context())
        future = command_service.run(module_info.o, input_dictionary.o)
        module = future.get()
        for setting, module_item in d[key]:
            if isinstance(setting, cps.ImageNameProvider):
                name = module_item.getName()
                output_name = setting.value
                if display_dictionary.has_key(name):
                    display = display_dictionary[name]
                else:
                    display = IJ2.wrap_display(module.getOutput(name))
                pixel_data = self.save_display_as_image(
                    workspace, display, output_name)
                
                if wants_display:
                    output_images.append((output_name, pixel_data))
        # Close any displays that we created.
        for display in display_dictionary.values():
            display.close()
示例#3
0
    def execute_advanced_command(self, workspace, command, d):
        '''Execute an advanced command

        command - name of the command
        d - dictionary to be used to find settings
        '''
        context = get_context()
        self.get_command_settings(command, d)
        wants_display = self.show_window
        if wants_display:
            workspace.display_data.input_images = input_images = []
            workspace.display_data.output_images = output_images = []
        key = command.get_unicode_value()
        node = command.get_selected_leaf()
        module_info = node[2]

        input_dictionary = J.get_map_wrapper(
            J.make_instance('java/util/HashMap', "()V"))
        display_dictionary = {}
        display_service = ij2.get_display_service(context)
        for setting, module_item in d[key]:
            if isinstance(setting, cps.ImageNameProvider):
                continue
            field_name = module_item.getName()
            field_type = module_item.getType()
            raw_type = J.call(module_item.o, "getType", "()Ljava/lang/Class;")
            if field_type in (ij2.FT_BOOL, ij2.FT_INTEGER, ij2.FT_FLOAT,
                              ij2.FT_STRING):
                input_dictionary.put(field_name, J.box(setting.value,
                                                       raw_type))
            elif field_type == ij2.FT_COLOR:
                assert isinstance(setting, cps.Color)
                red, green, blue = setting.to_rgb()
                jobject = J.make_instance("imagej/util/ColorRGB", "(III)V",
                                          red, green, blue)
                input_dictionary.put(field_name, jobject)
            elif field_type == ij2.FT_IMAGE:
                image_name = setting.value
                image = workspace.image_set.get_image(image_name)
                pixel_data = image.pixel_data * IMAGEJ_SCALE

                dataset = ij2.create_dataset(context, pixel_data, image_name)
                display = display_service.createDisplay(image_name, dataset)
                display_dictionary[module_item.getName()] = display
                if image.has_mask:
                    #overlay_name = "X" + uuid.uuid4().get_hex()
                    #image_dictionary[overlay_name] = image.mask
                    overlay = ij2.create_overlay(context, image.mask)
                    overlay_service = ij2.get_overlay_service(context)
                    overlay_service.addOverlays(display.o,
                                                J.make_list([overlay]))
                    ij2.select_overlay(display.o, overlay)
                input_dictionary.put(field_name, display.o)
                if wants_display:
                    input_images.append((image_name, image.pixel_data))
            elif field_type == ij2.FT_TABLE:
                table_name = setting.value
                table = workspace.object_set.get_type_instance(
                    IJ_TABLE_TYPE, table_name)
                input_dictionary.put(field_name, table)
            elif field_type == ij2.FT_FILE:
                jfile = J.make_instance("java/io/File",
                                        "(Ljava/lang/String;)V", setting.value)
                input_dictionary.put(field_name, jfile)
        command_service = ij2.get_command_service(get_context())
        future = command_service.run(module_info.o, input_dictionary.o)
        module = future.get()
        for setting, module_item in d[key]:
            if isinstance(setting, cps.ImageNameProvider):
                name = module_item.getName()
                output_name = setting.value
                if display_dictionary.has_key(name):
                    display = display_dictionary[name]
                else:
                    display = IJ2.wrap_display(module.getOutput(name))
                pixel_data = self.save_display_as_image(
                    workspace, display, output_name)

                if wants_display:
                    output_images.append((output_name, pixel_data))
        # Close any displays that we created.
        for display in display_dictionary.values():
            display.close()