示例#1
0
    def create_settings(self):
        self.object_name = cps.ObjectNameSubscriber("Select the input objects",
                                                    cps.NONE,
                                                    doc='''
            Select the objects that you want to rescale.''')

        self.output_object_name = cps.ObjectNameProvider(
            "Name the output objects",
            "RescaledObject",
            doc='''
            Enter a name for the resulting objects.''')

        self.operation = cps.Choice("Select the operation",
                                    O_ALL,
                                    doc='''
            Select the operation that you want to perform:
            <ul>
            <li><i>%(O_DOWNSCALE)s:</i> Downscale the Object Masks to a smaller image size.</li>
            <li><i>%(O_UPSCALE)s:</i> Expand objects, assigning every pixel in the image to an
            object. Background pixels are assigned to the nearest object.</li>
            </ul>''' % globals())

        self.scaling = cps.Float("Factor to scale the object mask",
                                 1,
                                 minval=0)
示例#2
0
    def create_settings(self):
        """Create the settings for the module

        Create the settings for the module during initialization.
        """
        self.secondary_objects_name = cps.ObjectNameSubscriber(
            "Select the larger identified objects",
            cps.NONE,
            doc="""
            Select the larger identified objects. This will usually
            be an object previously identified by a <b>IdentifySecondaryObjects</b>
            module.""")

        self.primary_objects_name = cps.ObjectNameSubscriber(
            "Select the smaller identified objects",
            cps.NONE,
            doc="""
            Select the smaller identified objects. This will usually
            be an object previously identified by a <b>IdentifyPrimaryObjects</b>
            module.""")

        self.subregion_objects_name = cps.ObjectNameProvider(
            "Name the tertiary objects to be identified",
            "Cytoplasm",
            doc="""
            Enter a name for the new tertiary objects. The tertiary objects
            will consist of the smaller object subtracted from the larger object."""
        )

        self.shrink_primary = cps.Binary(
            "Shrink smaller object prior to subtraction?",
            True,
            doc="""
            Select <i>%(YES)s</i> to shrink the smaller object by 1 pixel before subtracting the objects.
            this approach will ensure that there is always a tertiary object produced, even if it is
            only 1 pixel wide.
            <p>Select <i>%(NO)s</i> to subtract the objects directly, which will ensure that no pixels
            are shared between the primary/secondary/tertiary objects and hence measurements for all
            three sets of objects will not use the same pixels multiple times. However, this may result
            in the creation of objects with no area. Measurements can still be made on such objects, but
            the results will be zero or not-a-number (NaN)</p>""" % globals())

        self.use_outlines = cps.Binary(
            "Retain outlines of the tertiary objects?",
            False,
            doc="""
            %(RETAINING_OUTLINES_HELP)s""" % globals())

        self.outlines_name = cps.OutlineNameProvider("Name the outline image",
                                                     "CytoplasmOutlines",
                                                     doc="""
            %(NAMING_OUTLINES_HELP)s""" % globals())
示例#3
0
    def create_settings(self) -> None:
        module_explanation = "Creates a binary mask of the wedge."
        self.set_notes([module_explanation])

        self.wedge_mask_name = cps.ObjectNameProvider(
            text="Name the wedge mask",
            value="WedgeMask",
            doc="Enter the name of the wedge mask.",
        )

        self.image_name = cps.ImageNameProvider(
            text="Select image to overlay on",
            value="None",
            doc="""\
Choose the image_name upon which a wedge mask constructed from the given 
parameters is laid. Can be either RGB or grayscale.
""",
        )

        self.divider = cps.Divider(line=True)

        self.thickness = cps.Float(text="Enter thickness of wedge (um)",
                                   value=400.0,
                                   doc="")

        self.span = cps.Float(text="Enter span of wedge (deg)",
                              value=90.0,
                              doc="")

        self.radial_offset = cps.Float(
            text="Enter radial offset",
            value=0.0,
            doc=
            "Enter offset of the inner edge of wedge from well, in microns.",
        )

        self.angular_offset = cps.Float(
            text="Enter angular offset",
            value=0.0,
            doc="""\
Enter offset of the wedge midline from well midline, in degrees, clockwise positive.
""",
        )

        self.mask_color = cps.Color(
            text="Select wedge fill color",
            value=DEFAULT_MASK_COLOR,
            doc="""\
The wedge is outlined in this color. Only applies when the result of this 
module is visualized.""",
        )
    def create_settings(self):
        self.image_name = cps.ImageNameSubscriber(
            "Select the input image",
            cps.NONE,
            doc=
            """Choose the name of the image to display in the object selection user interface."""
        )

        self.objects_name = cps.ObjectNameProvider(
            "Name the objects to be identified",
            "Cells",
            doc="""\
What do you want to call the objects that you identify using this module? You can use this name to
refer to your objects in subsequent modules.""")
示例#5
0
    def create_settings(self):
        """Create the settings for the module

        Create the settings for the module during initialization.
        """
        self.secondary_objects_name = cps.ObjectNameSubscriber(
            "Select the larger identified objects",
            cps.NONE,
            doc="""\
Select the larger identified objects. This will usually be an object
previously identified by an **IdentifySecondaryObjects** module.""",
        )

        self.primary_objects_name = cps.ObjectNameSubscriber(
            "Select the smaller identified objects",
            cps.NONE,
            doc="""\
Select the smaller identified objects. This will usually be an object
previously identified by an **IdentifyPrimaryObjects** module.""",
        )

        self.subregion_objects_name = cps.ObjectNameProvider(
            "Name the tertiary objects to be identified",
            "Cytoplasm",
            doc="""\
Enter a name for the new tertiary objects. The tertiary objects
will consist of the smaller object subtracted from the larger object.""",
        )

        self.shrink_primary = cps.Binary(
            "Shrink smaller object prior to subtraction?",
            True,
            doc="""\
Select *Yes* to shrink the smaller objects by 1 pixel before
subtracting them from the larger objects. this approach will ensure that
there is always a tertiary object produced, even if it is only 1 pixel wide.
If you need alternate amounts of shrinking, use the **ExpandOrShrink**
module prior to **IdentifyTertiaryObjects**.

Select *No* to subtract the objects directly, which will ensure that
no pixels are shared between the primary/secondary/tertiary objects and
hence measurements for all three sets of objects will not use the same
pixels multiple times. However, this may result in the creation of
objects with no area. Measurements can still be made on such objects,
but the results will be zero or not-a-number (NaN).
""" % globals(),
        )
示例#6
0
    def create_settings(self):
        self.image_name = cps.ImageNameSubscriber(
                "Select the input image", cps.NONE, doc="""
            Choose the name of the image to display in the object
            selection user interface.""")

        self.objects_name = cps.ObjectNameProvider(
                "Name the objects to be identified", "Cells", doc="""
            What do you want to call the objects
            that you identify using this module? You can use this name to
            refer to your objects in subsequent modules.""")

        self.wants_outlines = cps.Binary(
                "Retain outlines of the identified objects?", False, doc="""
            %(RETAINING_OUTLINES_HELP)s""" % globals())

        self.outlines_name = cps.OutlineNameProvider(
                "Name the outlines", "CellOutlines", doc="""
            %(NAMING_OUTLINES_HELP)s""" % globals())
示例#7
0
    def create_settings(self) -> None:
        self.input_mask_name = cps.ObjectNameSubscriber(
            text="Select the input mask", value=cps.NONE, doc="")

        self.padding = cps.Integer(text="Enter padding size (px)",
                                   value=20,
                                   doc="")

        self.output_mask_name = cps.ObjectNameProvider(
            text="Name the output mask",
            value="PaddedMask",
            doc="Enter the name of the output mask",
        )

        self.custom = cps.Binary(text="Use custom settings?",
                                 value="No",
                                 doc="Use custom settings")

        self.divider = cps.Divider(line=True)

        self.image_name = cps.ImageNameSubscriber(
            text="Select image to overlay on",
            value=cps.LEAVE_BLANK,
            doc="""\
Choose the image_name upon which a padded mask constructed from the input_mask is laid.
""",
            can_be_blank=True,
        )

        self.input_mask_color = cps.Color(
            text="Select the input mask color",
            value="red",
            doc="Select the input mask color",
        )

        self.output_mask_color = cps.Color(
            text="Select the output mask color",
            value="blue",
            doc="Select the output mask color",
        )
示例#8
0
    def create_settings(self):
        self.objects_name = cps.ObjectNameSubscriber(
            "Select the input objects",
            cps.NONE,
            doc="""\
Select the objects you would like to split or merge (that is,
whose object numbers you want to reassign). You can
use any objects that were created in previous modules, such as
**IdentifyPrimaryObjects** or **IdentifySecondaryObjects**.""")

        self.output_objects_name = cps.ObjectNameProvider(
            "Name the new objects",
            "RelabeledNuclei",
            doc="""\
Enter a name for the objects that have been split or merged (that is,
whose numbers have been reassigned).
You can use this name in subsequent modules that take objects as inputs.""")

        self.relabel_option = cps.Choice("Operation",
                                         [OPTION_MERGE, OPTION_SPLIT],
                                         doc="""\
You can choose one of the following options:

-  *%(OPTION_MERGE)s:* Assign adjacent or nearby objects the same label
   based on certain criteria. It can be useful, for example, to merge
   together touching objects that were incorrectly split into two pieces
   by an **Identify** module.
-  *%(OPTION_SPLIT)s:* Assign a unique number to separate objects that
   currently share the same label. This can occur if you applied certain
   operations in the **Morph** module to objects.""" % globals())

        self.merge_option = cps.Choice("Merging method",
                                       [UNIFY_DISTANCE, UNIFY_PARENT],
                                       doc="""\
*(Used only with the "%(OPTION_MERGE)s" option)*

You can merge objects in one of two ways:

-  *%(UNIFY_DISTANCE)s:* All objects within a certain pixel radius from
   each other will be merged.
-  *%(UNIFY_PARENT)s:* All objects which share the same parent
   relationship to another object will be merged. This is not to be
   confused with using the **RelateObjects** module, in which the
   related objects remain as individual objects. See **RelateObjects**
   for more details.""" % globals())

        self.merging_method = cps.Choice("Output object type",
                                         [UM_DISCONNECTED, UM_CONVEX_HULL],
                                         doc="""\
*(Used only with the "%(UNIFY_PARENT)s" merging method)*

**SplitOrMergeObjects** can either merge the child objects and keep them
disconnected or it can find the smallest convex polygon (the convex
hull) that encloses all of a parent’s child objects. The convex hull
will be truncated to include only those pixels in the parent - in that
case it may not truly be convex. Choose *%(UM_DISCONNECTED)s* to leave
the children as disconnected pieces. Choose *%(UM_CONVEX_HULL)s* to
create an output object that is the convex hull around them all.""" %
                                         globals())

        self.parent_object = cps.Choice("Select the parent object", [cps.NONE],
                                        choices_fn=self.get_parent_choices,
                                        doc="""\
Select the parent object that will be used to merge the child objects.
Please note the following:

-  You must have established a parent-child relationship between the
   objects using a prior **RelateObjects** module.
-  Primary objects and their associated secondary objects are already in
   a one-to-one parent-child relationship, so it makes no sense to merge
   them here.""")

        self.distance_threshold = cps.Integer(
            "Maximum distance within which to merge objects",
            0,
            minval=0,
            doc="""\
*(Used only with the "%(OPTION_MERGE)s" option and the "%(UNIFY_DISTANCE)s"
method)*

Objects that are less than or equal to the distance you enter here, in
pixels, will be merged. If you choose zero (the default), only objects
that are touching will be merged. Note that *%(OPTION_MERGE)s* will
not actually connect or bridge the two objects by adding any new pixels;
it simply assigns the same object number to the portions of the object.
The new, merged object may therefore consist of two or more unconnected
components. If you want to add pixels around objects, see
**ExpandOrShrink** or **Morph**.""" % globals())

        self.wants_image = cps.Binary("Merge using a grayscale image?",
                                      False,
                                      doc="""\
*(Used only with the "%(OPTION_MERGE)s" option)*

Select *%(YES)s* to use the objects’ intensity features to determine
whether two objects should be merged. If you choose to use a grayscale
image, *%(OPTION_MERGE)s* will merge two objects only if they are
within the distance you have specified *and* certain criteria about the
objects within the grayscale image are met.""" % globals())

        self.image_name = cps.ImageNameSubscriber(
            "Select the grayscale image to guide merging",
            cps.NONE,
            doc="""\
*(Used only if a grayscale image is to be used as a guide for
merging)*

Select the name of an image loaded or created by a previous module.""")

        self.minimum_intensity_fraction = cps.Float(
            "Minimum intensity fraction",
            .9,
            minval=0,
            maxval=1,
            doc="""\
*(Used only if a grayscale image is to be used as a guide for
merging)*

Select the minimum acceptable intensity fraction. This will be used as
described for the method you choose in the next setting.""")

        self.where_algorithm = cps.Choice("Method to find object intensity",
                                          [CA_CLOSEST_POINT, CA_CENTROIDS],
                                          doc="""\
*(Used only if a grayscale image is to be used as a guide for
merging)*

You can use one of two methods to determine whether two objects should
merged, assuming they meet the distance criteria (as specified
above):

-  *%(CA_CENTROIDS)s:* When the module considers merging two objects,
   this method identifies the centroid of each object, records the
   intensity value of the dimmer of the two centroids, multiplies this
   value by the *minimum intensity fraction* to generate a threshold,
   and draws a line between the centroids. The method will merge the two
   objects only if the intensity of every point along the line is above
   the threshold. For instance, if the intensity of one centroid is 0.75
   and the other is 0.50 and the *minimum intensity fraction* has been
   chosen to be 0.9, all points along the line would need to have an
   intensity of min(0.75, 0.50) \* 0.9 = 0.50 \* 0.9 = 0.45.
   This method works well for round cells whose maximum intensity is in
   the center of the cell: a single cell that was incorrectly segmented
   into two objects will typically not have a dim line between the
   centroids of the two halves and will be correctly merged.
-  *%(CA_CLOSEST_POINT)s:* This method is useful for unifying
   irregularly shaped cells that are connected. It starts by assigning
   background pixels in the vicinity of the objects to the nearest
   object. Objects are then merged if each object has background pixels
   that are:

   -  Within a distance threshold from each object;
   -  Above the minimum intensity fraction of the nearest object pixel;
   -  Adjacent to background pixels assigned to a neighboring object.

   An example of a feature that satisfies the above constraints is a
   line of pixels that connects two neighboring objects and is roughly
   the same intensity as the boundary pixels of both (such as an axon
   connecting two neurons' soma).""" % globals())
示例#9
0
    def create_settings(self):
        '''Create the settings that control this module'''
        self.object_name = cps.ObjectNameSubscriber(
            "Select objects to be masked",
            cps.NONE,
            doc="""\
Select the objects that will be masked (that is, excluded in whole or in
part based on the other settings in the module). You can choose from any
objects created by a previous object processing module, such as
**IdentifyPrimaryObjects**, **IdentifySecondaryObjects** or
**IdentifyTertiaryObjects**.
""")

        self.remaining_objects = cps.ObjectNameProvider(
            "Name the masked objects",
            "MaskedNuclei",
            doc="""\
Enter a name for the objects that remain after
the masking operation. You can refer to the masked objects in
subsequent modules by this name.
""")

        self.mask_choice = cps.Choice(
            "Mask using a region defined by other objects or by binary image?",
            [MC_OBJECTS, MC_IMAGE],
            doc="""\
You can mask your objects by defining a region using objects you
previously identified in your pipeline (*%(MC_OBJECTS)s*) or by
defining a region based on the white regions in a binary image
previously loaded or created in your pipeline (*%(MC_IMAGE)s*).
""" % globals())

        self.masking_objects = cps.ObjectNameSubscriber(
            "Select the masking object",
            cps.NONE,
            doc="""\
*(Used only if mask is to be made from objects)*

Select the objects that will be used to define the masking region. You
can choose from any objects created by a previous object processing
module, such as **IdentifyPrimaryObjects**,
**IdentifySecondaryObjects**, or **IdentifyTertiaryObjects**.
""")

        self.masking_image = cps.ImageNameSubscriber(
            "Select the masking image",
            cps.NONE,
            doc="""\
*(Used only if mask is to be made from an image)*

Select an image that was either loaded or created by a previous module.
The image should be a binary image where the white portion of the image
is the region(s) you will use for masking. Binary images can be loaded
from disk using the **NamesAndTypes** module by selecting “Binary mask”
for the image type. You can also create a binary image from a grayscale
image using **ApplyThreshold**.
""")

        self.wants_inverted_mask = cps.Binary("Invert the mask?",
                                              False,
                                              doc="""\
This option reverses the foreground/background relationship of the mask.

-  Select "*%(NO)s*" for the mask to be composed of the foreground (white
   portion) of the masking image or the area within the masking objects.
-  Select "*%(YES)s*" for the mask to instead be composed of the
   *background* (black portions) of the masking image or the area
   *outside* the masking objects.
   """ % globals())

        self.overlap_choice = cps.Choice(
            "Handling of objects that are partially masked",
            [P_MASK, P_KEEP, P_REMOVE, P_REMOVE_PERCENTAGE],
            doc="""\
An object might partially overlap the mask region, with pixels both
inside and outside the region. **MaskObjects** can handle this in one
of three ways:

-  *%(P_MASK)s:* Choosing this option will reduce the size of partially
   overlapping objects. The part of the object that overlaps the masking
   region will be retained. The part of the object that is outside of the
   masking region will be removed.
-  *%(P_KEEP)s:* If you choose this option, **MaskObjects** will keep
   the whole object if any part of it overlaps the masking region.
-  *%(P_REMOVE)s:* Objects that are partially outside of the masking
   region will be completely removed if you choose this option.
-  *%(P_REMOVE_PERCENTAGE)s:* Determine whether to remove or keep an
   object depending on how much of the object overlaps the masking
   region. **MaskObjects** will keep an object if at least a certain
   fraction (which you enter below) of the object falls within the
   masking region. **MaskObjects** completely removes the object if too
   little of it overlaps the masking region.""" % globals())

        self.overlap_fraction = cps.Float(
            "Fraction of object that must overlap",
            .5,
            minval=0,
            maxval=1,
            doc="""\
*(Used only if removing based on overlap)*

Specify the minimum fraction of an object that must overlap the masking
region for that object to be retained. For instance, if the fraction is
0.75, then 3/4 of an object must be within the masking region for that
object to be retained.
""")

        self.retain_or_renumber = cps.Choice("Numbering of resulting objects",
                                             [R_RENUMBER, R_RETAIN],
                                             doc="""\
Choose how to number the objects that remain after masking, which
controls how remaining objects are associated with their predecessors:

-  *%(R_RENUMBER)s:* The objects that remain will be renumbered using
   consecutive numbers. This is a good choice if you do not plan to use
   measurements from the original objects; your object measurements for
   the masked objects will not have gaps (where removed objects are
   missing).
-  *%(R_RETAIN)s:* The original labels for the objects will be
   retained. This allows any measurements you make from the masked
   objects to be directly aligned with measurements you might have made
   of the original, unmasked objects (or objects directly associated
   with them).
""" % globals())
示例#10
0
    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.object_name = cps.ObjectNameSubscriber(
            "Select the objects to be edited",
            cps.NONE,
            doc="""\
Choose a set of previously identified objects
for editing, such as those produced by one of the
**Identify** modules (e.g., "*IdentifyPrimaryObjects*", "*IdentifySecondaryObjects*" etc.).""",
        )

        self.filtered_objects = cps.ObjectNameProvider(
            "Name the edited objects",
            "EditedObjects",
            doc="""\
Enter the name for the objects that remain
after editing. These objects will be available for use by
subsequent modules.""",
        )

        self.allow_overlap = cps.Binary(
            "Allow overlapping objects?",
            False,
            doc="""\
**EditObjectsManually** can allow you to edit an object so that it
overlaps another or it can prevent you from overlapping one object with
another. Objects such as worms or the neurites of neurons may cross each
other and might need to be edited with overlapping allowed, whereas a
monolayer of cells might be best edited with overlapping off.
Select "*Yes*" to allow overlaps or select "*No*" to prevent them.
""" % globals(),
        )

        self.renumber_choice = cps.Choice(
            "Numbering of the edited objects",
            [R_RENUMBER, R_RETAIN],
            doc="""\
Choose how to number the objects that remain after editing, which
controls how edited objects are associated with their predecessors:

-  *%(R_RENUMBER)s:* The module will number the objects that remain
   using consecutive numbers. This is a good choice if you do not plan
   to use measurements from the original objects and you only want to
   use the edited objects in downstream modules; the objects that remain
   after editing will not have gaps in numbering where removed objects
   are missing.
-  *%(R_RETAIN)s:* This option will retain each object’s original
   number so that the edited object’s number matches its original
   number. This allows any measurements you make from the edited objects
   to be directly aligned with measurements you might have made of the
   original, unedited objects (or objects directly associated with
   them).
""" % globals(),
        )

        self.wants_image_display = cps.Binary(
            "Display a guiding image?",
            True,
            doc="""\
Select "*Yes*" to display an image and outlines of the objects.

Select "*No*" if you do not want a guide image while editing.
""" % globals(),
        )

        self.image_name = cps.ImageNameSubscriber(
            "Select the guiding image",
            cps.NONE,
            doc="""\
*(Used only if a guiding image is desired)*

This is the image that will appear when editing objects. Choose an image
supplied by a previous module.
""",
        )
    def create_settings(self):
        self.primary_objects = cps.ObjectNameSubscriber(
            "Select the input objects",
            "Nuclei",
            doc="""
            What did you call the objects you want to use as "seeds" to identify a secondary
            object around each one? By definition, each primary object must be associated with exactly one
            secondary object and completely contained within it.""")

        self.objects_name = cps.ObjectNameProvider(
            "Name the objects to be identified",
            "Cells",
            doc="""
            Enter the name that you want to call the objects identified by this module."""
        )

        self.method = cps.Choice(
            "Select the method to identify the secondary objects", [
                M_PROPAGATION, M_WATERSHED_G, M_WATERSHED_I, M_DISTANCE_N,
                M_DISTANCE_B
            ],
            M_PROPAGATION,
            doc="""
            <p>There are several methods available to find the dividing lines
            between secondary objects which touch each other:
            <ul>
            <li><i>%(M_PROPAGATION)s:</i> This method will find dividing lines
            between clumped objects where the image stained for secondary objects
            shows a change in staining (i.e., either a dimmer or a brighter line).
            Smoother lines work better, but unlike the Watershed method, small gaps
            are tolerated. This method is considered an improvement on the
            traditional <i>Watershed</i> method. The dividing lines between objects are
            determined by a combination of the distance to the nearest primary object
            and intensity gradients. This algorithm uses local image similarity to
            guide the location of boundaries between cells. Boundaries are
            preferentially placed where the image's local appearance changes
            perpendicularly to the boundary (<i>Jones et al, 2005</i>).</li>

            <li><i>%(M_WATERSHED_G)s:</i> This method uses the watershed algorithm
            (<i>Vincent and Soille, 1991</i>) to assign
            pixels to the primary objects which act as seeds for the watershed.
            In this variant, the watershed algorithm operates on the Sobel
            transformed image which computes an intensity gradient. This method
            works best when the image intensity drops off or increases rapidly
            near the boundary between cells.
            </li>
            <li><i>%(M_WATERSHED_I)s:</i> This method is similar to the above,
            but it uses the inverted intensity of the image for the watershed.
            The areas of lowest intensity will form the boundaries between
            cells. This method works best when there is a saddle of relatively
            low intensity at the cell-cell boundary.
            </li>
            <li><i>Distance:</i> In this method, the edges of the primary
            objects are expanded a specified distance to create the secondary
            objects. For example, if nuclei are labeled but there is no stain to help
            locate cell edges, the nuclei can simply be expanded in order to estimate
            the cell's location. This is often called the "doughnut" or "annulus" or
            "ring" approach for identifying the cytoplasm.
            There are two methods that can be used:
            <ul>
            <li><i>%(M_DISTANCE_N)s</i>: In this method, the image of the secondary
            staining is not used at all; the expanded objects are the
            final secondary objects.</li>
            <li><i>%(M_DISTANCE_B)s</i>: Thresholding of the secondary staining image is used to eliminate background
            regions from the secondary objects. This allows the extent of the
            secondary objects to be limited to a certain distance away from the edge
            of the primary objects without including regions of background.</li></ul></li>
            </ul>
            <b>References</b>
            <ul>
            <li>Jones TR, Carpenter AE, Golland P (2005) "Voronoi-Based Segmentation of Cells on Image Manifolds",
            <i>ICCV Workshop on Computer Vision for Biomedical Image Applications</i>, 535-543.
            (<a href="http://www.cellprofiler.org/linked_files/Papers/JonesCVBIA2005.pdf">link</a>)</li>
            <li>(Vincent L, Soille P (1991) "Watersheds in Digital Spaces: An Efficient Algorithm Based on Immersion
            Simulations", <i>IEEE Transactions of Pattern Analysis and Machine
            Intelligence</i>, 13(6): 583-598
            (<a href="http://dx.doi.org/10.1109/34.87344">link</a>)</li>
            </ul>""" % globals())

        self.image_name = cps.ImageNameSubscriber("Select the input image",
                                                  cps.NONE,
                                                  doc="""
            The selected image will be used to find the edges of the secondary objects.
            For <i>%(M_DISTANCE_N)s</i> this will not affect object identification,
            only the final display.""" % globals())

        self.create_threshold_settings()
        # default smoothing choice is different for idprimary and idsecondary
        self.threshold_smoothing_choice.value = cpmi.TSM_NONE

        self.distance_to_dilate = cps.Integer(
            "Number of pixels by which to expand the primary objects",
            10,
            minval=1)

        self.regularization_factor = cps.Float("Regularization factor",
                                               0.05,
                                               minval=0,
                                               doc="""
            <i>(Used only if %(M_PROPAGATION)s method is selected)</i> <br>
            The regularization factor &lambda; can be anywhere in the range 0 to infinity.
            This method takes two factors into account when deciding where to draw
            the dividing line between two touching secondary objects: the distance to
            the nearest primary object, and the intensity of the secondary object
            image. The regularization factor controls the balance between these two
            considerations:
            <ul>
            <li>A &lambda; value of 0 means that the distance to the nearest
            primary object is ignored and the decision is made entirely on the
            intensity gradient between the two competing primary objects. </li>
            <li>Larger values of &lambda; put more and more weight on the distance between the two objects.
            This relationship is such that small changes in &lambda; will have fairly different
            results (e.,g 0.01 vs 0.001). However, the intensity image is almost completely
            ignored at &lambda; much greater than 1.</li>
            <li>At infinity, the result will look like %(M_DISTANCE_B)s, masked to the
            secondary staining image.</li>
            </ul>""" % globals())

        self.use_outlines = cps.Binary(
            "Retain outlines of the identified secondary objects?",
            False,
            doc="""
            %(RETAINING_OUTLINES_HELP)s""" % globals())

        self.outlines_name = cps.OutlineNameProvider('Name the outline image',
                                                     "SecondaryOutlines",
                                                     doc="""
            %(NAMING_OUTLINES_HELP)s""" % globals())

        self.wants_discard_edge = cps.Binary(
            "Discard secondary objects touching the border of the image?",
            False,
            doc="""
            Select <i>%(YES)s</i> to discard secondary objects which touch
            the image border. Select <i>%(NO)s</i> to retain objects regardless
            of whether they touch the image edge or not.
            <p>The objects are discarded
            with respect to downstream measurement modules, but they are retained in memory
            as "unedited objects"; this allows them to be considered in downstream modules that modify the
            segmentation.</p>""" % globals())

        self.fill_holes = cps.Binary("Fill holes in identified objects?",
                                     True,
                                     doc="""
            Select <i>%(YES)s</i> to fill any holes inside objects.""" %
                                     globals())

        self.wants_discard_primary = cps.Binary(
            "Discard the associated primary objects?",
            False,
            doc="""
            <i>(Used only if discarding secondary objects touching the image border)</i> <br>
            It might be appropriate to discard the primary object
            for any secondary object that touches the edge of the image.
            <p>Select <i>%(YES)s</i> to create a new set of objects that are identical
            to the original primary objects set, minus the objects for which the associated
            secondary object touches the image edge.</p>""" % globals())

        self.new_primary_objects_name = cps.ObjectNameProvider(
            "Name the new primary objects",
            "FilteredNuclei",
            doc="""
            <i>(Used only if associated primary objects are discarded)</i> <br>
            You can name the primary objects that remain after the discarding step.
            These objects will all have secondary objects
            that do not touch the edge of the image. Note that any primary object
            whose secondary object touches the edge will be retained in memory as an
            "unedited object"; this allows them to be considered in downstream modules that modify the
            segmentation.""")

        self.wants_primary_outlines = cps.Binary(
            "Retain outlines of the new primary objects?",
            False,
            doc="""
            <i>(Used only if associated primary objects are discarded)</i><br>
            %(RETAINING_OUTLINES_HELP)s""" % globals())

        self.new_primary_outlines_name = cps.OutlineNameProvider(
            "Name the new primary object outlines",
            "FilteredNucleiOutlines",
            doc="""
            <i>(Used only if associated primary objects are discarded and saving outlines of new primary objects)</i><br>
            Enter a name for the outlines of the identified
            objects. The outlined image can be selected in downstream modules by selecting
            them from any drop-down image list.""")
    def create_settings(self):
        """Create the settings for the module

        Create the settings for the module during initialization.
        """
        self.image_name = cps.ImageNameSubscriber("Select the input image",
                                                  cps.NONE,
                                                  doc="""
            The name of a binary image from a previous module.
            <b>IdentifyLinearObjects</b> will use this image to establish the
            foreground and background for the fitting operation. You can use
            <b>ApplyThreshold</b> to threshold a grayscale image and
            create the binary mask. You can also use a module such as
            <b>IdentifyPrimaryObjects</b> to label each linear object and then use
            <b>ConvertObjectsToImage</b> to make the result a mask.""")

        self.object_name = cps.ObjectNameProvider(
            "Name the linear objects to be identified",
            "LinearObjects",
            doc="""
            This is the name for the linear objects. You can refer
            to this name in subsequent modules such as
            <b>IdentifySecondaryObjects</b>""")

        self.object_width = cps.Integer("Linear object width",
                                        10,
                                        minval=1,
                                        doc="""
            This is the width (the short axis), measured in pixels,
            of the diamond used as a template when
            matching against the linear object. It should be less than the width
            of a linear object.""")

        self.object_length = cps.Integer("Linear object length",
                                         100,
                                         minval=1,
                                         doc="""
            This is the length (the long axis), measured in pixels,
            of the diamond used as a template when matching against the
            linear object. It should be less than the length of a linear object"""
                                         )

        self.angle_count = cps.Integer("Number of angles",
                                       32,
                                       minval=1,
                                       doc="""
            This is the number of different angles at which the
            template will be tried. For instance, if there are 12 angles,
            the template will be rotated by 0&deg;, 15&deg;, 30&deg;, 45&deg; ... 165&deg;.
            The shape is bilaterally symmetric; that is, you will get the same shape
            after rotating it by 180&deg;.""")

        self.wants_automatic_distance = cps.Binary(
            "Automatically calculate distance parameters?",
            True,
            doc="""
            This setting determines whether or not
            <b>IdentifyLinearObjects</b> automatically calculates the parameters
            used to determine whether two found-linear object centers belong to the
            same linear object.
            <p>Select <i>%(YES)s</i> to have <b>IdentifyLinearObjects</b>
            automatically calculate the distance from the linear object length
            and width. Select <i>%(NO)s</i> to set the distances manually.</p>"""
            % globals())

        self.space_distance = cps.Float("Spatial distance",
                                        5,
                                        minval=1,
                                        doc="""
            <i>(Used only if not automatically calculating distance parameters)</i><br>
            Enter the distance for calculating the linear object centers, in units of pixels.
            The linear object centers must be at least many pixels apart for the centers to
            be considered two separate linear objects.""")

        self.angular_distance = cps.Float("Angular distance",
                                          30,
                                          minval=1,
                                          doc="""
            <i>(Used only if automatically calculating distance parameters)</i><br>
            <b>IdentifyLinearObjects</b> calculates the linear object centers at different
            angles. Two linear object centers are considered to represent different
            linear objects if their angular distance is larger than this number. The
            number is measured in degrees.""")

        self.overlap_within_angle = cps.Binary(
            "Combine if overlapping and within angular distance?",
            False,
            doc="""
            This setting determines whether or not
            <b>IdentifyLinearObjects</b> merges putative linear objects that are within the
            angular distance specified AND in which pixels from the two 
            linear objects overlap.
            <p>Select <i>%(YES)s</i> to have <b>IdentifyLinearObjects</b>
            merge these linear objects. Select <i>%(NO)s</i> use only the spatial
            distance and angular distance parameters above.</p>""" % globals())
示例#13
0
    def create_settings(self):
        """Create the settings for the module

        Create the settings for the module during initialization.
        """
        self.image_name = cps.ImageNameSubscriber("Select the input image",
                                                  cps.NONE,
                                                  doc="""\
The name of a binary image from a previous module. **IdentifyDeadWorms**
will use this image to establish the foreground and background for the
fitting operation. You can use **ApplyThreshold** to threshold a
grayscale image and create the binary mask. You can also use a module
such as **IdentifyPrimaryObjects** to label each worm and then use
**ConvertObjectsToImage** to make the result a mask.
""")

        self.object_name = cps.ObjectNameProvider(
            "Name the dead worm objects to be identified",
            "DeadWorms",
            doc="""\
This is the name for the dead worm objects. You can refer
to this name in subsequent modules such as
**IdentifySecondaryObjects**""")

        self.worm_width = cps.Integer("Worm width",
                                      10,
                                      minval=1,
                                      doc="""\
This is the width (the short axis), measured in pixels,
of the diamond used as a template when
matching against the worm. It should be less than the width
of a worm.""")

        self.worm_length = cps.Integer("Worm length",
                                       100,
                                       minval=1,
                                       doc="""\
This is the length (the long axis), measured in pixels,
of the diamond used as a template when matching against the
worm. It should be less than the length of a worm""")

        self.angle_count = cps.Integer("Number of angles",
                                       32,
                                       minval=1,
                                       doc="""\
This is the number of different angles at which the template will be
tried. For instance, if there are 12 angles, the template will be
rotated by 0°, 15°, 30°, 45° … 165°. The shape is bilaterally symmetric;
that is, you will get the same shape after rotating it by 180°.
""")

        self.wants_automatic_distance = cps.Binary(
            "Automatically calculate distance parameters?",
            True,
            doc="""\
This setting determines whether or not **IdentifyDeadWorms**
automatically calculates the parameters used to determine whether two
found-worm centers belong to the same worm.

Select "*%(YES)s*" to have **IdentifyDeadWorms** automatically calculate
the distance from the worm length and width. Select "*%(NO)s*" to set the
distances manually.
""" % globals())

        self.space_distance = cps.Float("Spatial distance",
                                        5,
                                        minval=1,
                                        doc="""\
*(Used only if not automatically calculating distance parameters)*

Enter the distance for calculating the worm centers, in units of pixels.
The worm centers must be at least many pixels apart for the centers to
be considered two separate worms.
""")

        self.angular_distance = cps.Float("Angular distance",
                                          30,
                                          minval=1,
                                          doc="""\
*(Used only if automatically calculating distance parameters)*

**IdentifyDeadWorms** calculates the worm centers at different angles.
Two worm centers are considered to represent different worms if their
angular distance is larger than this number. The number is measured in
degrees.
""")
示例#14
0
    def add_file(self, can_remove=True):
        """Add settings for another file to the list"""
        group = cps.SettingsGroup()
        if can_remove:
            group.append("divider", cps.Divider(line=False))

        def get_directory_fn():
            return self.directory.get_absolute_path()

        group.append(
            "file_name",
            cps.FilenameText(
                FILE_TEXT,
                cps.NONE,
                metadata=True,
                get_directory_fn=get_directory_fn,
                exts=[("TIF - Tagged Image File format (*.tif,*.tiff)",
                       "*.tif;*.tiff"),
                      ("PNG - Portable Network Graphics (*.png)", "*.png"),
                      ("JPG/JPEG file (*.jpg,*.jpeg)", "*.jpg,*.jpeg"),
                      ("BMP - Windows Bitmap (*.bmp)", "*.bmp"),
                      ("Compuserve GIF file (*.gif)", "*.gif"),
                      ("MATLAB image (*.mat)", "*.mat"),
                      ("NumPy array (*.npy)", "*.npy"),
                      ("All files (*.*)", "*.*")],
                doc="""\
The filename can be constructed in one of two ways:

-  As a fixed filename (e.g., *Exp1\_D03f00d0.tif*).
-  Using the metadata associated with an image set in **LoadImages** or
   **LoadData**. This is especially useful if you want your output given
   a unique label according to the metadata corresponding to an image
   group. The name of the metadata to substitute is included in a
   special tag format embedded in your file specification.

{USING_METADATA_TAGS_REF}

{USING_METADATA_HELP_REF}

Keep in mind that in either case, the image file extension, if any, must
be included.
""".format(
                    **{
                        "USING_METADATA_TAGS_REF": USING_METADATA_TAGS_REF,
                        "USING_METADATA_HELP_REF": USING_METADATA_HELP_REF
                    })))

        group.append(
            "image_objects_choice",
            cps.Choice('Load as images or objects?',
                       IO_ALL,
                       doc="""\
This setting determines whether you load an image as image data or as
segmentation results (i.e., objects):

-  *{IO_IMAGES}:* The input image will be given the name you specify, by
   which it will be referred downstream. This is the most common usage
   for this module.
-  *{IO_OBJECTS}:* Use this option if the input image is a label matrix
   and you want to obtain the objects that it defines. A *label matrix*
   is a grayscale or color image in which the connected regions share
   the same label, and defines how objects are represented in
   CellProfiler. The labels are integer values greater than or equal to
   0. The elements equal to 0 are the background, whereas the elements
   equal to 1 make up one object, the elements equal to 2 make up a
   second object, and so on. This option allows you to use the objects
   without needing to insert an **Identify** module to extract them
   first. See **IdentifyPrimaryObjects** for more details.
""".format(**{
                           "IO_IMAGES": IO_IMAGES,
                           "IO_OBJECTS": IO_OBJECTS
                       })))

        group.append(
            "image_name",
            cps.FileImageNameProvider("Name the image that will be loaded",
                                      "OrigBlue",
                                      doc="""\
*(Used only if an image is output)*

Enter the name of the image that will be loaded. You can use this name
to select the image in downstream modules.
"""))

        group.append(
            "rescale",
            cps.Binary("Rescale intensities?",
                       True,
                       doc="""\
*(Used only if an image is output)*

This option determines whether image metadata should be used to
rescale the image’s intensities. Some image formats save the maximum
possible intensity value along with the pixel data. For instance, a
microscope might acquire images using a 12-bit A/D converter which
outputs intensity values between zero and 4095, but stores the values
in a field that can take values up to 65535.

Select *{YES}* to rescale the image intensity so that saturated values
are rescaled to 1.0 by dividing all pixels in the image by the maximum
possible intensity value.

Select *{NO}* to ignore the image metadata and rescale the image to 0 –
1.0 by dividing by 255 or 65535, depending on the number of bits used to
store the image.
""".format(**{
                           "NO": NO,
                           "YES": YES
                       })))

        group.append(
            "objects_name",
            cps.ObjectNameProvider('Name this loaded object',
                                   "Nuclei",
                                   doc="""\
*(Used only if objects are output)*

This is the name for the objects loaded from your image
"""))

        group.append(
            "wants_outlines",
            cps.Binary("Retain outlines of loaded objects?",
                       False,
                       doc="""\
*(Used only if objects are output)*

Select *{YES}* if you want to save an image of the outlines of the
loaded objects.
""".format(**{"YES": YES})))

        group.append(
            "outlines_name",
            cps.OutlineNameProvider('Name the outlines',
                                    'NucleiOutlines',
                                    doc="""\
*(Used only if objects are output)*

Enter a name that will allow the outlines to be selected later in the
pipeline.
"""))

        if can_remove:
            group.append(
                "remove",
                cps.RemoveSettingButton("", "Remove this image",
                                        self.file_settings, group))
        self.file_settings.append(group)
示例#15
0
    def create_settings(self):
        self.object_name = cps.ObjectNameSubscriber(
                "Select the input objects",
                cps.NONE, doc='''
            Select the objects that you want to expand or shrink.''')

        self.output_object_name = cps.ObjectNameProvider(
                "Name the output objects",
                "ShrunkenNuclei", doc='''
            Enter a name for the resulting objects.''')

        self.operation = cps.Choice(
                "Select the operation",
                O_ALL, doc='''
            Select the operation that you want to perform:
            <ul>
            <li><i>%(O_SHRINK_INF)s:</i> Remove all pixels but one from filled objects. Thin objects
            with holes to loops unless the "fill" option is checked.</li>
            <li><i>%(O_EXPAND_INF)s:</i> Expand objects, assigning every pixel in the image to an
            object. Background pixels are assigned to the nearest object.</li>
            <li><i>%(O_DIVIDE)s:</i> Remove pixels from an object that are adjacent to another
            object's pixels unless doing so would change the object's Euler number
            (break an object in two, remove the object completely or open a hole in
            an object).</li>
            <li><i>%(O_SHRINK)s:</i> Remove pixels around the perimeter of an object unless doing
            so would change the object's Euler number (break the object in two, remove the object completely or open
            a hole in the object). You can specify the number of times
            perimeter pixels should be removed. Processing stops automatically when there are no more
            pixels to remove.</li>
            <li><i>%(O_EXPAND)s:</i> Expand each object by adding background pixels adjacent to the
            image. You can choose the number of times to expand. Processing stops
            automatically if there are no more background pixels.</li>
            <li><i>%(O_SKELETONIZE)s:</i> Erode each object to its skeleton.</li>
            <li><i>%(O_SPUR)s:</i> Remove or reduce the length of spurs in a skeletonized image.
            The algorithm reduces spur size by the number of pixels indicated in the
            setting <i>Number of pixels by which to expand or shrink</i>.</li>
            </ul>''' % globals())

        self.iterations = cps.Integer(
                "Number of pixels by which to expand or shrink", 1, minval=1)

        self.wants_fill_holes = cps.Binary(
                "Fill holes in objects so that all objects shrink to a single point?", False, doc="""
            <i>(Used only if one of the "shrink" options selected)</i><br>
            Select <i>%(YES)s</i> to ensure that each object will shrink
            to a single point, by filling the holes in each object.
            <p>Select <i>%(NO)s</i> to preserve the Euler number. in this case, the
            shrink algorithm preserves each object's Euler number,
            which means that it will erode an object with a hole to a ring in order to
            keep the hole. An object with two holes will be shrunk to two rings
            connected by a line in order to keep from breaking up the object or breaking
            the hole.</p>""" % globals())

        self.wants_outlines = cps.Binary(
                "Retain the outlines of the identified objects?",
                False, doc="""
            %(RETAINING_OUTLINES_HELP)s""" % globals())

        self.outlines_name = cps.OutlineNameProvider(
                "Name the outline image",
                "ShrunkenNucleiOutlines", doc="""
            %(NAMING_OUTLINES_HELP)s""" % globals())
    def create_settings(self):
        """Create your settings by subclassing this function

        create_settings is called at the end of initialization.
        """
        self.grid_name = cps.GridNameSubscriber(
                "Select the defined grid", cps.NONE, doc="""Select the name of a grid created by a previous **DefineGrid** module.""")

        self.output_objects_name = cps.ObjectNameProvider(
                "Name the objects to be identified", "Wells", doc="""\
Enter the name of the grid objects identified by this module. These objects
will be available for further measurement and processing in subsequent modules.""")

        self.shape_choice = cps.Choice(
                "Select object shapes and locations",
                [SHAPE_RECTANGLE, SHAPE_CIRCLE_FORCED, SHAPE_CIRCLE_NATURAL, SHAPE_NATURAL], doc="""\
Use this setting to choose the method to be used to determine the grid
objects’ shapes and locations:

-  *%(SHAPE_RECTANGLE)s:* Each object will be created as a rectangle,
   completely occupying the entire grid compartment (rectangle). This
   option creates the rectangular objects based solely on the grid’s
   specifications, not on any previously identified guiding objects.
-  *%(SHAPE_CIRCLE_FORCED)s:* Each object will be created as a circle,
   centered in the middle of each grid compartment. This option places
   the circular objects’ locations based solely on the grid’s
   specifications, not on any previously identified guiding objects. The
   radius of all circles in a grid will be constant for the entire grid
   in each image cycle, and can be determined automatically for each
   image cycle based on the average radius of previously identified
   guiding objects for that image cycle, or instead it can be specified
   as a single radius for all circles in all grids in the entire
   analysis run.
-  *%(SHAPE_CIRCLE_NATURAL)s:* Each object will be created as a
   circle, and each circle’s location within its grid compartment will
   be determined based on the location of any previously identified
   guiding objects within that grid compartment. Thus, if a guiding
   object lies within a particular grid compartment, that object’s
   center will be the center of the created circular object. If no
   guiding objects lie within a particular grid compartment, the
   circular object is placed within the center of that grid compartment.
   If more than one guiding object lies within the grid compartment,
   they will be combined and the centroid of this combined object will
   be the location of the created circular object. Note that guiding
   objects whose centers are close to the grid edge are ignored.
-  *%(SHAPE_NATURAL)s:* Within each grid compartment, the object will
   be identified based on combining all of the parts of guiding objects,
   if any, that fall within the grid compartment. Note that guiding
   objects whose centers are close to the grid edge are ignored. If a
   guiding object does not exist within a grid compartment, an object
   consisting of one single pixel in the middle of the grid compartment
   will be created.
""" % globals())

        self.diameter_choice = cps.Choice(
                "Specify the circle diameter automatically?",
                [AM_AUTOMATIC, AM_MANUAL], doc="""\
*(Used only if "Circle" is selected as object shape)*

There are two methods for selecting the circle diameter:

-  *%(AM_AUTOMATIC)s:* Uses the average diameter of previously
   identified guiding objects as the diameter.
-  *%(AM_MANUAL)s:* Lets you specify the diameter directly, as a
   number.
""" % globals())

        self.diameter = cps.Integer(
                "Circle diameter", 20, minval=2, doc="""\
*(Used only if "Circle" is selected as object shape and diameter is
specified manually)*

Enter the diameter to be used for each grid circle, in pixels.
%(HELP_ON_MEASURING_DISTANCES)s
""" % globals())

        self.guiding_object_name = cps.ObjectNameSubscriber(
                "Select the guiding objects", cps.NONE, doc="""\
*(Used only if "Circle" is selected as object shape and diameter is
specified automatically, or if Natural Location is selected as the
object shape)*

Select the names of previously identified objects that will be used to
guide the shape and/or location of the objects created by this module,
depending on the method chosen.
""")
示例#17
0
    def create_settings(self):
        '''Create the settings that control this module'''
        self.object_name = cps.ObjectNameSubscriber(
                "Select objects to be masked", cps.NONE, doc="""
            Select the objects that will be masked (that is, excluded in whole
            or in part based on the other settings in the module).
            You can choose from any objects created by
            a previous object processing module, such as <b>IdentifyPrimaryObjects</b>,
            <b>IdentifySecondaryObjects</b> or <b>IdentifyTertiaryObjects</b>.""")

        self.remaining_objects = cps.ObjectNameProvider(
                "Name the masked objects", "MaskedNuclei", doc="""
            Enter a name for the objects that remain after
            the masking operation. You can refer to the masked objects in
            subsequent modules by this name.""")

        self.mask_choice = cps.Choice(
                "Mask using a region defined by other objects or by binary image?",
                [MC_OBJECTS, MC_IMAGE], doc="""
            You can mask your objects by defining a region using objects
            you previously identified in your pipeline (<i>%(MC_OBJECTS)s</i>) or by defining a
            region based on the white regions in a binary image (<i>%(MC_IMAGE)s</i>).""" % globals())

        self.masking_objects = cps.ObjectNameSubscriber(
                "Select the masking object", cps.NONE, doc="""
            Select the objects that will be used to define the
            masking region. You can choose from any objects created
            by a previous object processing module, such as <b>IdentifyPrimaryObjects</b>,
            <b>IdentifySecondaryObjects</b>, or <b>IdentifyTertiaryObjects</b>.""")

        self.masking_image = cps.ImageNameSubscriber(
                "Select the masking image", cps.NONE, doc="""
            Select an image that was either loaded or
            created by a previous module. The image should be a binary image where
            the white portion of the image is the region(s) you will use for masking.
            Binary images can be loaded from disk using the
            <b>NamesAndTypes</b> module by selecting "Binary mask" for the image type.
            You can also create a binary image from a grayscale
            image using <b>ApplyThreshold</b>.""")

        self.wants_inverted_mask = cps.Binary(
                "Invert the mask?", False, doc="""
            This option reverses the foreground/background relationship of
            the mask.
            <ul>
            <li>Select <i>%(NO)s</i> for the mask to be composed of the foregound
            (white portion) of the masking image or the area within the masking
            objects.</li>
            <li>Select <i>%(YES)s</i> for the mask to instead be composed of the
            <i>background</i> (black portions) of the masking image or the area
            <i>outside</i> the masking objects.</li>
            </ul>""" % globals())

        self.overlap_choice = cps.Choice(
                "Handling of objects that are partially masked",
                [P_MASK, P_KEEP, P_REMOVE, P_REMOVE_PERCENTAGE], doc="""
            An object might partially overlap the mask region, with
            pixels both inside and outside the region. <b>MaskObjects</b>
            can handle this in one of three ways:<br>
            <ul>
            <li><i>%(P_MASK)s:</i> Choosing this option
            will reduce the size of partially overlapping objects. The part
            of the object that overlaps the region will be retained. The
            part of the object that is outside of the region will be removed.</li>
            <li><i>%(P_KEEP)s:</i> If you choose this option, <b>MaskObjects</b>
            will keep the whole object if any part of it overlaps the masking
            region.</li>
            <li><i>%(P_REMOVE)s:</i> Objects that are partially outside
            of the masking region will be completely removed if you choose
            this option.</li>
            <li><i>%(P_REMOVE_PERCENTAGE)s:</i> Determine whether to
            remove or keep an object depending on how much of the object
            overlaps the masking region. <b>MaskObjects</b> will keep an
            object if at least a certain fraction (which you enter below) of
            the object falls within the masking region. <b>MaskObjects</b>
            completely removes the object if too little of it overlaps
            the masking region.</li>
            </ul>""" % globals())

        self.overlap_fraction = cps.Float(
                "Fraction of object that must overlap", .5,
                minval=0, maxval=1, doc="""
            <i>(Used only if removing based on a overlap)</i><br>
            Specify the minimum fraction of an object
            that must overlap the masking region for that object to be retained.
            For instance, if the fraction is 0.75, then 3/4 of an object
            must be within the masking region for that object to be retained.""")

        self.retain_or_renumber = cps.Choice(
                "Numbering of resulting objects",
                [R_RENUMBER, R_RETAIN], doc="""
            Choose how to number the objects that
            remain after masking, which controls how remaining objects are associated with their predecessors:
            <ul>
            <li><i>%(R_RENUMBER)s:</i> The objects that remain will be renumbered
            using consecutive numbers. This
            is a good choice if you do not plan to use measurements from the
            original objects; your object measurements for the
            masked objects will not have gaps (where removed objects are missing).</li>
            <li><i>%(R_RETAIN)s:</i>: The original labels for the objects will be retained.
            This allows any measurements you make from
            the masked objects to be directly aligned with measurements you might
            have made of the original, unmasked objects (or objects directly
            associated with them).</li>
            </ul>""" % globals())

        self.wants_outlines = cps.Binary(
                "Retain outlines of the resulting objects?", False, doc="""
            %(RETAINING_OUTLINES_HELP)s""" % globals())

        self.outlines_name = cps.OutlineNameProvider(
                "Name the outline image", "MaskedOutlines", doc="""
            %(NAMING_OUTLINES_HELP)s""" % globals())
示例#18
0
    def create_settings(self):
        self.objects_name = cps.ObjectNameSubscriber(
            "Select the input objects",
            cps.NONE,
            doc="""
            Select the objects whose object numbers you want to reassign.
            You can use any objects that were created in previous modules, such as
            <b>IdentifyPrimaryObjects</b> or <b>IdentifySecondaryObjects</b>."""
        )

        self.output_objects_name = cps.ObjectNameProvider(
            "Name the new objects",
            "RelabeledNuclei",
            doc="""
            Enter a name for the objects whose numbers have been reassigned.
            You can use this name in subsequent modules that take objects as inputs."""
        )

        self.relabel_option = cps.Choice("Operation",
                                         [OPTION_UNIFY, OPTION_SPLIT],
                                         doc="""
            You can choose one of the following options:
            <ul>
            <li><i>%(OPTION_UNIFY)s:</i> Assign adjacent or nearby objects the same
            label based on certain criteria. It can be useful, for example,
            to merge together touching objects that were incorrectly split into two pieces
            by an <b>Identify</b> module.</li>
            <li><i>%(OPTION_SPLIT)s:</i> Assign a unique number to separate objects
            that currently share the same label. This can occur if you applied certain
            operations with the <b>Morph</b> module to objects.</li>
            </ul>""" % globals())

        self.unify_option = cps.Choice("Unification method",
                                       [UNIFY_DISTANCE, UNIFY_PARENT],
                                       doc="""
            <i>(Used only with the %(OPTION_UNIFY)s option)</i><br>
            You can unify objects in one of two ways:
            <ul>
            <li><i>%(UNIFY_DISTANCE)s: </i> All objects within a certain pixel radius
            from each other will be unified</li>
            <li><i>%(UNIFY_PARENT)s: </i>All objects which share the same parent
            relationship to another object will be unified. This is not be confused
            with using the <b>RelateObjects</b> module, in which the related objects
            remain as individual objects. See <b>RelateObjects</b> for more details.</li>
            </ul>
            """ % globals())

        self.unification_method = cps.Choice("Output object type",
                                             [UM_DISCONNECTED, UM_CONVEX_HULL],
                                             doc="""
            <i>(Used only with the %(UNIFY_PARENT)s unification method)</i>
            <br>
            <b>ReassignObjectNumbers</b> can either unify the child objects
            and keep them disconnected or it can find the smallest convex
            polygon (the convex hull) that encloses all of a parent's child
            objects. The convex hull will be truncated to include only those
            pixels in the parent - in that case it may not truly be convex.
            Choose %(UM_DISCONNECTED)s to leave the children as
            disconnected pieces. Choose %(UM_CONVEX_HULL)s to create an
            output object that is the convex hull around them all.
            """ % globals())

        self.parent_object = cps.Choice("Select the parent object", [cps.NONE],
                                        choices_fn=self.get_parent_choices,
                                        doc="""
            Select the parent object that will be used to
            unify the child objects. Please note the following:
            <ul>
            <li>You must have established a parent-child relationship
            between the objects using a prior <b>RelateObjects</b> module.</li>
            <li>Primary objects and their associated secondary objects are
            already in a one-to-one parent-child relationship, so it makes no
            sense to unify them here.</li>
            </ul>""")

        self.distance_threshold = cps.Integer(
            "Maximum distance within which to unify objects",
            0,
            minval=0,
            doc="""
            <i>(Used only with the %(OPTION_UNIFY)s option and the %(UNIFY_DISTANCE)s method)</i><br>
            Objects that are less than or equal to the distance
            you enter here, in pixels, will be unified. If you choose zero
            (the default), only objects that are touching will be unified.
            Note that <i>%(OPTION_UNIFY)s </i> will not actually connect or bridge
            the two objects by adding any new pixels; it simply assigns the same object number
            to the portions of the object. The new, unified object
            may therefore consist of two or more unconnected components.""" %
            globals())

        self.wants_image = cps.Binary("Unify using a grayscale image?",
                                      False,
                                      doc="""
            <i>(Used only with the %(OPTION_UNIFY)s option)</i><br>
            Select <i>%(YES)s</i> to use the objects' intensity features to determine whether two
            objects should be unified. If you choose to use a grayscale image,
            <i>%(OPTION_UNIFY)s</i> will unify two objects only if they
            are within the distance you have specified <i>and</i> certain criteria about the objects
            within the grayscale image are met.""" % globals())

        self.image_name = cps.ImageNameSubscriber(
            "Select the grayscale image to guide unification",
            cps.NONE,
            doc="""
            <i>(Used only if a grayscale image is to be used as a guide for unification)</i><br>
            Select the name of an image loaded or created by a previous module."""
        )

        self.minimum_intensity_fraction = cps.Float(
            "Minimum intensity fraction",
            .9,
            minval=0,
            maxval=1,
            doc="""
            <i>(Used only if a grayscale image is to be used as a guide for unification)</i><br>
            Select the minimum acceptable intensity fraction. This will be used
            as described for the method you choose in the next setting.""")

        self.where_algorithm = cps.Choice("Method to find object intensity",
                                          [CA_CLOSEST_POINT, CA_CENTROIDS],
                                          doc="""
            <i>(Used only if a grayscale image is to be used as a guide for unification)</i><br>
            You can use one of two methods to determine whether two
            objects should unified, assuming they meet the distance criteria (as specified above):
            <ul>
            <li><i>%(CA_CENTROIDS)s:</i> When the module considers merging two objects,
            this method identifies the centroid of each object,
            records the intensity value of the dimmer of the two centroids,
            multiplies this value by the <i>minimum intensity fraction</i> to generate a threshold,
            and draws a line between the centroids. The method will unify the
            two objects only if the intensity of every point along the line is above
            the threshold. For instance, if the intensity
            of one centroid is 0.75 and the other is 0.50 and the <i>minimum intensity fraction</i>
            has been chosen to be 0.9, all points along the line would need to have an intensity
            of min(0.75, 0.50) * 0.9 = 0.50 * 0.9 = 0.45.<br>
            This method works well for round cells whose maximum intensity
            is in the center of the cell: a single cell that was incorrectly segmented
            into two objects will typically not have a dim line between the centroids
            of the two halves and will be correctly unified.</li>

            <li><i>%(CA_CLOSEST_POINT)s:</i> This method is useful for unifying irregularly shaped cells
            which are connected. It starts by assigning background pixels in the vicinity of the objects to the nearest
            object. Objects are then unified if each object has background pixels that are:
            <ul>
            <li>Within a distance threshold from each object;</li>
            <li>Above the minimum intensity fraction of the nearest object pixel;</li>
            <li>Adjacent to background pixels assigned to a neighboring object.</li>
            </ul>
            An example of a feature that satisfies the above constraints is a line of
            pixels that connect two neighboring objects and is roughly the same intensity
            as the boundary pixels of both (such as an axon connecting two neurons).</li>
            </ul>""" % globals())

        self.wants_outlines = cps.Binary(
            "Retain outlines of the relabeled objects?",
            False,
            doc="""
            %(RETAINING_OUTLINES_HELP)s""" % globals())

        self.outlines_name = cps.OutlineNameProvider('Name the outlines',
                                                     'RelabeledNucleiOutlines',
                                                     doc="""
            %(NAMING_OUTLINES_HELP)s""" % globals())