def add_outline(self, can_remove=True):
        group = cps.SettingsGroup()
        if can_remove:
            group.append("divider", cps.Divider(line=False))

        group.append(
            "outline_choice",
            cps.Choice("Load outlines from an image or objects?",
                       [FROM_OBJECTS, FROM_IMAGES],
                       doc="""
            This setting selects what source the outlines come from:
            <ul>
            <li><i>%(FROM_OBJECTS)s:</i> Create the image directly from the
            objects. This option will improve the functionality of the
            contrast options for this module's interactive display and will
            save memory.</li>
            <li><i>%(FROM_IMAGES)s:</i> Prior versions of <b>OverlayOutlines</b> would only
            display outline images which were optional outputs of the identify
            modules. For legacy pipelines or to continue using the outline
            images instead of objects, choose this option.</li>
            </ul>
            """ % globals()))

        group.append(
            "objects_name",
            cps.ObjectNameSubscriber(
                "Select objects to display",
                cps.NONE,
                doc="""Choose the objects whose outlines you would like
        to display."""))
        group.append(
            "outline_name",
            cps.OutlineNameSubscriber("Select outlines to display",
                                      cps.NONE,
                                      doc="""
            Choose outlines to display, from a previous <b>Identify</b>
            module. Each of the <b>Identify</b> modules has a checkbox that
            determines whether the outlines are saved. If you have checked this,
            you were asked to supply a name for the outline; you
            can then select that name here.
            """))

        default_color = (COLOR_ORDER[len(self.outlines)]
                         if len(self.outlines) < len(COLOR_ORDER) else
                         COLOR_ORDER[0])
        group.append("color", cps.Color("Select outline color", default_color))
        if can_remove:
            group.append(
                "remover",
                cps.RemoveSettingButton("", "Remove this outline",
                                        self.outlines, group))

        self.outlines.append(group)
    def add_stack_channel_cb(self, can_remove=True):
        group = cps.SettingsGroup()
        default_color = DEFAULT_COLORS[len(self.stack_channels) %
                                       len(DEFAULT_COLORS)]
        group.append(
            "image_name",
            cps.ImageNameSubscriber("Image name",
                                    cps.NONE,
                                    doc="""
                <i>Used only if %(SCHEME_STACK)s or %(SCHEME_COMPOSITE)s is
                chosen</i><br>
                Select the input image to add to the stacked image""" %
                                    globals()))
        group.append(
            "color",
            cps.Color("Color",
                      default_color,
                      doc="""
            <i>Used only if %(SCHEME_COMPOSITE)s is chosen</i>
            <br>The color to be assigned to the above image.
            """ % globals()))
        group.append(
            "weight",
            cps.Float("Weight",
                      1.0,
                      minval=.5 / 255,
                      doc="""
            <i>Used only if %(SCHEME_COMPOSITE)s is chosen</i>
            <br>The weighting of the above image relative to the others. The
            image's pixel values are multiplied by this weight before assigning
            the color.
            """ % globals()))

        if can_remove:
            group.append(
                "remover",
                cps.RemoveSettingButton("", "Remove this image",
                                        self.stack_channels, group))
        self.stack_channels.append(group)
    def create_settings(self):
        self.orig_image_name = cps.ImageNameSubscriber(
            "Select the input images", "None",
            doc="""Select the images to display on the web page.""")
        
        self.wants_thumbnails = cps.Binary(
            "Use thumbnail images?", False,
            doc="""Check this option to display thumbnail images (small versions of the 
            images) on the web page that link to the full images. Leave it 
            unchecked to display the full image directly on the web page.
            <p>If you are going to use thumbnails, you will need to load
            them using <b>LoadImages</b> or <b>LoadData</b>; you can run a separate 
            pipeline prior to this one to create thumbnails from your originals  
            using the <b>Resize</b> and <b>SaveImages</b> modules. For some high-content
            screening systems, thumbnail files are automatically created and have
            the text "thumb" in the name.</p>""")
        
        self.thumbnail_image_name = cps.ImageNameSubscriber(
            "Select the thumbnail images", "None",
            doc="""
            <i>(Used only if using thumbnails)</i><br>
            Select the name of the images to use for thumbnails.""")
        
        self.web_page_file_name = cps.Text(
            "Webpage file name", "images1",
            metadata= True,
            doc="""Enter the desired file name for the web page. <b>CreateWebPage</b>
            will add the .html extension if no extension is specified.
            If you have metadata associated with your images, you can name the 
            file using metadata tags. %(USING_METADATA_TAGS_REF)s<br>
            For instance, if you have metadata tags named "Plate" and 
            "Well", you can create separate per-plate, per-well web pages based on
            your metadata by inserting the tags "Plate_Well" to specify the 
            name. %(USING_METADATA_HELP_REF)s."""%globals())
        
        self.directory_choice = cps.Choice(
            "Select the folder for the .html file",
            [ DIR_SAME, DIR_ABOVE],
            doc="""This setting determines how <b>CreateWebPage</b> selects the 
            folder for the .html file(s) it creates. 
            <ul>
            <li><i>%(DIR_SAME)s</i>: Place the .html file(s) in the same folder as 
            the files.</li>
            <li><i>%(DIR_ABOVE)s</i>: Place the .html file(s) in the
            image files' parent folder.</li>
            </ul>""" % globals())
        
        self.title = cps.Text(
            "Webpage title", "Image", metadata = True,
            doc = """This is the title that appears at the top of the browser
            window. If you have metadata associated with your images, you can name the 
            file using metadata tags. %(USING_METADATA_TAGS_REF)sFor instance, if you 
            have a metadata tag named "Plate", you can type "Plate: " and then insert 
            the metadata tag "Plate" to display the plate metadata item. %(USING_METADATA_HELP_REF)s."""
            %globals())
        
        self.background_color = cps.Color(
            "Webpage background color", "White",
            doc = """This setting controls the background color for the web page.""")
        
        self.columns = cps.Integer(
            "Number of columns", 1, minval = 1,
            doc = """This setting determines how many images are displayed
            in each row.""")
        
        self.table_border_width = cps.Integer(
            "Table border width", 1, minval = 0,
            doc = """The table border width determines the width of the border
            around the entire grid of displayed images (i.e., the "table" of images) and is measured in pixels. This value can be 
            set to zero, in which case you will not see the table border.""")
        
        self.table_border_color = cps.Color(
            "Table border color", "White")

        self.image_spacing = cps.Integer(
            "Image spacing", 1, minval = 0,
            doc = """The spacing between images ("table cells"), in pixels.""")
        
        self.image_border_width = cps.Integer(
            "Image border width", 1, minval = 0,
            doc = """The image border width determines the width of
            the border around each image and is measured in pixels.
            This value can be set to zero, in which case you will not see the 
            image border.""")
        
        self.create_new_window = cps.Choice(
            "Open new window when viewing full image?",
            [OPEN_ONCE, OPEN_EACH, OPEN_NO],
            doc = """This controls the behavior of the thumbnail links. If
            you select, <i>%(OPEN_ONCE)s</i>, your browser will open a new window
            when you click on the first thumbnail and will display subsequent
            images in the newly opened window. If you select <i>
            %(OPEN_EACH)s</i>, the browser will open a new window each time
            you click on a link. If you select, <i>%(OPEN_NO)s</i>, the
            browser will reuse the current window to display the image"""% globals())
        
        self.wants_zip_file = cps.Binary(
            "Make a ZIP file containing the full-size images?", False,doc="""
            ZIP files are a common archive and data compression file format, making it convenient to download all of the images represented on the web page with a single click.
            Check this box to create a ZIP file that contains all your images, 
            compressed to reduce file size.""")
        
        self.zipfile_name = cps.Text(
            "Enter the ZIP file name", "Images.zip",
            metadata = True,
            doc="""
            <i>(Used only if creating a ZIP file)</i><br>
            Specify the name for the ZIP file.""")
Exemple #4
0
 def get_command_settings(self, command, d):
     '''Get the settings associated with the current command
     
     d - the dictionary that persists the setting. None = regular
     '''
     key = command.get_unicode_value()
     if not d.has_key(key):
         try:
             module_info = command.get_selected_leaf()[2]
         except cps.ValidationError:
             logger.info("Could not find command %s" % key)
             return []
         result = []
         inputs = module_info.getInputs()
         for module_item in inputs:
             field_type = module_item.getType()
             label = module_item.getLabel()
             if label is None:
                 label = module_item.getName()
             if module_item.isOutput():
                 # if both, qualify which is for input and which for output
                 label = "%s (Input)" % label
             minimum = module_item.getMinimumValue()
             maximum = module_item.getMaximumValue()
             default = module_item.loadValue()
             description = module_item.getDescription()
             if field_type == ij2.FT_BOOL:
                 value = (J.is_instance_of(default, 'java/lang/Boolean')
                          and J.call(default, "booleanValue", "()Z"))
                 setting = cps.Binary(label, value=value, doc=description)
             elif field_type == ij2.FT_INTEGER:
                 if J.is_instance_of(default, 'java/lang/Number'):
                     value = J.call(default, "intValue", "()I")
                 elif minimum is not None:
                     value = minimum
                 elif maximum is not None:
                     value = maximum
                 else:
                     value = 0
                 setting = cps.Integer(label, value=value, doc=description)
             elif field_type == ij2.FT_FLOAT:
                 if J.is_instance_of(default, 'java/lang/Number'):
                     value = J.call(default, "doubleValue", "()D")
                 elif minimum is not None:
                     value = minimum
                 elif maximum is not None:
                     value = maximum
                 else:
                     value = 0
                 setting = cps.Float(label, value=value, doc=description)
             elif field_type == ij2.FT_STRING:
                 choices = module_item.getChoices()
                 value = J.to_string(default)
                 if choices is not None:
                     choices = J.get_collection_wrapper(choices)
                     setting = cps.Choice(label,
                                          choices,
                                          value,
                                          doc=description)
                 else:
                     setting = cps.Text(label, value, doc=description)
             elif field_type == ij2.FT_COLOR:
                 value = "#ffffff"
                 setting = cps.Color(label, value, doc=description)
             elif field_type == ij2.FT_IMAGE:
                 setting = cps.ImageNameSubscriber(label,
                                                   "InputImage",
                                                   doc=description)
             elif field_type == ij2.FT_TABLE:
                 setting = IJTableSubscriber(label,
                                             "InputTable",
                                             doc=description)
             elif field_type == ij2.FT_FILE:
                 setting = cps.FilenameText(label, None, doc=description)
             else:
                 continue
             result.append((setting, module_item))
         for output in module_info.getOutputs():
             field_type = output.getType()
             label = output.getLabel()
             if label is None:
                 label = output.getName()
             if output.isInput():
                 # if both, qualify which is for input and which for output
                 label = "%s (Output)" % label
             if field_type == ij2.FT_IMAGE:
                 result.append(
                     (cps.ImageNameProvider(label,
                                            "ImageJImage",
                                            doc=description), output))
             elif field_type == ij2.FT_TABLE:
                 result.append((IJTableProvider(label,
                                                "ImageJTable",
                                                doc=description), output))
         d[key] = result
     else:
         result = d[key]
     return [setting for setting, module_info in result]
 def create_settings(self):
     """Create your settings by subclassing this function
     
     create_settings is called at the end of initialization.
     
     You should create the setting variables for your module here:
         # Ask the user for the input image
         self.image_name = cellprofiler.settings.ImageNameSubscriber(...)
         # Ask the user for the name of the output image
         self.output_image = cellprofiler.settings.ImageNameProvider(...)
         # Ask the user for a parameter
         self.smoothing_size = cellprofiler.settings.Float(...)
     """
     self.objects_or_image = cps.Choice(
         "Display object or image measurements?",
         [OI_OBJECTS, OI_IMAGE],doc = """
         <ul>
         <li><i>%(OI_OBJECTS)s</i> displays measurements made on
         objects.</li>
         <li><i>%(OI_IMAGE)s</i> displays a single measurement made
         on an image.</li> 
         </ul>"""%globals())
     
     self.objects_name = cps.ObjectNameSubscriber(
         "Select the input objects", cps.NONE, doc = """
         <i>(Used only when displaying object measurements)</i><br>
         Choose the name of objects identified by some previous
         module (such as <b>IdentifyPrimaryObjects</b> or
         <b>IdentifySecondaryObjects</b>).""")
     
     def object_fn():
         if self.objects_or_image == OI_OBJECTS:
             return self.objects_name.value
         else:
             return cpmeas.IMAGE
     self.measurement = cps.Measurement(
         "Measurement to display", object_fn,doc="""
         Choose the measurement to display. This will be a measurement
         made by some previous module on either the whole image (if
         displaying a single image measurement) or on the objects you
         selected.""")
     
     self.wants_image = cps.Binary(
         "Display background image?", True,
         doc="""Choose whether or not to display the measurements on
         a background image. Usually, you will want to see the image
         context for the measurements, but it may be useful to save
         just the overlay of the text measurements and composite the
         overlay image and the original image later. Choose "Yes" to
         display the measurements on top of a background image or "No"
         to display the measurements on a black background.""")
     self.image_name = cps.ImageNameSubscriber(
         "Select the image on which to display the measurements", cps.NONE, doc="""
         Choose the image to be displayed behind the measurements.
         This can be any image created or loaded by a previous module.
         If you have chosen not to display the background image, the image
         will only be used to determine the dimensions of the displayed image""")
     
     self.color_or_text = cps.Choice(
         "Display mode", [CT_TEXT, CT_COLOR],
         doc = """<i>(Used only when displaying object measurements)</i><br>
         Choose how to display the measurement information. If you choose
         %(CT_TEXT)s, <b>DisplayDataOnImage</b> will display the numeric
         value on top of each object. If you choose %(CT_COLOR)s,
         <b>DisplayDataOnImage</b> will convert the image to grayscale, if
         necessary, and display the portion of the image within each object
         using a hue that indicates the measurement value relative to
         the other objects in the set using the default color map.
         """ % globals()
         )
     
     self.colormap = cps.Colormap(
         "Color map",
         doc = """<i>(Used only when displaying object measurements)</i><br>
         This is the color map used as the color gradient for coloring the
         objects by their measurement values.
         """)        
     self.text_color = cps.Color(
         "Text color","red",doc="""
         This is the color that will be used when displaying the text.
         """)
     
     self.display_image = cps.ImageNameProvider(
         "Name the output image that has the measurements displayed","DisplayImage",doc="""
         The name that will be given to the image with
         the measurements superimposed. You can use this name to refer to the image in
         subsequent modules (such as <b>SaveImages</b>).""")
     
     self.font_size = cps.Integer(
         "Font size (points)", 10, minval=1)
     
     self.decimals = cps.Integer(
         "Number of decimals", 2, minval=0)
     
     self.saved_image_contents = cps.Choice(
         "Image elements to save",
         [E_IMAGE, E_FIGURE, E_AXES],doc="""
         This setting controls the level of annotation on the image:
         <ul>
         <li><i>%(E_IMAGE)s:</i> Saves the image with the overlaid measurement annotations.</li>
         <li><i>%(E_AXES)s:</i> Adds axes with tick marks and image coordinates.</li>
         <li><i>%(E_FIGURE)s:</i> Adds a title and other decorations.</li></ul>"""%globals())
     
     self.offset = cps.Integer(
         "Annotation offset (in pixels)",0,doc="""
         Add a pixel offset to the measurement. Normally, the text is
         placed at the object (or image) center, which can obscure relevant features of
         the object. This setting adds a specified offset to the text, in a random
         direction.""")
     
     self.color_map_scale_choice = cps.Choice(
         "Color map scale",
         [CMS_USE_MEASUREMENT_RANGE, CMS_MANUAL],
         doc = """<i>(Used only when displaying object measurements as a 
         colormap)</i><br>
         <b>DisplayDataOnImage</b> assigns a color to each object's
         measurement value from a colormap when in colormap-mode, mapping
         the value to a color along the colormap's continuum. This mapping
         has implicit upper and lower bounds to its range which are the
         extremes of the colormap. This setting determines whether the
         extremes are the minimum and maximum values of the measurement
         from among the objects in the current image or manually-entered
         extremes. Choose <i>%(CMS_USE_MEASUREMENT_RANGE)s</i> to use
         the full range of colors to get the maximum contrast within the
         image. Choose <i>%(CMS_MANUAL)s</i> to manually set the upper and
         lower bounds so that images with different maxima and minima
         can be compared by a uniform color mapping.
         """ % globals())
     self.color_map_scale = cps.FloatRange(
         "Color map range", 
         value = (0.0, 1.0),
         doc = """<i>(Used only when setting a manual colormap range)</i><br>
         This setting determines the lower and upper bounds of the values
         for the color map.
         """)
    def get_command_settings(self, command, d):
        '''Get the settings associated with the current command
        
        d - the dictionary that persists the setting. None = regular
        '''
        key = command.get_unicode_value()
        if not d.has_key(key):
            if bioformats.USE_IJ2:
                try:
                    module_info = command.get_selected_leaf()[2]
                except cps.ValidationError:
                    return []
                result = []
                inputs = module_info.getInputs()
                module = module_info.createModule()
                implied_outputs = []
                for module_item in inputs:
                    field_type = module_item.getType()
                    label = module_item.getLabel()
                    value = module_item.getValue(module)
                    minimum = module_item.getMinimumValue()
                    maximum = module_item.getMaximumValue()
                    description = module_item.getDescription()
                    if field_type == IJ2.FT_BOOL:
                        setting = cps.Binary(label,
                                             J.call(value, "booleanValue",
                                                    "()Z"),
                                             doc=description)
                    elif field_type == IJ2.FT_INTEGER:
                        if minimum is not None:
                            minimum = J.call(minimum, "intValue", "()I")
                        if maximum is not None:
                            maximum = J.call(maximum, "intValue", "()I")
                        setting = cps.Integer(label,
                                              J.call(value, "intValue", "()I"),
                                              minval=minimum,
                                              maxval=maximum,
                                              doc=description)
                    elif field_type == IJ2.FT_FLOAT:
                        if minimum is not None:
                            minimum = J.call(minimum, "floatValue", "()F")
                        if maximum is not None:
                            maximum = J.call(maximum, "floatValue", "()F")
                        setting = cps.Float(label,
                                            J.call(value, "floatValue", "()F"),
                                            minval=minimum,
                                            maxval=maximum,
                                            doc=description)
                    elif field_type == IJ2.FT_STRING:
                        choices = module_item.getChoices()
                        value = J.to_string(value)
                        if choices is not None:
                            choices = [
                                J.to_string(choice)
                                for choice in J.iterate_collection(choices)
                            ]
                            setting = cps.Choice(label,
                                                 choices,
                                                 value,
                                                 doc=description)
                        else:
                            setting = cps.Text(label, value, doc=description)
                    elif field_type == IJ2.FT_COLOR:
                        if value is not None:
                            value = IJ2.color_rgb_to_html(value)
                        else:
                            value = "#ffffff"
                        setting = cps.Color(label, value, doc=description)
                    elif field_type == IJ2.FT_IMAGE:
                        setting = cps.ImageNameSubscriber(label,
                                                          "InputImage",
                                                          doc=description)
                        #
                        # This is a Display for ij2 - the plugin typically
                        # scribbles all over the display's image. So
                        # we list it as an output too.
                        #
                        implied_outputs.append(
                            (cps.ImageNameProvider(label,
                                                   "OutputImage",
                                                   doc=description),
                             module_item))
                    elif field_type == IJ2.FT_OVERLAY:
                        setting = cps.ObjectNameSubscriber(label,
                                                           "ImageJObject",
                                                           doc=description)
                    else:
                        continue
                    result.append((setting, module_item))
                for output in module_info.getOutputs():
                    field_type = output.getType()
                    if field_type == IJ2.FT_IMAGE:
                        result.append(
                            (cps.ImageNameProvider(label,
                                                   "ImageJImage",
                                                   doc=description), output))
                result += implied_outputs
                d[key] = result
                return [setting for setting, module_info in result]
            else:
                cc = self.get_cached_commands()
                if (not cc.has_key(key)) or (cc[key] is None):
                    return []
                classname = cc[key]
                try:
                    plugin = M.get_plugin(classname)
                except:
                    d[key] = []
                    return []
                fp_in = P.get_input_fields_and_parameters(plugin)
                result = []
                for field, parameter in fp_in:
                    field_type = P.get_field_type(field)
                    label = parameter.label() or ""
                    if field_type == P.FT_BOOL:
                        result += [cps.Binary(label, field.getBoolean(plugin))]
                    elif field_type == P.FT_INTEGER:
                        result += [cps.Integer(label, field.getLong(plugin))]
                    elif field_type == P.FT_FLOAT:
                        result += [cps.Float(label, field.getDouble(plugin))]
                    elif field_type == P.FT_STRING:
                        result += [
                            cps.Text(label, J.to_string(field.get(plugin)))
                        ]
                    else:
                        assert field_type == P.FT_IMAGE
                        result += [cps.ImageNameSubscriber(label, "None")]

                fp_out = P.get_output_fields_and_parameters(plugin)
                for field, parameter in fp_out:
                    field_type = P.get_field_type(field)
                    if field_type == P.FT_IMAGE:
                        result += [
                            cps.ImageNameProvider(parameter.label() or "",
                                                  "Output")
                        ]
            d[key] = result
        elif bioformats.USE_IJ2:
            result = [setting for setting, module_info in d[key]]
        else:
            result = d[key]
        return result