Esempio n. 1
0
    def add_function(self, can_remove=True):
        group = MorphSettingsGroup()
        group.can_remove = can_remove
        if can_remove:
            group.append("divider", cps.Divider(line=False))
        group.append(
            "function",
            cps.Choice(
                "Select the operation to perform",
                F_ALL,
                doc=
                """Choose one of the operations described in this module's help."""
            ))

        group.append(
            "repeats_choice",
            cps.Choice("Number of times to repeat operation",
                       R_ALL,
                       doc="""\
This setting controls the number of times that the same operation is
applied successively to the image.

-  *%(R_ONCE)s:* Perform the operation once on the image.
-  *%(R_FOREVER)s:* Perform the operation on the image until successive
   iterations yield the same image.
-  *%(R_CUSTOM)s:* Perform the operation a custom number of times.""" %
                       globals()))

        group.append(
            "custom_repeats",
            cps.Integer(self.CUSTOM_REPEATS_TEXT,
                        2,
                        1,
                        doc=self.CUSTOM_REPEATS_DOC))

        group.append(
            "rescale_values",
            cps.Binary("Rescale values from 0 to 1?",
                       True,
                       doc="""\
*(Used only for the "%(F_DISTANCE)s" operation).*

Select "*%(YES)s*" to rescale the transformed values to lie between 0 and
1. This is the option to use if the distance transformed image is to be
used for thresholding by an **Identify** module or the like, which
assumes a 0-1 scaling.

Select "*%(NO)s*" to leave the values in absolute pixel units. This useful
in cases where the actual pixel distances are to be used downstream as
input for a measurement module.""" % globals()))

        if can_remove:
            group.append(
                "remove",
                cps.RemoveSettingButton("", "Remove this operation",
                                        self.functions, group))
        self.functions.append(group)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
0
 def create_settings(self):
     self.object_name = cps.ObjectNameSubscriber(
         "Input objects", "None",
         doc = """Enter the name of the objects whose population context is
         to be measured.""")
     self.operation = cps.Choice(
         "Operation",
         choices= (O_POPULATION_DENSITY, O_DISTANCE_TO_EDGE, O_BOTH),
         doc = """Select the measurements you wish to perform. The choices
         are:<br><ul>
         <li><i>%(O_POPULATION_DENSITY)s</i> - calculate the population
         density within a radius from each cell.</li>
         <li><i>%(O_DISTANCE_TO_EDGE)s</i> - calculate the distance of
         each cell from the edge of a binary mask.</li>
         <li><i>%(O_BOTH)s</i> - make both measurements"""%globals())
     self.radius = cps.Integer(
         "Search radius", 50, minval=1,
         doc = """Count all objects within this radius""")
     self.object_diameter = cps.Integer(
         "Object diameter", 20, minval=0,
         doc = """The average diameter of objects in the image. This number
         is used to adjust the area of the image to account for objects
         that would otherwise be excluded because they were touching
         the border.""")
     self.edge_image = cps.ImageNameSubscriber(
         "Edge image",
         doc = """For measuring distance to an edge, this is the reference
         image. Cell distances will be computed to the nearest foreground / 
         background edge in the reference image.""")
Esempio n. 5
0
    def create_settings(self):
        '''Create the initial settings for the module'''
        self.image_groups = []
        self.add_image(can_delete=False)
        self.spacer_1 = cps.Divider()
        self.add_image(can_delete=False)
        self.image_count = cps.HiddenCount(self.image_groups)

        self.add_image_button = cps.DoSomething("", 'Add another image', self.add_image)
        self.spacer_2 = cps.Divider()
        self.thr = cps.Float(
                "Set threshold as percentage of maximum intensity for the images",
                15, minval=0, maxval=99, doc='''\
            Select the threshold as a percentage of the maximum intensity of the above image [0-99].''')

        self.images_or_objects = cps.Choice(
                'Select where to measure correlation',
                [M_IMAGES, M_OBJECTS, M_IMAGES_AND_OBJECTS], doc='''
            You can measure the correlation in several ways:
            <ul>
            <li><i>%(M_OBJECTS)s:</i> Measure correlation only in those pixels previously
            identified as an object. You will be asked to specify which object to measure from.</li>
            <li><i>%(M_IMAGES)s:</i> Measure the correlation across all pixels in the images.</li>
            <li><i>%(M_IMAGES_AND_OBJECTS)s:</i> Calculate both measurements above.</li>
            </ul>
            All methods measure correlation on a pixel by pixel basis.''' % globals())

        self.object_groups = []
        self.add_object(can_delete=False)
        self.object_count = cps.HiddenCount(self.object_groups)

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

        self.add_object_button = cps.DoSomething("", 'Add another object', self.add_object)
 def test_01_01_assign(self):
     x = cps.Choice("text", ["foo", "bar"], "bar")
     self.assertTrue(x == "bar")
     x.value = "foo"
     self.assertTrue(x == "foo")
     x.value = "bar"
     self.assertTrue(x == "bar")
Esempio n. 7
0
    def add_image(self, can_remove=True):
        '''Add an image + associated questions and buttons'''
        group = cps.SettingsGroup()
        if can_remove:
            group.append("divider", cps.Divider(line=False))

        group.append("input_image_name",
                     cps.ImageNameSubscriber(
                             "Select the additional image",
                             cps.NONE, doc="""
                         Select the additional image to align?"""))

        group.append("output_image_name",
                     cps.ImageNameProvider(
                             "Name the output image",
                             "AlignedBlue", doc="""
                         Enter the name of the aligned image?"""))

        group.append("align_choice",
                     cps.Choice(
                             "Select how the alignment is to be applied",
                             [A_SIMILARLY, A_SEPARATELY], doc="""
                         An additional image can either be aligned similarly to the second one or
                         a separate alignment to the first image can be calculated:
                         <ul>
                         <li><i>%(A_SIMILARLY)s:</i> The same alignment measurements obtained from
                         the first two input images are applied to this additional image.</li>
                         <li><i>%(A_SEPARATELY)s:</i> A new set of alignment measurements are
                         calculated for this additional image using the alignment method
                         specified with respect to the first input image.</li>
                         </ul>""" % globals()))

        if can_remove:
            group.append("remover", cps.RemoveSettingButton("", "Remove above image", self.additional_images, group))
        self.additional_images.append(group)
Esempio n. 8
0
            def __init__(self, index, operation):
                self.__index = index
                self.__operation = operation
                self.__operand_choice = cps.Choice(
                    self.operand_choice_text(),
                    MC_ALL,
                    doc="""Indicate whether the operand is an image or object measurement.""",
                )

                self.__operand_objects = cps.ObjectNameSubscriber(
                    self.operand_objects_text(),
                    cps.NONE,
                    doc="""Choose the objects you want to measure for this operation.""",
                )

                self.__operand_measurement = cps.Measurement(
                    self.operand_measurement_text(),
                    self.object_fn,
                    doc="""\
Enter the category that was used to create the measurement. You
will be prompted to add additional information depending on
the type of measurement that is requested.""",
                )

                self.__multiplicand = cps.Float(
                    "Multiply the above operand by",
                    1,
                    doc="""Enter the number by which you would like to multiply the above operand.""",
                )

                self.__exponent = cps.Float(
                    "Raise the power of above operand by",
                    1,
                    doc="""Enter the power by which you would like to raise the above operand.""",
                )
Esempio n. 9
0
    def add_image(self, removable=True):
        # The text for these settings will be replaced in renumber_settings()
        group = cps.SettingsGroup()
        group.removable = removable
        group.append("image_or_measurement", cps.Choice(
                "Image or measurement?", [IM_IMAGE, IM_MEASUREMENT], doc="""
            You can perform math operations using two images or you
            can use a measurement for one of the operands. For instance,
            to divide the intensity of one image by another, choose <i>%(IM_IMAGE)s</i>
            for both and pick the respective images. To divide the intensity
            of an image by its median intensity, use <b>MeasureImageIntensity</b>
            prior to this module to calculate the median intensity, then
            select <i>%(IM_MEASUREMENT)s</i> and use the median intensity measurement as
            the denominator""" % globals()))

        group.append("image_name", cps.ImageNameSubscriber("", "", doc="""
            Selec the image that you want to use for this operation."""))

        group.append("measurement", cps.Measurement(
                "Measurement", lambda: cpmeas.IMAGE, "", doc="""
            This is a measurement made on the image. The value of the
            measurement is used for the operand for all of the pixels of the
            other operand's image."""))

        group.append("factor", cps.Float("", 1, doc="""
            Enter the number that you would like to multiply the above image by. This multiplication
            is applied before other operations."""))

        if removable:
            group.append("remover", cps.RemoveSettingButton("", "Remove this image", self.images, group))
        group.append("divider", cps.Divider())
        self.images.append(group)
    def create_settings(self):

        self.input_object_name = cps.ObjectNameSubscriber(
            "Select objects to measure",
            cps.NONE,
            doc=
            """Select the objects whose radial entropy you want to measure.""")

        self.input_image_name = cps.ImageNameSubscriber(
            "Select an image to measure",
            cps.NONE,
            doc="""Select the
            grayscale image you want to measure the entropy of.""")

        self.bin_number = cps.Integer(
            "Input number of bins",
            6,
            minval=3,
            maxval=60,
            doc=
            """Number of radial bins to divide your object into.  The minimum number
            of bins allowed is 3, the maximum number is 60.""")

        self.intensity_measurement = cps.Choice(
            "Which intensity measurement should be used?",
            ['Mean', 'Median', 'Integrated'],
            value='Mean',
            doc="""
            Whether each wedge's mean, median, or integrated intensity
            should be used to calculate the entropy.""")
Esempio n. 11
0
    def add_channel(self, can_remove=True):
        '''Add another channel to the channels list'''
        group = cps.SettingsGroup()
        group.can_remove = can_remove
        group.append("channel_choice", cps.Choice(
                "Channel number", self.channel_names,
                self.channel_names[len(self.channels) % len(self.channel_names)], doc="""
            This setting chooses a channel to be processed.
            <i>Red: 1</i> is the first channel in a .TIF or the red channel
            in a traditional image file. <i>Green: 2</i> and <i>Blue: 3</i>
            are the second and third channels of a TIF or the green and blue
            channels in other formats. <i>Alpha: 4</i> is the transparency
            channel for image formats that support transparency and is
            channel # 4 for a .TIF file.

            <b>ColorToGray</b> will fail to process an image if you select
            a channel that is not supported by that image, for example, "5"
            for a .PNG file"""))

        group.append("contribution", cps.Float(
                "Relative weight of the channel", 1, 0, doc='''
            <i>(Used only when combining channels)</i><br>
            Relative weights: If all relative weights are equal, all three
            colors contribute equally in the final image. To weight colors relative
            to each other, increase or decrease the relative weights.'''))

        group.append("image_name", cps.ImageNameProvider(
                "Image name", value="Channel%d" % (len(self.channels) + 1), doc="""
            This is the name of the grayscale image that holds
            the image data from the chosen channel."""))

        if group.can_remove:
            group.append("remover", cps.RemoveSettingButton(
                    "", "Remove this channel", self.channels, group))
        self.channels.append(group)
 def test_00_00_init(self):
     x = cps.Choice("text", ["choice"])
     x.test_valid(None)
     self.assertEqual(x.text, "text")
     self.assertEqual(x.value, "choice")
     self.assertEqual(len(x.choices), 1)
     self.assertEqual(x.choices[0], "choice")
Esempio n. 13
0
    def create_settings(self):
        self.site_count = cps.Integer(
                "Number of image sites per well", 1, minval=1, doc="""\
Enter the number of image sets (fields of view) corresponding to each well.""")

        self.column_count = cps.Integer(
                "Number of columns per plate", 12, minval=1, doc="""\
Enter the number of columns per plate.""")

        self.row_count = cps.Integer(
                "Number of rows per plate", 8, minval=1, doc="""\
Enter the number of rows per plate.""")

        self.order = cps.Choice(
                "Order of image data", [O_ROW, O_COLUMN], doc="""\
This setting specifies how the input data is ordered (assuming that
sites within a well are ordered consecutively):

-  *%(O_ROW)s:* The data appears by row and then by column. That is,
   all columns for a given row (e.g., A01, A02, A03…) appear
   consecutively, for each row in consecutive order.
-  *%(O_COLUMN)s:* The data appears by column and then by row. That is,
   all rows for a given column (e.g., A01, B01, C01…) appear
   consecutively, for each column in consecutive order.

For instance, the SBS Bioimage example (available `here`_) has files that are named:
Channel1-01-A01.tif, Channel1-02-A02.tif, …, Channel1-12-A12.tif, Channel1-13-B01.tif, …
You would use “%(O_ROW)s” to label these because the ordering is by row and then by column.

.. _here: http://cellprofiler.org/examples.html#SBS_Bioimage_CNT
""" % globals())
Esempio n. 14
0
    def add_channelfn(self, can_remove=True):
        '''Add another image channel

        can_remove - true if we are allowed to remove this channel
        '''
        group = cps.SettingsGroup()
        self.channels.append(group)

        # Check which cellprofiler image we are in the group
        # (each channel translates to a single cellprofiler image)
        cpimg_index = 0
        for channel in self.channels:
            if id(channel) == id(group):
                break
            cpimg_index += 1

        group.append("divider", cps.Divider(line=True))
        group.append("cpimage_name", cps.ImageNameProvider(
                'Image name', default_cpimage_name(cpimg_index)))
        channel_numbers = [
            str(x) for x in range(0, max(10, len(self.channels) + 2))]
        group.append("channel_number", cps.Choice(
                "Channel number:", channel_numbers, channel_numbers[len(self.channels) - 1],
                doc="""(Used only for multichannel images)
			The channels of a multichannel image are numbered starting from 0 (zero).

			Each channel is a greyscale image, acquired using different
			illumination sources and/or optics. Use this setting to pick
			the channel to associate with the image or images you load from
			OMERO."""))
        group.can_remove = can_remove
        if can_remove:
            group.append("remover", cps.RemoveSettingButton(
                    "Remove this channel", "Remove channel", self.channels, group))
Esempio n. 15
0
    def create_settings(self):
        self.image_name = cps.ImageNameSubscriber("Select the input image",
                                                  cps.NONE)

        self.conversion_method = cps.Choice("Conversion method",
                                            [MEAN, MEDIAN, CUSTOMFUNCTION],
                                            doc='''
            How do you want to summarize the multichannel image?
            <ul>
            <li><i>%(MEAN)s:</i> Takes the mean.</li>
            <li><i>%(MEDIAN)s</i> Takes the median</li>
            <li><i>%(MEDIAN)s</i> Applies a cutstom python function</li>
            </ul>''' % globals())

        self.custom_function = cps.Text("Input a Python function",
                                        'np.mean',
                                        doc='''
        Can be a simple function as "np.max" (without ") or complicated as "functools.partial(np.percentile,q=80, axis=2)".
        functools is imported as convenience.
        ''')
        # The following settings are used for the combine option
        self.grayscale_name = cps.ImageNameProvider("Name the output image",
                                                    "OrigGray")

        # The alternative model:
        self.channels = []
Esempio n. 16
0
    def create_settings(self):
        """Create the settings here and set the module name (initialization)

        """
        self.source_choice = cps.Choice("Use objects or an image as a mask?",
                                        [IO_OBJECTS, IO_IMAGE],
                                        doc="""\
You can mask an image in two ways:

-  *%(IO_OBJECTS)s*: Using objects created by another module (for
   instance **IdentifyPrimaryObjects**). The module will mask out all
   parts of the image that are not within one of the objects (unless you
   invert the mask).
-  *%(IO_IMAGE)s*: Using a binary image as the mask, where black
   portions of the image (false or zero-value pixels) will be masked
   out. If the image is not binary, the module will use all pixels whose
   intensity is greater than 0.5 as the mask’s foreground (white area).
   You can use **Threshold** instead to create a binary image with
   finer control over the intensity choice.
   """ % globals())

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

Select the objects you would like to use to mask the input image.
""")

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

Select the image that you like to use to mask the input image.
""")

        self.image_name = cps.ImageNameSubscriber(
            "Select the input image",
            cps.NONE,
            doc="Select the image that you want to mask.")

        self.masked_image_name = cps.ImageNameProvider(
            "Name the output image",
            "MaskBlue",
            doc="Enter the name for the output masked image.")

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

-  Select "*%(NO)s*" to produce the mask from the foreground (white
   portion) of the masking image or the area within the masking objects.
-  Select "*%(YES)s*" to instead produce the mask from the *background*
   (black portions) of the masking image or the area *outside* the
   masking objects.
       """ % globals())
Esempio n. 17
0
    def create_settings(self):
        self.workspace = None
        module_explanation = [
            "To begin creating your project, use the %s module to compile" %
            self.module_name,
            "a list of files and/or folders that you want to analyze. You can also specify a set of rules",
            "to include only the desired files in your selected folders."
        ]
        self.set_notes([" ".join(module_explanation)])

        self.path_list_display = cps.PathListDisplay()
        predicates = [
            FilePredicate(),
            DirectoryPredicate(),
            ExtensionPredicate()
        ]

        self.filter_choice = cps.Choice("Filter images?",
                                        FILTER_CHOICE_ALL,
                                        value=FILTER_CHOICE_IMAGES,
                                        doc="""
            The <b>Images</b> module will pass all the files specified in the file list
            panel downstream to have a meaningful name assigned to it (so other modules can
            access it) or optionally, to define the relationships between images and associated
            metadata. Enabling file filtering will allow you to specify a subset of the files
            from the file list panel by defining rules to filter the files. This approach is
            useful if, for example, you drag-and-dropped a folder onto the file list panel
            which contains a mixture of images that you want to analyze and other files that
            you want to ignore.
            <p>Several options are available for this setting:
            <ul>
            <li><i>%(FILTER_CHOICE_NONE)s:</i> Do not enable filtering; all files in the File list
            panel will be passed to downstream modules for processing. This option can be
            selected if you are sure that only images are specified in the list.</li>
            <li><i>%(FILTER_CHOICE_IMAGES)s:</i> Only image files will be passed to downstream
            modules. The permissible image formats are provided by a library called Bio-Formats; see
            <a href="http://www.openmicroscopy.org/site/support/bio-formats5/supported-formats.html">here</a> for the formats available.</li>
            <li><i>%(FILTER_CHOICE_CUSTOM)s:</i> Specify custom rules for selecting a subset of
            the files from the File list panel. This approach is useful if, for example, you
            drag-and-dropped a folder onto the File list panel which contains a mixture of images
            that you want to analyze and other files that you want to ignore.</li>
            </ul></p>""" % globals())

        self.filter = cps.Filter("Select the rule criteria",
                                 predicates,
                                 FILTER_DEFAULT,
                                 doc="""
            Specify a set of rules to narrow down the files to be analyzed.
            <p>%(FILTER_RULES_BUTTONS_HELP)s</p>""" % globals())

        self.update_button = cps.PathListRefreshButton(
            "",
            "Apply filters to the file list",
            doc="""
            <i>(Only displayed if filtering based on rules)</i><br>
            Re-display the file list, removing or graying out the files
            that do not pass the current filter.
            """)
    def add_image(self, can_delete=True):
        '''Add an image and its settings to the list of images'''
        image_name = cps.ImageNameSubscriber(
            "Select the input image",
            cps.NONE,
            doc="Select the image to be corrected.")

        corrected_image_name = cps.ImageNameProvider(
            "Name the output image",
            "CorrBlue",
            doc="Enter a name for the corrected image.")

        illum_correct_function_image_name = cps.ImageNameSubscriber(
            "Select the illumination function",
            cps.NONE,
            doc="""\
Select the illumination correction function image that will be used to
carry out the correction. This image is usually produced by another
module or loaded as a .npy format image using the **Images** module or
**LoadSingleImage**.
""")

        divide_or_subtract = cps.Choice(
            "Select how the illumination function is applied",
            [DOS_DIVIDE, DOS_SUBTRACT],
            doc="""\
This choice depends on how the illumination function was calculated and
on your physical model of the way illumination variation affects the
background of images relative to the objects in images; it is also
somewhat empirical.

-  *%(DOS_SUBTRACT)s:* Use this option if the background signal is
   significant relative to the real signal coming from the cells. If you
   created the illumination correction function using
   *%(IC_BACKGROUND)s*, then you will want to choose
   *%(DOS_SUBTRACT)s* here.
-  *%(DOS_DIVIDE)s:* Choose this option if the signal to background
   ratio is high (the cells are stained very strongly). If you created
   the illumination correction function using *%(IC_REGULAR)s*, then
   you will want to choose *%(DOS_DIVIDE)s* here.
""" % globals())

        image_settings = cps.SettingsGroup()
        image_settings.append("image_name", image_name)
        image_settings.append("corrected_image_name", corrected_image_name)
        image_settings.append("illum_correct_function_image_name",
                              illum_correct_function_image_name)
        image_settings.append("divide_or_subtract", divide_or_subtract)
        image_settings.append("rescale_option", RE_NONE)

        if can_delete:
            image_settings.append(
                "remover",
                cps.RemoveSettingButton("", "Remove this image", self.images,
                                        image_settings))
        image_settings.append("divider", cps.Divider())
        self.images.append(image_settings)
Esempio n. 19
0
    def create_settings(self):
        """Create the settings for the module at startup.

        The module allows for an unlimited number of measured objects, each
        of which has an entry in self.object_groups.
        """
        self.image_groups = []
        self.object_groups = []
        self.scale_groups = []
        self.image_count = cps.HiddenCount(self.image_groups)
        self.object_count = cps.HiddenCount(self.object_groups)
        self.scale_count = cps.HiddenCount(self.scale_groups)
        self.add_image_cb(can_remove=False)
        self.add_images = cps.DoSomething("", "Add another image",
                                          self.add_image_cb)
        self.image_divider = cps.Divider()
        self.add_object_cb(can_remove=True)
        self.add_objects = cps.DoSomething("", "Add another object",
                                           self.add_object_cb)
        self.object_divider = cps.Divider()
        self.add_scale_cb(can_remove=False)
        self.add_scales = cps.DoSomething("", "Add another scale",
                                          self.add_scale_cb)
        self.scale_divider = cps.Divider()

        self.wants_gabor = cps.Binary(
            "Measure Gabor features?",
            True,
            doc=
            """The Gabor features measure striped texture in an object, and can
                take a substantial time to calculate.
                <p>Select <i>%(YES)s</i> to measure the Gabor features. Select
                <i>%(NO)s</i> to skip the Gabor feature calculation if it is not
                informative for your images.</p>""" % globals())

        self.gabor_angles = cps.Integer(
            "Number of angles to compute for Gabor",
            4,
            2,
            doc="""
            <i>(Used only if Gabor features are measured)</i><br>
            Enter the number of angles to use for each Gabor texture measurement.
            The default value is 4 which detects bands in the horizontal, vertical and diagonal
            orientations.""")
        self.images_or_objects = cps.Choice(
            "Measure images or objects?", [IO_IMAGES, IO_OBJECTS, IO_BOTH],
            value=IO_BOTH,
            doc="""This setting determines whether the module
            computes image-wide measurements, per-object measurements or both.
            <ul>
            <li><i>%(IO_IMAGES)s:</i> Select if you only want to measure the texture of objects.</li>
            <li><i>%(IO_OBJECTS)s:</i> Select if your pipeline does not contain objects or if
            you only want to make per-image measurements.</li>
            <li><i>%(IO_BOTH)s:</i> Select to make both image and object measurements.</li>
            </ul>""" % globals())
Esempio n. 20
0
    def create_settings(self):
        self.input_type = cps.Choice("Select the type of input",
                                     [IF_IMAGE, IF_OBJECTS], IF_IMAGE)

        self.image_name = cps.ImageNameSubscriber("Select input images",
                                                  cps.NONE)

        self.objects_name = cps.ObjectNameSubscriber(
            "Select the input objects",
            cps.NONE,
        )

        self.output_name = cps.ImageNameProvider(
            "Input the output image stack name",
            "BinStack",
            doc="""
            Input the output name.
            """ % globals())

        self.main_object_def = cps.Choice(
            "How should the main label be determined?",
            [SEL_MID, SEL_MAXAREA, SEL_PROVIDED],
            SEL_MID,
            doc="""
            The main object can be determined by 3 ways:
            <ul>
            <li> %(SEL_PROVIDED)s: Label provided by metadata or
            manual. <\li>
            <li> %(SEL_MAXAREA)s: Label with the biggest area is assumed to be
            the main label. <\li>
            <li> %(SEL_MID)s: The label closest to the middle of the image is
            considered the main label. <\li>
            <\ul>
            """ % globals())

        self.main_object_id = cps.Text("Indicate the object id",
                                       '1',
                                       doc="""
                Indicates the id from the main object.
                Rightclick to choose a metadata value.
                """ % globals(),
                                       metadata=True)
    def add_outline(self, can_remove=True):
        group = cps.SettingsGroup()
        if can_remove:
            group.append("divider", cps.Divider(line=False))

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

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

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

        self.outlines.append(group)
 def create_settings(self):
     self.images = []
     self.objects = []
     self.bin_counts = []
     self.heatmaps = []
     self.image_count = cps.HiddenCount(self.images)
     self.object_count = cps.HiddenCount(self.objects)
     self.bin_counts_count = cps.HiddenCount(self.bin_counts)
     self.heatmap_count = cps.HiddenCount(self.heatmaps)
     self.wants_zernikes = cps.Choice(
         "Calculate intensity Zernikes?",
         Z_ALL,
         doc="""This setting determines whether the intensity Zernike
         moments are calculated. Choose <i>%(Z_NONE)s</i> to save computation
         time by not calculating the Zernike moments. Choose
         <i>%(Z_MAGNITUDES)s</i> to only save the magnitude information
         and discard information related to the object's angular orientation.
         Choose <i>%(Z_MAGNITUDES_AND_PHASE)s</i> to save the phase information
         as well. The last option lets you recover each object's rough
         appearance from the Zernikes but may not contribute useful
         information if used to classify phenotypes.""" % globals())
     self.zernike_degree = cps.Integer(
         "Maximum zernike moment",
         value=9,
         minval=1,
         maxval=20,
         doc="""(<i>Only if "%s" is %s or %s</i>)<br>
         This is the maximum radial moment that will be calculated.
         There are increasing numbers of azimuthal moments as you increase
         the radial moment, so higher values are increasingly expensive
         to calculate.""" %
         (self.wants_zernikes.text, Z_MAGNITUDES, Z_MAGNITUDES_AND_PHASE))
     self.add_image_button = cps.DoSomething("", "Add another image",
                                             self.add_image)
     self.spacer_1 = cps.Divider()
     self.add_object_button = cps.DoSomething("", "Add another object",
                                              self.add_object)
     self.spacer_2 = cps.Divider()
     self.add_bin_count_button = cps.DoSomething("",
                                                 "Add another set of bins",
                                                 self.add_bin_count)
     self.spacer_3 = cps.Divider()
     self.add_heatmap_button = cps.DoSomething(
         "",
         "Add another heatmap display",
         self.add_heatmap,
         doc="""
     Press this button to add a display of one of the radial distribution
     measurements. Each radial band of the object is colored using a
     heatmap according to the measurement value for that band.""")
     self.add_image(can_remove=False)
     self.add_object(can_remove=False)
     self.add_bin_count(can_remove=False)
    def add_image(self, can_delete=True):
        '''Add an image and its settings to the list of images'''
        image_name = cps.ImageNameSubscriber("Select the input image",
                                             cps.NONE,
                                             doc='''
            Select the image to be corrected.''')

        corrected_image_name = cps.ImageNameProvider("Name the output image",
                                                     "SpillCorrected",
                                                     doc='''
            Enter a name for the corrected image.''')

        spill_correct_function_image_name = cps.ImageNameSubscriber(
            "Select the spillover function image",
            cps.NONE,
            doc='''
            Select the spillover correction image that will be used to
            carry out the correction. This image is usually produced by the R
            software CATALYST or loaded as a .tiff format image using the
            <b>Images</b> module or
            <b>LoadSingleImage</b>.''')
        spill_correct_method = cps.Choice("Spillover correction method",
                                          [METHOD_LS, METHOD_NNLS],
                                          doc="""
            Select the spillover correction method.
            <ul>
            <li><i>%(METHOD_LS)s:</i> Gives the least square solution
            for overdetermined solutions or the exact solution for exactly 
            constraint problems. </li>
            <li><i>%(METHOD_NNLS)s:</i> Gives the non linear least squares
            solution: The most accurate solution, according to the least
            squares criterium, without any negative values.
            </li>
            </ul>
            """ % globals())

        image_settings = cps.SettingsGroup()
        image_settings.append("image_name", image_name)
        image_settings.append("corrected_image_name", corrected_image_name)
        image_settings.append("spill_correct_function_image_name",
                              spill_correct_function_image_name)
        image_settings.append("spill_correct_method", spill_correct_method)

        if can_delete:
            image_settings.append(
                "remover",
                cps.RemoveSettingButton("", "Remove this image", self.images,
                                        image_settings))
        image_settings.append("divider", cps.Divider())
        self.images.append(image_settings)
    def add_object(self, can_remove=True):
        '''Add an object to be measured (plus optional centers)'''
        group = cps.SettingsGroup()
        if can_remove:
            group.append("divider", cps.Divider(line=False))
        group.append(
            "object_name",
            cps.ObjectNameSubscriber("Select objects to measure",
                                     cps.NONE,
                                     doc="""
                Select the objects that you want to measure the intensity from."""
                                     ))

        group.append(
            "center_choice",
            cps.Choice("Object to use as center?",
                       C_ALL,
                       doc="""
                There are three ways to specify the center of the radial measurement:
                <ul>
                <li><i>%(C_SELF)s:</i> Use the centers of these objects for the
                radial measurement.</li>
                <li><i>%(C_CENTERS_OF_OTHER)s:</i> Use the centers of other objects
                for the radial measurement.</li>
                <li><i>%(C_EDGES_OF_OTHER)s:</i> Measure distances from the
                edge of the other object to each pixel outside of the
                centering object. Do not include pixels within the centering
                object in the radial measurement calculations.</li>
                </ul>
                For example, if measuring the radial distribution in a Cell
                object, you can use the center of the Cell objects (<i>%(C_SELF)s</i>)
                or you can use previously identified Nuclei objects as
                the centers (<i>%(C_CENTERS_OF_OTHER)s</i>).""" % globals()))

        group.append(
            "center_object_name",
            cps.ObjectNameSubscriber("Select objects to use as centers",
                                     cps.NONE,
                                     doc="""
                <i>(Used only if "%(C_CENTERS_OF_OTHER)s" are selected for centers)</i><br>
                Select the object to use as the center, or select <i>None</i> to
                use the input object centers (which is the same as selecting
                <i>%(C_SELF)s</i> for the object centers).""" % globals()))

        if can_remove:
            group.append(
                "remover",
                cps.RemoveSettingButton("", "Remove this object", self.objects,
                                        group))
        self.objects.append(group)
Esempio n. 25
0
    def add_channel(self, can_remove=True):
        '''Add another channel to the channels list'''
        group = cps.SettingsGroup()
        group.can_remove = can_remove
        group.append(
            "channel_choice",
            cps.Choice("Channel number",
                       self.channel_names,
                       self.channel_names[len(self.channels) %
                                          len(self.channel_names)],
                       doc="""\
*(Used only when splitting images)*

This setting chooses a channel to be processed. For example, *Red: 1*
is the first
channel in a .TIF or the red channel in a traditional image file.
*Green: 2* and *Blue: 3* are the second and third channels of a TIF or
the green and blue channels in other formats. *Alpha: 4* is the
transparency channel for image formats that support transparency and is
channel # 4 for a .TIF file. **ColorToGray** will fail to process an
image if you select a channel that is not supported by that image, for
example, “5” for a three-channel .PNG file."""))

        group.append(
            "contribution",
            cps.Float("Relative weight of the channel",
                      1,
                      0,
                      doc='''\
*(Used only when combining channels)*

Relative weights: If all relative weights are equal, all three colors
contribute equally in the final image. To weight colors relative to each
other, increase or decrease the relative weights.'''))

        group.append(
            "image_name",
            cps.ImageNameProvider("Image name",
                                  value="Channel%d" % (len(self.channels) + 1),
                                  doc="""\
*(Used only when splitting images)*

Select the name of the output grayscale image."""))

        if group.can_remove:
            group.append(
                "remover",
                cps.RemoveSettingButton("", "Remove this channel",
                                        self.channels, group))
        self.channels.append(group)
Esempio n. 26
0
    def create_settings(self):
        self.image_name = cps.ImageNameSubscriber('Select the input image',
                                                  cps.NONE)

        self.transformed_image_name = cps.ImageNameProvider(
            "Name the transformed image", 'DistanceImage')

        self.transform_method = cps.Choice('Select a transformation',
                                           [DISTANCE_BORDER],
                                           doc="""
            <ul>
            <li><i>%(DISTANCE_BORDER)s</i> Transforms the binary image to an
            eucledian distance transform to the border between the binary
            regions. The distance to a nonzero pixel will be positive, while
            the distance to a zero pixel will be negative.</li>
            </ul>""" % globals())
    def add_output(self, can_remove=True):
        group = cps.SettingsGroup()
        group.append("output_image",
                     cps.ImageNameProvider("Output image", "Probability"))

        group.append(
            "class_name",
            cps.Choice("Class name",
                       choices=self.get_class_names(),
                       choices_fn=self.get_class_names))
        if can_remove:
            group.append(
                "remover",
                cps.RemoveSettingButton("Remove object", "Remove",
                                        self.outputs, group))
        self.outputs.append(group)
Esempio n. 28
0
    def create_settings(self):
        self.image_name = cps.ImageNameSubscriber(
            "Select the input image", cps.NONE, doc='''
            Select the image to be resized.''')

        self.cropped_image_name = cps.ImageNameProvider(
            "Name the output image", "CroppedImage", doc='''
            Enter the name of the cropped image.''')

        self.crop_random = cps.Choice(
            'Crop random or specified section?', [C_RANDOM, C_SPECIFIC, C_SEED_METADATA])

        self.crop_x = cps.Text(
            "X of upper left corner", '0', doc='''
            X position.''', metadata=True)

        self.crop_y = cps.Text(
            "Y of upper left corner", '0', doc='''
            Y position.''', metadata=True)

        self.crop_w = cps.Text(
            "W width", '100', doc='''
            Width of cut.''', metadata=True)

        self.crop_h = cps.Text(
            "H height", '100', doc='''
            Height of cut.''', metadata=True)

        self.seed_metadata = cps.Text(
            "Optional Random Seed", '', doc='''
            Sets the seed based on this string.
            Use the `Metadata` module to generate metadata and right click into the
            field to select metadata.''', metadata=True
        )

        self.separator = cps.Divider(line=False)

        self.additional_images = []

        self.additional_image_count = cps.HiddenCount(
            self.additional_images, "Additional image count")

        self.add_button = cps.DoSomething("", "Add another image",
                                          self.add_image)
Esempio n. 29
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())
Esempio n. 30
0
    def create_settings(self):
        self.omero_host = cps.Text(
            "Host address",
            DEFAULT_OMERO_HOST,
            doc=
            """Host address of an omero server. Can be an ip-address or a hostname.""",
        )
        self.omero_port = cps.Integer("Port",
                                      DEFAULT_OMERO_PORT,
                                      doc="""Port of an omero server.""")
        self.omero_username = cps.Text(
            "Username",
            DEFAULT_OMERO_USERNAME,
            doc="""Username is required for login into an omero server.""",
        )
        self.omero_password = cps.Text(
            "Password",
            DEFAULT_OMERO_PASSWORD,
            doc="""Password is required for login into an omero server.""",
        )
        self.omero_object = cps.Choice("Object to load",
                                       [MS_IMAGE, MS_DATASET, MS_PLATE],
                                       DEFAULT_OMERO_OBJECT)
        self.omero_object_id = cps.Integer(
            "Object id",
            DEFAULT_OMERO_OBJECT_ID,
            doc=
            """This is a number that omero uses to uniquely identify an object, be it a dataset, plate, or image.""",
        )
        self.load_channels = cps.DoSomething("", "Load channels from OMERO",
                                             self.load_channels)

        # All the omero images that are loaded are assumed to have
        # as many or more channels than the highest channel number
        # the user specifies.
        self.channels = []
        self.channel_count = cps.HiddenCount(self.channels, "Channel count")
        # Add the first channel
        self.add_channelfn(False)

        # Button for adding other channels
        self.add_channel = cps.DoSomething("", "Add another channel",
                                           self.add_channelfn)