示例#1
0
    def add_heatmap(self):
        group = cps.SettingsGroup()
        if len(self.heatmaps) > 0:
            group.append("divider", cps.Divider(line=False))
        group.append("image_name", MORDImageNameSubscriber(
                "Image", doc="""
            The heatmap will be displayed with measurements taken using this image.
            The setting will let you choose from among the images you have
            specified in "Select image to measure".
            """))
        group.image_name.set_module(self)
        group.append("object_name", MORDObjectNameSubscriber(
                "Objects to display", doc="""
            The objects to display in the heatmap. You can select any of the
            objects chosen in "Select objects to measure".
            """))
        group.object_name.set_module(self)
        group.append("bin_count", cps.Choice(
                "Number of bins", self.get_bin_count_choices(),
                choices_fn=self.get_bin_count_choices))

        def get_number_of_bins(module=self, group=group):
            if len(module.bin_counts) == 1:
                return module.bin_counts[0].bin_count.value
            else:
                return int(group.bin_count.value)

        group.get_number_of_bins = get_number_of_bins

        group.append("measurement", cps.Choice(
                "Measurement", MEASUREMENT_CHOICES,
                doc="""The measurement to display."""))
        group.append("colormap", cps.Colormap(
                "Color map",
                doc="""
            The color map setting chooses the color palette that will be
            used to render the different values for your measurement. If you
            choose "gray", the image will label each of the bins with the
            actual image measurement.
            """))
        group.append("wants_to_save_display", cps.Binary(
                "Save display as image?", False,
                doc="""This setting allows you to save the heatmap display as
            an image that can be output using the <b>SaveImages</b> module.
            Choose <i>%(YES)s</i> to save the display or <i>%(NO)s</i> if the
            display is not needed.""" % globals()))
        group.append("display_name", cps.ImageNameProvider(
                "Output image name", "Heatmap",
                doc="""
            <i>(Only used if "Save display as image?" is "%(YES)s")</i><br>
            This setting names the heatmap image so that the name you enter
            here can be selected in a later <b>SaveImages</b> or other module.
            """ % globals()))
        group.append("remover", cps.RemoveSettingButton(
                "", "Remove this heatmap display", self.heatmaps, group))
        self.heatmaps.append(group)
示例#2
0
    def create_settings(self):
        self.object_name = cps.ObjectNameSubscriber("Select the input objects",
                                                    cps.NONE,
                                                    doc="""
            Choose the name of the objects you want to convert to an image.""")

        self.image_name = cps.ImageNameProvider("Name the output image",
                                                "CellImage",
                                                doc="""
            Enter the name of the resulting image.""")

        self.image_mode = cps.Choice("Select the color format",
                                     IM_ALL,
                                     doc="""
            Select which colors the resulting image should use. You have the following
            options:
            <ul>
            <li><i>%(IM_COLOR)s:</i> Allows you to choose a colormap that will
            produce jumbled colors for your objects. </li>
            <li><i>%(IM_BINARY)s:</i> All object pixels will be assigned 1 and all
            background pixels will be assigned 0, creating a binary image.</li>
            <li><i>%(IM_GRAYSCALE)s:</i> Gives each object
            a graylevel pixel intensity value corresponding to its number (also
            called label), so it usually results in objects on the left side of the
            image being very dark, progressing toward white on the right side of
            the image. </li>
            <li><i>%(IM_UINT16)s:</i> Assigns each object a different number,
            from 1 to 65535 (the numbers that you can put in
            a 16-bit integer) and numbers all pixels in each
            object with the object's number. This format can
            be written out as a .mat or .tiff file if you
            want to process the label matrix image using
            another program.</li>
            </ul>
            You can choose <i>%(IM_COLOR)s</i> with a <i>Gray</i> colormap to produce
            jumbled gray objects.""" % globals())

        self.colormap = cps.Colormap("Select the colormap",
                                     doc="""
            <i>(Used only if "<i>%(IM_COLOR)s</i>" output image selected)</i><br>
            Choose the colormap to be used, which affects how the objects are colored.
            You can look up your default colormap under <i>File > Preferences</i>.
            """ % globals())
    def create_settings(self):
        self.object_name = cps.ObjectNameSubscriber(
            'Select objects to measure',
            cps.NONE,
            doc="""
            Select the objects whose neighbors you want to measure.""")

        self.neighbors_name = cps.ObjectNameSubscriber(
            'Select neighboring objects to measure',
            cps.NONE,
            doc="""
            This is the name of the objects that are potential
            neighbors of the above objects. You can find the neighbors
            within the same set of objects by selecting the same objects
            as above.""")

        self.distance_method = cps.Choice('Method to determine neighbors',
                                          D_ALL,
                                          D_EXPAND,
                                          doc="""
            There are several methods by which to determine whether objects are neighbors:
            <ul>
            <li><i>%(D_ADJACENT)s:</i> In this mode, two objects must have adjacent
            boundary pixels to be neighbors. </li>
            <li><i>%(D_EXPAND)s:</i> The objects are expanded until all
            pixels on the object boundaries are touching another. Two objects are
            neighbors if any of their boundary pixels are adjacent after
            expansion.</li>
            <li><i>%(D_WITHIN)s:</i> Each object is expanded by
            the number of pixels you specify. Two objects are
            neighbors if they have adjacent pixels after expansion. </li>
            </ul>

            <p>For <i>%(D_ADJACENT)s</i> and <i>%(D_EXPAND)s</i>, the
            <i>%(M_PERCENT_TOUCHING)s</i> measurement is the percentage of pixels on the boundary
            of an object that touch adjacent objects. For <i>%(D_WITHIN)s</i>,
            two objects are touching if any of their boundary
            pixels are adjacent after expansion and <i>%(M_PERCENT_TOUCHING)s</i> measures the
            percentage of boundary pixels of an <i>expanded</i> object that
            touch adjacent objects.</p>""" % globals())

        self.distance = cps.Integer('Neighbor distance',
                                    5,
                                    1,
                                    doc="""
            <i>(Used only when "%(D_WITHIN)s" is selected)</i> <br>
            The Neighbor distance is the number of pixels that each object is
            expanded for the neighbor calculation. Expanded objects that touch
            are considered neighbors.""" % globals())

        self.wants_count_image = cps.Binary(
            'Retain the image of objects colored by numbers of neighbors?',
            False,
            doc="""
            An output image showing the input objects
            colored by numbers of neighbors may be retained. A colormap of your choice shows
            how many neighbors each object has. The background is set
            to -1. Objects are colored with an increasing color value
            corresponding to the number of neighbors, such that objects with no
            neighbors are given a color corresponding to 0. Use the <b>SaveImages</b>
            module to save this image to a file.""")

        self.count_image_name = cps.ImageNameProvider('Name the output image',
                                                      'ObjectNeighborCount',
                                                      doc="""
            <i>(Used only if the image of objects colored by numbers of neighbors
            is to be retained for later use in the pipeline)</i> <br>
            Specify a name
            that will allow the image of objects colored by numbers of neighbors
            to be selected later in the pipeline.""")

        self.count_colormap = cps.Colormap('Select colormap',
                                           doc="""
            <i>(Used only if the image of objects colored by numbers of neighbors
            is to be retained for later use in the pipeline)</i> <br>
            Select the colormap to use to color the neighbor number image. All available colormaps can be seen
            <a href="http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps">here</a>."""
                                           )

        self.wants_percent_touching_image = cps.Binary(
            'Retain the image of objects colored by percent of touching pixels?',
            False,
            doc="""
            Select <i>%(YES)s</i> to keep an image of the input objects
            colored by the percentage of the boundary touching their neighbors.
            A colormap of your choice is used to show the touching percentage of
            each object. Use the <b>SaveImages</b> module to save this image to a file."""
            % globals())

        self.touching_image_name = cps.ImageNameProvider(
            'Name the output image',
            'PercentTouching',
            doc="""
            <i>(Used only if the image of objects colored by percent touching
            is to be retained for later use in the pipeline)</i> <br>
            Specify a name that will allow the image of objects colored by percent of touching
            pixels to be selected later in the pipeline.""")

        self.touching_colormap = cps.Colormap('Select a colormap',
                                              doc="""
            <i>(Used only if the image of objects colored by percent touching
            is to be retained for later use in the pipeline)</i> <br>
            Select the colormap to use to color the percent touching image. All available colormaps can be seen
            <a href="http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps">here</a>."""
                                              )
示例#4
0
    def create_settings(self):
        self.object_name = cps.ObjectNameSubscriber(
            'Select objects to measure',
            cps.NONE,
            doc="""\
Select the objects whose neighbors you want to measure.""")

        self.neighbors_name = cps.ObjectNameSubscriber(
            'Select neighboring objects to measure',
            cps.NONE,
            doc="""\
This is the name of the objects that are potential
neighbors of the above objects. You can find the neighbors
within the same set of objects by selecting the same objects
as above.""")

        self.distance_method = cps.Choice('Method to determine neighbors',
                                          D_ALL,
                                          D_EXPAND,
                                          doc="""\
There are several methods by which to determine whether objects are
neighbors:

-  *%(D_ADJACENT)s:* In this mode, two objects must have adjacent
   boundary pixels to be neighbors.
-  *%(D_EXPAND)s:* The objects are expanded until all pixels on the
   object boundaries are touching another. Two objects are neighbors if
   any of their boundary pixels are adjacent after expansion.
-  *%(D_WITHIN)s:* Each object is expanded by the number of pixels you
   specify. Two objects are neighbors if they have adjacent pixels after
   expansion.

For *%(D_ADJACENT)s* and *%(D_EXPAND)s*, the
*%(M_PERCENT_TOUCHING)s* measurement is the percentage of pixels on
the boundary of an object that touch adjacent objects. For
*%(D_WITHIN)s*, two objects are touching if any of their boundary
pixels are adjacent after expansion and *%(M_PERCENT_TOUCHING)s*
measures the percentage of boundary pixels of an *expanded* object that
touch adjacent objects.
""" % globals())

        self.distance = cps.Integer('Neighbor distance',
                                    5,
                                    1,
                                    doc="""\
*(Used only when “%(D_WITHIN)s” is selected)*

The Neighbor distance is the number of pixels that each object is
expanded for the neighbor calculation. Expanded objects that touch are
considered neighbors.
""" % globals())

        self.wants_count_image = cps.Binary(
            'Retain the image of objects colored by numbers of neighbors?',
            False,
            doc="""\
An output image showing the input objects colored by numbers of
neighbors may be retained. A colormap of your choice shows how many
neighbors each object has. The background is set to -1. Objects are
colored with an increasing color value corresponding to the number of
neighbors, such that objects with no neighbors are given a color
corresponding to 0. Use the **SaveImages** module to save this image to
a file.""")

        self.count_image_name = cps.ImageNameProvider('Name the output image',
                                                      'ObjectNeighborCount',
                                                      doc="""\
*(Used only if the image of objects colored by numbers of neighbors is
to be retained for later use in the pipeline)*

Specify a name that will allow the image of objects colored by numbers
of neighbors to be selected later in the pipeline.""")

        self.count_colormap = cps.Colormap('Select colormap',
                                           doc="""\
*(Used only if the image of objects colored by numbers of neighbors is
to be retained for later use in the pipeline)*

Select the colormap to use to color the neighbor number image. All
available colormaps can be seen `here`_.

.. _here: http://matplotlib.org/examples/color/colormaps_reference.html""")

        self.wants_percent_touching_image = cps.Binary(
            'Retain the image of objects colored by percent of touching pixels?',
            False,
            doc="""\
Select *%(YES)s* to keep an image of the input objects colored by the
percentage of the boundary touching their neighbors. A colormap of your
choice is used to show the touching percentage of each object. Use the
**SaveImages** module to save this image to a file.
""" % globals())

        self.touching_image_name = cps.ImageNameProvider(
            'Name the output image',
            'PercentTouching',
            doc="""\
*(Used only if the image of objects colored by percent touching is to be
retained for later use in the pipeline)*

Specify a name that will allow the image of objects colored by percent
of touching pixels to be selected later in the pipeline.""")

        self.touching_colormap = cps.Colormap('Select colormap',
                                              doc="""\
*(Used only if the image of objects colored by percent touching is to be
retained for later use in the pipeline)*

Select the colormap to use to color the percent touching image. All
available colormaps can be seen `here`_.

.. _here: http://matplotlib.org/examples/color/colormaps_reference.html""")
    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="""\
-  *%(OI_OBJECTS)s* displays measurements made on objects.
-  *%(OI_IMAGE)s* displays a single measurement made on an image.
""" % globals())

        self.objects_name = cps.ObjectNameSubscriber(
            "Select the input objects",
            cps.NONE,
            doc="""\
*(Used only when displaying object measurements)*

Choose the name of objects identified by some previous module (such as
**IdentifyPrimaryObjects** or **IdentifySecondaryObjects**).
""")

        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="""\
*(Used only when displaying object measurements)*

Choose how to display the measurement information. If you choose
%(CT_TEXT)s, **DisplayDataOnImage** will display the numeric value on
top of each object. If you choose %(CT_COLOR)s, **DisplayDataOnImage**
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="""\
*(Used only when displaying object measurements)*

This is the color map used as the color gradient for coloring the
objects by their measurement values. See `this page`_ for pictures
of the available colormaps.

.. _this page: http://matplotlib.org/users/colormaps.html
            """)
        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 **SaveImages**).
""")

        self.font_size = cps.Integer(
            "Font size (points)",
            10,
            minval=1,
            doc="""Set the font size of the letters to be displayed.""")

        self.decimals = cps.Integer(
            "Number of decimals",
            2,
            minval=0,
            doc=
            """Set how many decimals to be displayed, for example 2 decimals for 0.01; 3 decimals for 0.001."""
        )

        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:

-  *%(E_IMAGE)s:* Saves the image with the overlaid measurement
   annotations.
-  *%(E_AXES)s:* Adds axes with tick marks and image coordinates.
-  *%(E_FIGURE)s:* Adds a title and other decorations.
""" % 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="""\
*(Used only when displaying object measurements as a colormap)*

**DisplayDataOnImage** 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.

-  *%(CMS_USE_MEASUREMENT_RANGE)s:* Use the full range of colors to
   get the maximum contrast within the image.
-  *%(CMS_MANUAL)s:* 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="""\
*(Used only when setting a manual colormap range)*

This setting determines the lower and upper bounds of the values for the
color map.
""")