Пример #1
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())
Пример #2
0
 def create_settings(self):
     self.divider_top = cps.Divider(line=False)
     self.images = []
     self.image_count = cps.HiddenCount(self.images, "Image count")
     self.add_image(can_remove = False)
     self.add_button = cps.DoSomething("", "Add another image", self.add_image)
     self.divider_bottom = cps.Divider(line=False)
Пример #3
0
    def create_settings(self):
        self.pipeline = None
        self.ipds = []
        self.imported_metadata = []
        module_explanation = [
            "The %s module optionally allows you to extract information" %
            self.module_name,
            "describing your images (i.e, metadata) which will be stored along",
            "with your measurements. This information can be contained in the",
            "file name and/or location, or in an external file."
        ]
        self.set_notes([" ".join(module_explanation)])

        self.wants_metadata = cps.Binary("Extract metadata?",
                                         False,
                                         doc="""
            Do your file or path names or file headers contain information\n
            (metadata) you would like to extract and store along with your 
            measurements?""")

        self.extraction_methods = []
        self.add_extraction_method(False)
        self.extraction_method_count = cps.HiddenCount(
            self.extraction_methods, "Extraction method count")
        self.add_extraction_method_button = cps.DoSomething(
            "Add another extraction method", "Add", self.add_extraction_method)
        self.table = cps.Table("", use_sash=True)
        self.update_table_button = cps.DoSomething("Update table", "Update",
                                                   self.update_table)
Пример #4
0
 def create_settings(self):
     """Create the settings variables here and name the module"""
     self.operands = []
     self.count = cps.HiddenCount(self.operands)
     self.add_operand(can_remove=False)
     self.add_operand_button = cps.DoSomething("", "Add another area", self.add_operand)
     self.remover = cps.DoSomething("", "Remove this area", self.remove)
Пример #5
0
 def create_settings(self):
     self.flags = []
     self.flag_count = cps.HiddenCount(self.flags)
     self.add_flag_button = cps.DoSomething("", "Add another flag",
                                            self.add_flag)
     self.spacer_1 = cps.Divider()
     self.add_flag(can_delete=False)
Пример #6
0
    def create_settings(self):
        self.image_name = cps.ImageNameSubscriber("Select the input image",
                                                  cps.NONE)

        self.probability_maps = []

        self.probability_map_count = cps.HiddenCount(self.probability_maps,
                                                     "Probability map count")

        self.add_probability_map(False)

        self.add_probability_button = cps.DoSomething(
            "",
            "Add another probability map",
            self.add_probability_map,
            doc="""
            Press this button to output another
            probability map image from the classifier. Ilastik can be trained
            to recognize any number of classes of pixels. You can generate
            probability maps for any or all of them simultaneously by adding
            more images.""")

        self.h5_directory = cps.DirectoryPath(
            "Classifier file location",
            dir_choices=[
                DEFAULT_OUTPUT_FOLDER_NAME, DEFAULT_INPUT_FOLDER_NAME,
                ABSOLUTE_FOLDER_NAME, DEFAULT_INPUT_SUBFOLDER_NAME,
                DEFAULT_OUTPUT_SUBFOLDER_NAME, URL_FOLDER_NAME
            ],
            allow_metadata=False,
            doc="""
                Select the folder containing the classifier file to be loaded.
            %(IO_FOLDER_CHOICE_HELP_TEXT)s""" % globals())

        def get_directory_fn():
            '''Get the directory for the CSV file name'''
            return self.h5_directory.get_absolute_path()

        def set_directory_fn(path):
            dir_choice, custom_path = self.h5_directory.get_parts_from_path(
                path)
            self.h5_directory.join_parts(dir_choice, custom_path)

        self.classifier_file_name = cps.FilenameText(
            "Classfier file name",
            cps.NONE,
            doc="""This is the name of the Classfier file.""",
            get_directory_fn=get_directory_fn,
            set_directory_fn=set_directory_fn,
            browse_msg="Choose Classifier file",
            exts=[("Classfier file (*.h5)", "*.h5"),
                  ("All files (*.*)", "*.*")])
        self.no_ilastik_msg = cps.HTMLText("",
                                           content="""
            ClassifyPixels cannot run on this platform because
            the necessary libraries are not available. ClassifyPixels is
            supported on 64-bit versions of Windows Vista, Windows 7 and
            Windows 8 and on Linux.""",
                                           size=(-1, 50))
Пример #7
0
    def create_settings(self):
        self.image_name = cps.ImageNameSubscriber("Select the input image",
                                                  "None", doc = '''What did you call the image to be resized?''')

        self.resized_image_name = cps.ImageNameProvider("Name the output image",
                                                        "ResizedBlue", doc = '''What do you want to call the resized image?''')

        self.size_method = cps.Choice("Select resizing method",
                                      R_ALL, doc = """How do you want to resize the image? 
                                      <ul><li><i>Resize by a fraction or multiple of the original size:</i> 
                                      Enter a single value which specifies the scaling. </li>
                                      <li><i>Resize by specifying desired final dimensions:</i></li> 
                                      Enter the new height and width of the resized image.</ul>""")

        self.resizing_factor = cps.Float("Resizing factor",
                                         .25, minval=0, doc = '''
                                         <i>(Used only if resizing by a fraction or multiple of the original size)</i><br>
                                         Numbers less than one (that is, fractions) will shrink the image; 
                                         numbers greater than one (that is, multiples) will enlarge the image.''')

        self.use_manual_or_image = cps.Choice("How do you want to specify the dimensions?",C_ALL, doc = """
                                        <i>(Used only if resizing by specifying the dimensions)</i><br>
                                        You have two options on how to resize your image:
                                        <ul>
                                        <li><i>Manual:</i> Specify the height and width of the output image.</li>
                                        <li><i>Image:</i> Specify an image and the input image will be resized
                                        to the same dimensions.</li>
                                        </ul>""")
        
        self.specific_width = cps.Integer("Width of the final image, in pixels", 100, minval=1, doc = '''
                                         <i>(Used only if resizing by specifying desired final dimensions)</i><br>
                                         Enter the desired width of the final image.''')

        self.specific_height = cps.Integer("Height of the final image, in pixels", 100, minval=1, doc = '''
                                         <i>(Used only if resizing by specifying desired final dimensions)</i><br>
                                         Enter the desired height of the final image.''')
        
        self.specific_image = cps.ImageNameSubscriber("Select the image with the desired dimensions", "None", doc = """"
                                        <i>(Used only if resizing by specifying desired final dimensions using an image)</i><br>
                                        The input image will be resized to the dimensions of the specified image.""")

        self.interpolation = cps.Choice("Interpolation method",
                                        I_ALL, doc = '''<ul><li><i>Nearest Neighbor:</i> Each output pixel is given the intensity of the nearest
                                        corresponding pixel in the input image.</li>
                                        <li><i>Bilinear:</i> Each output pixel is given the intensity of the weighted average
                                        of the 2x2 neighborhood at the corresponding position in the input image.</li>
                                        <li><i>Bicubic:</i> Each output pixel is given the intensity of the weighted average
                                        of the 4x4 neighborhood at the corresponding position in the input image.</li>
                                        </ul>''')
        
        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)
 def create_settings(self):
     self.images = []
     self.objects = []
     self.bin_counts = []
     self.image_count = cps.HiddenCount(self.images)
     self.object_count = cps.HiddenCount(self.objects)
     self.bin_counts_count = cps.HiddenCount(self.bin_counts)
     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.add_image(can_remove = False)
     self.add_object(can_remove = False)
     self.add_bin_count(can_remove = False)
Пример #9
0
 def create_settings(self):
     self.images = []
     self.add_image(can_remove = False)
     self.image_count = cps.HiddenCount(self.images)
     self.add_image_button = cps.DoSomething("", "Add another image", self.add_image)
     self.divider = cps.Divider()
     self.objects = []
     self.add_object(can_remove = False)
     self.add_object_button = cps.DoSomething("", "Add another object", self.add_object)
Пример #10
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.""")
Пример #11
0
 def add_flag(self, can_delete=True):
     group = cps.SettingsGroup()
     group.append("divider1", cps.Divider(line=False))
     group.append("measurement_settings", [])
     group.append("measurement_count", cps.HiddenCount(group.measurement_settings))
     group.append("category", cps.Text("Name the flag's category","Metadata", doc = '''
                             Name a measurement category in which the flag should reside. Metadata allows you to 
                             later group images in the <b>LoadImages</b> module based on the flag, if you load the 
                             flag data in a future pipeline via the <b>LoadData</b> module.  Otherwise, you might 
                             choose to have the flag stored in the "Image" category or using some other word you prefer.  
                             The flag is stored as a per-image measurement whose name is a combination of the
                             flag's category and feature name, underscore delimited. 
                             For instance, if the measurement category is
                             "Metadata" and the feature name is "QCFlag", then the default
                             measurement name would be "Metadata_QCFlag". %s'''%USING_METADATA_HELP_REF))
     
     group.append("feature_name", cps.Text("Name the flag","QCFlag", doc = '''
                             The flag is stored as a per-image measurement whose name is a combination of the
                             flag's category and feature name, underscore delimited. 
                             For instance, if the measurement category is
                             "Metadata" and the feature name is "QCFlag", then the default
                             measurement name would be "Metadata_QCFlag".'''))
     
     group.append("combination_choice", cps.Choice("Flag if any, or all, measurement(s) fails to meet the criteria?",
                             [ C_ANY, C_ALL], doc = '''
                             <ul>
                             <li><i>Any:</i> An image will be flagged if any of its measurements fail. This can be useful
                             for flagging images possessing multiple QC flaws; for example, you can flag all bright images and all out of focus images with one flag.</li>
                             <li><i>All:</i> A flag will only be assigned if all measurements fail.  This can be useful for flagging  images that possess only a combination
                             of QC flaws; for example, you can flag only images that are both bright and out of focus.</li>
                             </ul>'''))
     
     group.append(
         "wants_skip", cps.Binary("Skip image set if flagged?", False,
         doc = """You can skip the remainder of the pipeline for image sets
         that are flagged by checking this setting. If you check this
         setting, CellProfiler will not run subsequent modules in the
         pipeline on the images in any image set that is flagged. 
         CellProfiler will continue to process the pipeline if you leave
         the setting unchecked.<p>
         You may want to check this setting in order to filter out
         unwanted images during processing. For instance, you may want
         to exclude out of focus images when running 
         <b>CorrectIllumination_Calculate</b>. You can do this with a
         pipeline that measures image quality and flags inappropriate
         images before it runs <b>CorrectIllumination_Calculate</b>"""))
         
     group.append("add_measurement_button", 
                  cps.DoSomething("",
                                  "Add another measurement",
                                  self.add_measurement, group))
     self.add_measurement(group, False if not can_delete else True)
     if can_delete:
         group.append("remover", cps.RemoveSettingButton("", "Remove this flag", self.flags, group))
     group.append("divider2", cps.Divider(line=True))
     self.flags.append(group)
Пример #12
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)
Пример #13
0
    def create_settings(self):
        """Create the settings for the module at startup.
        """
        self.image_groups = []
        self.image_count = cps.HiddenCount(self.image_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.object_groups = []
        self.object_count = cps.HiddenCount(self.object_groups)
        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.bins_groups = []
        self.bins_count = cps.HiddenCount(self.bins_groups)
        self.add_bins_cb(can_remove=False)
        self.add_bins = cps.DoSomething("", "Add another histogram",
                                        self.add_bins_cb)
Пример #14
0
    def create_settings(self):
        self.image_name = cps.ImageNameSubscriber("Select the input image",
                                                  "None")

        self.probability_maps = []

        self.probability_map_count = cps.HiddenCount(self.probability_maps,
                                                     "Probability map count")

        self.add_probability_map(False)

        self.add_probability_button = cps.DoSomething(
            "Add another probability map",
            "Add",
            self.add_probability_map,
            doc="""Press the <i>Add</i> button to output another
            probability map image from the classifier. Ilastik can be trained
            to recognize any number of classes of pixels. You can generate
            probability maps for any or all of them simultaneously by adding
            more images.""")

        self.h5_directory = cps.DirectoryPath(
            "Classifier file location",
            dir_choices=[
                DEFAULT_OUTPUT_FOLDER_NAME, DEFAULT_INPUT_FOLDER_NAME,
                ABSOLUTE_FOLDER_NAME, DEFAULT_INPUT_SUBFOLDER_NAME,
                DEFAULT_OUTPUT_SUBFOLDER_NAME
            ],
            allow_metadata=False,
            doc=
            """Select the folder containing the classifier file to be loaded. 
            %(IO_FOLDER_CHOICE_HELP_TEXT)s""" % globals())

        def get_directory_fn():
            '''Get the directory for the CSV file name'''
            return self.h5_directory.get_absolute_path()

        def set_directory_fn(path):
            dir_choice, custom_path = self.h5_directory.get_parts_from_path(
                path)
            self.h5_directory.join_parts(dir_choice, custom_path)

        self.classifier_file_name = cps.FilenameText(
            "Classfier file name",
            "None",
            doc="""This is the name of the Classfier file.""",
            get_directory_fn=get_directory_fn,
            set_directory_fn=set_directory_fn,
            browse_msg="Choose Classifier file",
            exts=[("Classfier file (*.h5)", "*.h5"),
                  ("All files (*.*)", "*.*")])
Пример #15
0
 def create_settings(self):
     self.outputs = []
     self.stain_count = cps.HiddenCount(self.outputs, "Stain count")
     self.input_image_name = cps.ImageNameSubscriber(
         "Color image", "None",
         doc = """Choose the name of the histologically stained color image
         loaded or created by some prior module.""")
     self.add_image(False)
     self.add_image_button = cps.DoSomething(
         "Add another stain", "Add stain", self.add_image,
         doc = """Press this button to add another stain to the list.
         You will be able to name the image produced and to either pick
         the stain from a list of precalibrated stains or to enter
         custom values for the stain's red, green and blue absorbance.""")
Пример #16
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])

        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.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)
Пример #17
0
    def create_settings(self):
        self.pipeline = None
        self.metadata_keys = {}

        module_explanation = [
            "The %s module optionally allows you to split your list of images into image subsets"
            % self.module_name,
            "(groups) which will be processed independently of each other. Examples of",
            "groupings include screening batches, microtiter plates, time-lapse movies, etc."
        ]
        self.set_notes([" ".join(module_explanation)])

        self.wants_groups = cps.Binary("Do you want to group your images?",
                                       False,
                                       doc="""
            Select <i>%(YES)s</i> if you need to split your images into image subsets (or <i>groups</i>) such that each
            group is processed independently of each other. See the main module
            help for more details.""" % globals())

        self.grouping_text = cps.HTMLText("",
                                          content="""
            Each unique metadata value (or combination of values) 
            will be defined as a group""",
                                          size=(30, 2))
        self.grouping_metadata = []
        self.grouping_metadata_count = cps.HiddenCount(
            self.grouping_metadata, "grouping metadata count")
        self.add_grouping_metadata(can_remove=False)
        self.add_grouping_metadata_button = cps.DoSomething(
            "", "Add another metadata item", self.add_grouping_metadata)

        self.grouping_list = cps.Table("Grouping list",
                                       min_size=(300, 100),
                                       doc="""
            This list shows the unique values of the selected metadata under the "Group" column; each of the unique values 
            comprises a group. The "Count" column shows the number of image sets that included in a given group; this
            is useful as a "sanity check", to make sure that the expected number of images are present. For example,
            if you are grouping by per-plate metadata from a 384-well assay with 2 sites per well consisting of 3 plates, 
            you would expect to see 3 groups (each from the 3 unique plate IDs), with 384 wells &times; 2 sites/well 
            = 768 image sets in each.""")

        self.image_set_list = cps.Table("Image sets",
                                        doc="""
            This list displays the file name and location of each of the image sets that comprise the
            group. For example, if you are grouping by per-plate metadata from a 384-well assay with 2 sites per well 
            consisting of 3 plates, you would expect to see a table consisting of 3 plates &times; 384 wells/plate 
            &times;2 sites/well = 2304 rows.""")
Пример #18
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)
Пример #19
0
 def create_settings(self):
     self.groups = []
     #
     # A hidden count setting saves the number of items in a list
     # to the pipeline. When you load the module, you can read the
     # hidden count and make sure your module has the correct number of
     # groups before the settings are transferred.
     #
     self.group_count = cps.HiddenCount(self.groups)
     #
     # A DoSomething setting looks like a button. When you press the button,
     # it does something: it calls the callback function which, in this case,
     # is "self.add_group()"
     #
     self.add_group_button = cps.DoSomething(
         "Add another group", "Add", self.add_group,
         doc = "Press this button to add another group")
     #
     # We call "add_group()" with a False argument. This tells add_group
     # to make sure and not add a button that would allow the user to
     # remove the first group
     #
     self.add_group(False)
Пример #20
0
    def create_settings(self):
        '''Create the UI settings for this module'''

        self.recipients = []
        self.recipient_count = cps.HiddenCount(self.recipients)
        self.add_recipient(False)
        self.add_recipient_button = cps.DoSomething("Add a recipient address.",
                                                    "Add address",
                                                    self.add_recipient)

        if sys.platform.startswith("win"):
            user = os.environ.get("USERNAME", "yourname@yourdomain")
        else:
            user = os.environ.get("USER", "yourname@yourdomain")

        self.from_address = cps.Text("Sender address",
                                     user,
                                     doc="""
            Enter the address for the email's "From" field.""")

        self.subject = cps.Text("Subject line",
                                "CellProfiler notification",
                                metadata=True,
                                doc="""
            Enter the text for the email's subject line. If you have metadata 
            associated with your images, you can use metadata tags here. %(USING_METADATA_TAGS_REF)s<br>
            For instance, if you have plate metadata,
            you might use the line, "CellProfiler: processing plate " and insert the metadata tag
            for the plate at the end. %(USING_METADATA_HELP_REF)s.""" %
                                globals())

        self.smtp_server = cps.Text("Server name",
                                    "mail",
                                    doc="""
            Enter the address of your SMTP server. You can ask your
            network administrator for your outgoing mail server which is often
            made up of part of your email address, e.g., 
            "*****@*****.**". You might be able to find this information
            by checking your settings or preferences in whatever email program
            you use.""")

        self.port = cps.Integer("Port",
                                smtplib.SMTP_PORT,
                                0,
                                65535,
                                doc="""
            Enter your server's SMTP port. The default (25) is the
            port used by most SMTP servers. Your network administrator may
            have set up SMTP to use a different port; also, the connection
            security settings may require a different port.""")

        self.connection_security = cps.Choice("Select connection security",
                                              C_ALL,
                                              doc="""
            Select the connection security. Your network administrator 
            can tell you which setting is appropriate, or you can check the
            settings on your favorite email program.""")

        self.use_authentication = cps.Binary(
            "Username and password required to login?",
            False,
            doc="""
            Select <i>%(YES)s</i> if you need to enter a username and password 
            to authenticate.""" % globals())

        self.username = cps.Text("Username",
                                 user,
                                 doc="""
            Enter your server's SMTP username.""")

        self.password = cps.Text("Password",
                                 "",
                                 doc="""
            Enter your server's SMTP password.""")

        self.when = []
        self.when_count = cps.HiddenCount(self.when)
        self.add_when(False)

        self.add_when_button = cps.DoSomething("Add another email event",
                                               "Add email event",
                                               self.add_when,
                                               doc="""
            Press this button to add another event or condition.
            <b>SendEmail</b> will send an email when this event happens""")
Пример #21
0
    def create_settings(self):
        """Create the settings for the module

        Create the settings for the module during initialization.
        """
        self.contrast_choice = cps.Choice(
            "Make each classification decision on how many measurements?",
            [BY_SINGLE_MEASUREMENT, BY_TWO_MEASUREMENTS],
            doc="""
            This setting controls how many measurements are used to make a classifications decision
            for each object:
            <ul>
            <li><i>%(BY_SINGLE_MEASUREMENT)s:</i> Classifies each object based on a single measurement.</li>
            <li><i>%(BY_TWO_MEASUREMENTS)s:</i> Classifies each object based on a pair of measurements taken
            together (that is, an object must meet two criteria to belong to a class).</li>
            </ul>""" % globals())

        ############### Single measurement settings ##################
        #
        # A list holding groupings for each of the single measurements
        # to be done
        #
        self.single_measurements = []
        #
        # A count of # of measurements
        #
        self.single_measurement_count = cps.HiddenCount(
            self.single_measurements)
        #
        # Add one single measurement to start off
        #
        self.add_single_measurement(False)
        #
        # A button to press to get another measurement
        #
        self.add_measurement_button = cps.DoSomething(
            "", "Add another classification", self.add_single_measurement)
        #
        ############### Two-measurement settings #####################
        #
        # The object for the contrasting method
        #
        self.object_name = cps.ObjectNameSubscriber("Select the object name",
                                                    cps.NONE,
                                                    doc="""
            Choose the object that you want to measure from the list.
            This should be an object created by a previous module such as
            <b>IdentifyPrimaryObjects</b>, <b>IdentifySecondaryObjects</b>, or
            <b>IdentifyTertiaryObjects</b>.""")

        #
        # The two measurements for the contrasting method
        #
        def object_fn():
            return self.object_name.value

        self.first_measurement = cps.Measurement(
            "Select the first measurement",
            object_fn,
            doc="""
            Choose a measurement made on the above object. This is
            the first of two measurements that will be contrasted together.
            The measurement should be one made on the object in a prior
            module.""")

        self.first_threshold_method = cps.Choice(
            "Method to select the cutoff", [TM_MEAN, TM_MEDIAN, TM_CUSTOM],
            doc="""
            Objects are classified as being above or below a cutoff
            value for a measurement. You can set this cutoff threshold in one
            of three ways:<br>
            <ul>
            <li><i>%(TM_MEAN)s</i>: At the mean
            of the measurement's value for all objects in the image cycle.</li>
            <li><i>%(TM_MEDIAN)s</i>: At the median of the
            measurement's value for all objects in the image set.</li>
            <li><i>%(TM_CUSTOM)s</i>: You specify a custom threshold value.</li>
            </ul>""" % globals())

        self.first_threshold = cps.Float("Enter the cutoff value",
                                         0.5,
                                         doc="""
            This is the cutoff value separating objects in the two
            classes.""")

        self.second_measurement = cps.Measurement(
            "Select the second measurement",
            object_fn,
            doc="""
            Select a measurement made on the above object. This is
            the second of two measurements that will be contrasted together.
            The measurement should be one made on the object in a prior
            module.""")

        self.second_threshold_method = cps.Choice(
            "Method to select the cutoff", [TM_MEAN, TM_MEDIAN, TM_CUSTOM],
            doc="""
            Objects are classified as being above or below a cutoff
            value for a measurement. You can set this cutoff threshold in one
            of three ways:<br>
            <ul>
            <li><i>%(TM_MEAN)s:</i> At the mean
            of the measurement's value for all objects in the image cycle.</li>
            <li><i>%(TM_MEDIAN)s:</i> At the median of the
            measurement's value for all objects in the image set.</li>
            <li><i>%(TM_CUSTOM)s:</i> You specify a custom threshold value.</li>
            </ul>""" % globals())

        self.second_threshold = cps.Float("Enter the cutoff value",
                                          0.5,
                                          doc="""
            This is the cutoff value separating objects in the two
            classes.""")

        self.wants_custom_names = cps.Binary("Use custom names for the bins?",
                                             False,
                                             doc="""
            Select <i>%(YES)s</i> if you want to specify the names of each bin
            measurement. <br>
            Select <i>%(NO)s</i> to create names based on the
            measurements. For instance, for
            "Intensity_MeanIntensity_Green" and "Intensity_TotalIntensity_Blue",
            the module generates measurements such as
            "Classify_Intensity_MeanIntensity_Green_High_Intensity_TotalIntensity_Low"."""
                                             % globals())

        self.low_low_custom_name = cps.AlphanumericText(
            "Enter the low-low bin name",
            "low_low",
            doc="""
            <i>(Used only if using a pair of measurements)</i><br>
            Name of the measurement for objects that
            fall below the threshold for both measurements.""")

        self.low_high_custom_name = cps.AlphanumericText(
            "Enter the low-high bin name",
            "low_high",
            doc="""
            <i>(Used only if using a pair of measurements)</i><br>
            Name of the measurement for objects whose
            first measurement is below threshold and whose second measurement
            is above threshold.""")

        self.high_low_custom_name = cps.AlphanumericText(
            "Enter the high-low bin name",
            "high_low",
            doc="""
            <i>(Used only if using a pair of measurements)</i><br>
            Name of the measurement for objects whose
            first measurement is above threshold and whose second measurement
            is below threshold.""")

        self.high_high_custom_name = cps.AlphanumericText(
            "Enter the high-high bin name",
            "high_high",
            doc="""
            <i>(Used only if using a pair of measurements)</i><br>
            Name of the measurement for objects that
            are above the threshold for both measurements.""")

        self.wants_image = cps.Binary(
            "Retain an image of the classified objects?",
            False,
            doc="""
            Select <i>%(YES)s</i> to retain the image of the objects color-coded according
            to their classification, for use later in the pipeline (for example,
            to be saved by a <b>SaveImages</b> module).""" % globals())

        self.image_name = cps.ImageNameProvider("Enter the image name",
                                                cps.NONE,
                                                doc="""
            <i>(Used only if the classified object image is to be retained for later use in the pipeline)</i> <br>
            Enter the name to be given to the classified object image.""")
Пример #22
0
    def create_settings(self):
        '''Create the settings for the module'''
        self.command_or_macro = cps.Choice(
            "Run an ImageJ command or macro?", [CM_COMMAND, CM_MACRO],
            doc=
            """This setting determines whether <b>RunImageJ</b> runs either a:
            <ul>
            <li><i>Command:</i> Select from a list of available ImageJ commands
            (those items contained in the ImageJ menus); or</li>
            <li><i>Macro:</i> A series of ImageJ commands/plugins that you write yourself.</li>
            </ul>""")
        #
        # Load the commands in visible_settings so that we don't call
        # ImageJ unless someone tries the module
        #
        self.command = self.make_command_choice(
            "Command",
            doc="""<i>(Used only if running a command)</i><br>
            The command to execute when the module runs.""")

        self.command_settings_dictionary = {}
        self.command_settings = []
        self.command_settings_count = cps.HiddenCount(
            self.command_settings, "Command settings count")
        self.pre_command_settings_dictionary = {}
        self.pre_command_settings = []
        self.pre_command_settings_count = cps.HiddenCount(
            self.pre_command_settings, "Prepare group command settings count")
        self.post_command_settings_dictionary = {}
        self.post_command_settings = []
        self.post_command_settings_count = cps.HiddenCount(
            self.post_command_settings, "Post-group command settings count")

        self.macro = cps.Text("Macro",
                              'run("Invert");',
                              multiline=True,
                              doc="""<i>(Used only if running a macro)</i><br>
            This is the ImageJ macro to be executed. For help on
            writing macros, see <a href="http://rsb.info.nih.gov/ij/developer/macro/macros.html">here</a>."""
                              )

        self.options = cps.Text(
            "Options",
            "",
            doc="""<i>(Used only if running a command)</i><br>
            Use this setting to provide options to the command.""")

        self.wants_to_set_current_image = cps.Binary(
            "Input the currently active image in ImageJ?",
            True,
            doc="""<p>Check this setting if you want to set the currently 
            active ImageJ image using an image from a 
            prior CellProfiler module.</p>
            <p>Leave it unchecked to use the currently 
            active image in ImageJ. You may want to do this if you
            have an output image from a prior <b>RunImageJ</b>
            that you want to perform further operations upon
            before retrieving the final result back to CellProfiler.</p>""")

        self.current_input_image_name = cps.ImageNameSubscriber(
            "Select the input image",
            doc="""<i>(Used only if setting the currently active image)</i><br>
            This is the CellProfiler image that will become 
            ImageJ's currently active image.
            The ImageJ commands and macros in this module will perform 
            their operations on this image. You may choose any image produced
            by a prior CellProfiler module.""")

        self.wants_to_get_current_image = cps.Binary(
            "Retrieve the currently active image from ImageJ?",
            True,
            doc="""Check this setting if you want to retrieve ImageJ's
            currently active image after running the command or macro. 
            <p>Leave
            the setting unchecked if the pipeline does not need to access
            the current ImageJ image. For example, you might want to run
            further ImageJ operations with additional <b>RunImageJ</b>
            upon the current image
            prior to retrieving the final image back to CellProfiler.</p>""")

        self.current_output_image_name = cps.ImageNameProvider(
            "Name the current output image",
            "ImageJImage",
            doc=
            """<i>(Used only if retrieving the currently active image)</i><br>
            This is the CellProfiler name for ImageJ's current image after
            processing by the command or macro. The image will be a
            snapshot of the current image after the command has run, and
            will be avilable for processing by subsequent CellProfiler modules."""
        )

        self.pause_before_proceeding = cps.Binary(
            "Wait for ImageJ before continuing?",
            False,
            doc="""Some ImageJ commands and macros are interactive; you
            may want to adjust the image in ImageJ before continuing. Check
            this box to stop CellProfiler while you adjust the image in
            ImageJ. Leave the box unchecked to immediately use the image.
            <br>
            This command will not wait if CellProfiler is executed in
            batch mode. See <i>%(BATCH_PROCESSING_HELP_REF)s</i> for more
            details on batch processing.""" % globals())

        self.prepare_group_choice = cps.Choice(
            "Run a command or macro before each group of images?",
            [CM_NOTHING, CM_COMMAND, CM_MACRO],
            doc=
            """You can run an ImageJ macro or a command <i>before</i> each group of
            images. This can be useful in order to set up ImageJ before
            processing a stack of images. Choose <i>%(CM_NOTHING)s</i> if
            you do not want to run a command or macro, <i>%(CM_COMMAND)s</i>
            to choose a command to run or <i>%(CM_MACRO)s</i> to run a macro.
            """ % globals())

        self.prepare_group_command = self.make_command_choice(
            "Command",
            doc=
            """<i>(Used only if running a command before an image group)</i><br>
            The command to execute before processing a group of images.""")

        self.prepare_group_macro = cps.Text(
            "Macro",
            'run("Invert");',
            multiline=True,
            doc=
            """<i>(Used only if running a macro before an image group)</i><br>
            This is the ImageJ macro to be executed before processing
            a group of images. For help on writing macros, see 
            <a href="http://rsb.info.nih.gov/ij/developer/macro/macros.html">here</a>."""
        )

        self.prepare_group_options = cps.Text(
            "Options",
            "",
            doc=
            """<i>(Used only if running a command before an image group)</i><br>
            Use this setting to provide options to the command.""")

        self.post_group_choice = cps.Choice(
            "Run a command or macro after each group of images?",
            [CM_NOTHING, CM_COMMAND, CM_MACRO],
            doc=
            """You can run an ImageJ macro or a command <i>after</i> each group of
            images. This can be used to do some sort of operation on a whole
            stack of images that have been accumulated by the group operation.
            Choose <i>%(CM_NOTHING)s</i> if you do not want to run a command or 
            macro, <i>%(CM_COMMAND)s</i> to choose a command to run or 
            <i>%(CM_MACRO)s</i> to run a macro.
            """ % globals())

        self.post_group_command = self.make_command_choice("Command",
                                                           doc="""
            <i>(Used only if running a command after an image group)</i><br>
            The command to execute after processing a group of images.""")

        self.post_group_macro = cps.Text(
            "Macro",
            'run("Invert");',
            multiline=True,
            doc="""<i>(Used only if running a macro after an image group)</i><br>
            This is the ImageJ macro to be executed after processing
            a group of images. For help on writing macros, see 
            <a href="http://rsb.info.nih.gov/ij/developer/macro/macros.html">here</a>."""
        )

        self.post_group_options = cps.Text(
            "Options",
            "",
            doc=
            """<i>(Used only if running a command after an image group)</i><br>
            Use this setting to provide options to the command or
            macro.""")

        self.wants_post_group_image = cps.Binary(
            "Retrieve the image output by the group operation?",
            False,
            doc="""You can retrieve the image that is currently active in ImageJ
            at the end of macro processing and use it later in CellProfiler.
            The image will only be available during the last cycle of the
            image group. Check this setting to use the active image in CellProfiler
            or leave it unchecked if you do not want to use the active image.
            """)

        self.post_group_output_image = cps.ImageNameProvider(
            "Name the group output image",
            "ImageJGroupImage",
            doc=
            """<i>(Used only if retrieving an image after an image group operation)</i><br>
            This setting names the output image produced by the
            ImageJ command or macro that CellProfiler runs after processing
            all images in the group. The image is only available at the
            last cycle in the group""",
            provided_attributes={
                cps.AGGREGATE_IMAGE_ATTRIBUTE: True,
                cps.AVAILABLE_ON_LAST_ATTRIBUTE: True
            })

        self.show_imagej_button = cps.DoSomething(
            "Show ImageJ",
            "Show",
            self.on_show_imagej,
            doc="""Press this button to show the ImageJ user interface.
            You can use the user interface to run ImageJ commands or
            set up ImageJ before a CellProfiler run.""")
Пример #23
0
    def create_settings(self):
        '''Create the settings for the module'''
        self.images = []

        self.objects_name = cps.ObjectNameSubscriber(
            'Select the input untangled worm objects', 'OverlappingWorms',
            doc = """This is the name of the objects produced by the
            <b>UntangleWorms</b> module. <b>StraightenWorms</b> can use
            either the overlapping or non-overlapping objects as input. It
            will use the control point measurements associated with the objects
            to reconstruct the straight worms. You can also use objects
            saved from a previous run and loaded via <b>LoadImages</b>, objects
            edited using <b>EditObjectsManually</b> or objects from one
            of the Identify modulues. <b>StraightenWorms</b>
            will recalculate the control points for these images.""")

        self.straightened_objects_name = cps.ObjectNameProvider(
            "Name the output straightened worm objects", "StraightenedWorms",
            doc = """This is the name that will be given to the straightened
            worm objects. These objects can then be used in a subsequent
            measurement module.""")
        
        self.width = cps.Integer(
            "Worm width", 20, minval = 3,
            doc = """This setting determines the width of the image of each
            worm. The width should be set to at least the maximum width of
            any untangled worm, but can be set to be larger to include the
            worm's background in the straightened image.""")
        
        self.training_set_directory = cps.DirectoryPath(
            "Training set file location", support_urls = True,
            allow_metadata = False,
            doc = """Select the folder containing the training set to be loaded.
            %(IO_FOLDER_CHOICE_HELP_TEXT)s
            <p>An additional option is the following:
            <ul>
            <li><i>URL</i>: Use the path part of a URL. For instance, your
            training set might be hosted at 
            <i>http://university.edu/~johndoe/TrainingSet.mat</i>
            To access this file, you would choose <i>URL</i> and enter
            <i>https://svn.broadinstitute.org/CellProfiler/trunk/ExampleImages/ExampleSBSImages</i>
            as the path location.</li>
            </ul></p>"""%globals())
        def get_directory_fn():
            '''Get the directory for the CSV file name'''
            return self.training_set_directory.get_absolute_path()
        def set_directory_fn(path):
            dir_choice, custom_path = self.training_set_directory.get_parts_from_path(path)
            self.training_set_directory.join_parts(dir_choice, custom_path)
            
        self.training_set_file_name = cps.FilenameText(
            "Training set file name", "TrainingSet.mat",
            doc = "This is the name of the training set file.",
            get_directory_fn = get_directory_fn,
            set_directory_fn = set_directory_fn,
            browse_msg = "Choose training set",
            exts = [("Worm training set (*.xml)", "*.xml"),
                    ("All files (*.*)", "*.*")])
        
        self.wants_measurements = cps.Binary(
            "Measure intensity distribution?", True,
            doc = """<b>StraightenWorms</b> can divide a worm into sections
            and measure the intensities of each section in each of the
            straightened images. These measurements can help classify
            phenotypes if the staining pattern across the segments differs
            between phenotypes.""")
        
        self.number_of_segments = cps.Integer(
            "Number of transverse segments", 4, 1,
            doc = """(<i>Only displayed if intensities are measured</i>)<br>
            This setting controls the number of segments measured, dividing
            the worm longitudally into transverse segments starting at the head 
            and ending at the tail.
            These measurements might be used to identify a phenotype in which
            a stain is localized longitudally, for instance, in the head.
            
            Set the number of vertical segments to 1 to only measure intensity
            in the horizontal direction.""")

        self.number_of_stripes = cps.Integer(
            "Number of longitudinal stripes", 3, 1,
            doc = """(<i>Only displayed if intensities are measured</i>)<br>
            This setting controls the number of stripes measured, dividing
            the worm transversely into areas that run longitudally. These
            measurements might be used to identify a phenotype in which a
            stain is localized transversely, for instance in the gut of the
            worm.
            
            Set the number of horizontal stripes to 1 to only measure intensity
            in the vertical direction.""")
        
        self.flip_worms = cps.Choice(
            "Align worms?", [FLIP_NONE, FLIP_TOP, FLIP_BOTTOM],
            doc = """(<i>Only displayed if intensities are measured</i>)<br>
            <b>StraightenWorms</b> can align worms so that the brightest
            half of the worm (the half with the highest mean intensity) is
            at the top of the image or at the bottom of the image. This
            can be used to align all worms similarly if some feature,
            such as the larynx, is stained and is always at the same end
            of the worm. Choose <i>%(FLIP_TOP)s</i> if the brightest part of the
            worm should be at the top of the image, <i>%(FLIP_BOTTOM)s</i> if the
            brightest part of the worm should be at the bottom or
            <i>%(FLIP_NONE)s</i> if the worm should not be aligned."""%globals())
        
        def image_choices_fn(pipeline):
            '''Return the image choices for the alignment image'''
            return [ group.image_name.value
                     for group in self.images ]
        
        self.flip_image = cps.Choice(
            "Alignment image", [ "None" ], choices_fn = image_choices_fn,
            doc = """(<i>Only displayed if aligning worms</i>)<br>
            This is the image whose intensity will be used to align the worms.
            You must use one of the straightened images below.""")
        
        
        self.image_count = cps.HiddenCount(self.images, "Image count")
        
        self.add_image(False)
        
        self.add_image_button = cps.DoSomething(
            "", "Add another image", self.add_image,
            doc = """Press this button to add another image to be straightened""")
Пример #24
0
    def create_settings(self):
        '''Create the settings for the ExportToCellH5 module'''
        self.directory = cps.DirectoryPath("Output file location",
                                           doc="""
            This setting lets you choose the folder for the output files.
            %(IO_FOLDER_CHOICE_HELP_TEXT)s
            """ % globals())

        def get_directory_fn():
            '''Get the directory for the CellH5 file'''
            return self.directory.get_absolute_path()

        def set_directory_fn(path):
            dir_choice, custom_path = self.directory.get_parts_from_path(path)
            self.directory.join_parts(dir_choice, custom_path)

        self.file_name = cps.FilenameText("Output file name",
                                          "DefaultOut.ch5",
                                          get_directory_fn=get_directory_fn,
                                          set_directory_fn=set_directory_fn,
                                          metadata=True,
                                          browse_msg="Choose CellH5 file",
                                          mode=cps.FilenameText.MODE_APPEND,
                                          exts=[("CellH5 file (*.cellh5)",
                                                 "*.ch5"),
                                                ("HDF5 file (*.h5)", "*.h5"),
                                                ("All files (*.*", "*.*")],
                                          doc="""
            This setting lets you name your CellH5 file. If you choose an
            existing file, CellProfiler will add new data to the file
            or overwrite existing locations.
            <p>%(IO_WITH_METADATA_HELP_TEXT)s %(USING_METADATA_TAGS_REF)s.
            For instance, if you have a metadata tag named
            "Plate", you can create a per-plate folder by selecting one the subfolder options
            and then specifying the subfolder name as "\g&lt;Plate&gt;". The module will
            substitute the metadata values for the current image set for any metadata tags in the
            folder name.%(USING_METADATA_HELP_REF)s.</p>

            """ % globals())
        self.overwrite_ok = cps.Binary(
            "Overwrite existing data without warning?",
            False,
            doc="""
            Select <i>%(YES)s</i> to automatically overwrite any existing data
            for a site. Select <i>%(NO)s</i> to be prompted first.

            If you are running the pipeline on a computing cluster,
            select <i>%(YES)s</i> unless you want execution to stop because you
            will not be prompted to intervene. Also note that two instances
            of CellProfiler cannot write to the same file at the same time,
            so you must ensure that separate names are used on a cluster.
            """ % globals())
        self.repack = cps.Binary("Repack after analysis",
                                 True,
                                 doc="""
            This setting determines whether CellProfiler in multiprocessing mode
            repacks the data at the end of analysis. If you select <i>%(YES)s</i>,
            CellProfiler will combine all of the satellite files into a single
            file upon completion. This option requires some extra temporary disk
            space and takes some time at the end of analysis, but results in
            a single file which may occupy less disk space. If you select
            <i>%(NO)s</i>, CellProfiler will create a master file using the
            name that you give and this file will have links to individual
            data files that contain the actual data. Using the data generated by
            this option requires that you keep the master file and the linked
            files together when copying them to a new folder.
            """ % globals())
        self.plate_metadata = cps.Choice("Plate metadata", [],
                                         value="Plate",
                                         choices_fn=self.get_metadata_choices,
                                         doc="""
            This is the metadata tag that identifies the plate name of
            the images for the current cycle. Choose <i>None</i> if
            your assay does not have metadata for plate name. If your
            assay is slide-based, you can use a metadata item that identifies
            the slide as the choice for this setting and set the well
            and site metadata items to <i>None</i>.""")
        self.well_metadata = cps.Choice(
            "Well metadata", [],
            value="Well",
            choices_fn=self.get_metadata_choices,
            doc="""This is the metadata tag that identifies the well name
            for the images in the current cycle. Choose <i>None</i> if
            your assay does not have metadata for the well.""")
        self.site_metadata = cps.Choice(
            "Site metadata", [],
            value="Site",
            choices_fn=self.get_metadata_choices,
            doc="""This is the metadata tag that identifies the site name
                for the images in the current cycle. Choose <i>None</i> if
                your assay doesn't divide wells up into sites or if this
                tag is not required for other reasons.""")
        self.divider = cps.Divider()
        self.wants_to_choose_measurements = cps.Binary("Choose measurements?",
                                                       False,
                                                       doc="""
            This setting lets you choose between exporting all measurements or
            just the ones that you choose. Select <i>%(YES)s</i> to pick the
            measurements to be exported. Select <i>%(NO)s</i> to automatically
            export all measurements available at this stage of the pipeline.
            """ % globals())
        self.measurements = cps.MeasurementMultiChoice(
            "Measurements to export",
            doc="""
            <i>(Used only if choosing measurements.)</i>
            <br>
            This setting lets you choose individual measurements to be exported.
            Check the measurements you want to export.
            """)
        self.objects_to_export = []
        self.add_objects_button = cps.DoSomething("Add objects to export",
                                                  "Add objects",
                                                  self.add_objects)
        self.images_to_export = []
        self.add_image_button = cps.DoSomething("Add an image to export",
                                                "Add image", self.add_image)
        self.objects_count = cps.HiddenCount(self.objects_to_export)
        self.images_count = cps.HiddenCount(self.images_to_export)
Пример #25
0
    def create_settings(self):
        self.image_name = cps.ImageNameSubscriber("Select the input image",
                                                  cps.NONE)

        self.combine_or_split = cps.Choice("Conversion method",
                                           [COMBINE, SPLIT],
                                           doc='''
            How do you want to convert the color image? 
            <ul>
            <li><i>%(SPLIT)s:</i> Splits the three channels
            (red, green, blue) of a color image into three separate grayscale images. </li>
            <li><i>%(COMBINE)s</i> Converts a color image to a grayscale 
            image by combining the three channels (red, green, blue) together.</li>
            </ul>''' % globals())

        self.rgb_or_channels = cps.Choice("Image type",
                                          [CH_RGB, CH_HSV, CH_CHANNELS],
                                          doc="""
            Many images contain color channels other than red, green
            and blue. For instance, GIF and PNG formats can have an alpha
            channel that encodes transparency. TIF formats can have an arbitrary
            number of channels which represent pixel measurements made by
            different detectors, filters or lighting conditions. This setting
            provides three options to choose from:
            <ul>
            <li><i>%(CH_RGB)s:</i> The RGB (red,green,blue) color space is the typical model in which color images are stored. Choosing this option
            will split the image into any of the red, green and blue component images.</li>
            <li><i>%(CH_HSV)s:</i>The HSV (hue, saturation, value) color space is based on more intuitive color characteristics as 
            tint, shade and tone. Choosing
            this option will split the image into any of the hue, saturation, and value component images.</li>
            <li><i>%(CH_CHANNELS)s:</i>This is a more complex model for images which involve more than three channels.</li>
            </ul>""" % globals())

        # The following settings are used for the combine option
        self.grayscale_name = cps.ImageNameProvider("Name the output image",
                                                    "OrigGray")

        self.red_contribution = cps.Float("Relative weight of the red 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.''')

        self.green_contribution = cps.Float(
            "Relative weight of the green 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.''')

        self.blue_contribution = cps.Float(
            "Relative weight of the blue 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.''')

        # The following settings are used for the split RGB option
        self.use_red = cps.Binary('Convert red to gray?', True)
        self.red_name = cps.ImageNameProvider('Name the output image',
                                              "OrigRed")

        self.use_green = cps.Binary('Convert green to gray?', True)
        self.green_name = cps.ImageNameProvider('Name the output image',
                                                "OrigGreen")

        self.use_blue = cps.Binary('Convert blue to gray?', True)
        self.blue_name = cps.ImageNameProvider('Name the output image',
                                               "OrigBlue")

        # The following settings are used for the split HSV ption
        self.use_hue = cps.Binary('Convert hue to gray?', True)
        self.hue_name = cps.ImageNameProvider('Name the output image',
                                              "OrigHue")

        self.use_saturation = cps.Binary('Convert saturation to gray?', True)
        self.saturation_name = cps.ImageNameProvider('Name the output image',
                                                     "OrigSaturation")

        self.use_value = cps.Binary('Convert value to gray?', True)
        self.value_name = cps.ImageNameProvider('Name the output image',
                                                "OrigValue")

        # The alternative model:
        self.channels = []
        self.add_channel(False)
        self.channel_button = cps.DoSomething("", "Add another channel",
                                              self.add_channel)

        self.channel_count = cps.HiddenCount(self.channels, "Channel count")
Пример #26
0
    def add_flag(self, can_delete=True):
        group = cps.SettingsGroup()
        group.append("divider1", cps.Divider(line=False))
        group.append("measurement_settings", [])
        group.append("measurement_count",
                     cps.HiddenCount(group.measurement_settings))
        group.append(
            "category",
            cps.Text("Name the flag's category",
                     "Metadata",
                     doc='''
                        Name a measurement category by which to categorize the flag. The <i>Metadata</i> 
                        category is the default used in CellProfiler to store information about 
                        images (referred to as <i>metadata</i>).</p>
                        <p>The flag is stored as a per-image measurement whose name is a combination of the
                        flag's category and feature name, underscore delimited. 
                        For instance, if the measurement category is
                        <i>Metadata</i> and the feature name is <i>QCFlag</i>, then the default
                        measurement name would be <i>Metadata_QCFlag</i>. %s</p>'''
                     % USING_METADATA_HELP_REF))

        group.append(
            "feature_name",
            cps.Text("Name the flag",
                     "QCFlag",
                     doc='''
                        The flag is stored as a per-image measurement whose name is a combination of the
                        flag's category and feature name, separated by underscores. 
                        For instance, if the measurement category is
                        <i>Metadata</i> and the feature name is <i>QCFlag</i>, then the default
                        measurement name would be <i>Metadata_QCFlag</i>.'''))

        group.append(
            "combination_choice",
            cps.Choice(
                "Flag if any, or all, measurement(s) fails to meet the criteria?",
                [C_ANY, C_ALL],
                doc='''
                        <ul>
                        <li><i>%(C_ANY)s:</i> An image will be flagged if any of its measurements fail. This can be useful
                        for flagging images possessing multiple QC flaws; for example, you can flag all bright images 
                        and all out of focus images with one flag.</li>
                        <li><i>%(C_ALL)s:</i> A flag will only be assigned if all measurements fail.  This can be useful 
                        for flagging images that possess only a combination
                        of QC flaws; for example, you can flag only images that are both bright and out of focus.</li>
                        </ul>''' % globals()))

        group.append(
            "wants_skip",
            cps.Binary("Skip image set if flagged?",
                       False,
                       doc="""
                        <p>Select <i>%(YES)s</i> to skip the remainder of the pipeline for image sets
                        that are flagged. CellProfiler will not run subsequent modules in the
                        pipeline on the images in any image set that is flagged. 
                        Select <i>%(NO)s</i> for CellProfiler to continue to process the pipeline regardless
                        of flagging.</p>
                        <p>You may want to skip processing in order to filter out
                        unwanted images. For instance, you may want
                        to exclude out of focus images when running 
                        <b>CorrectIllumination_Calculate</b>. You can do this with a
                        pipeline that measures image quality and flags inappropriate
                        images before it runs <b>CorrectIllumination_Calculate</b>.</p>"""
                       % globals()))

        group.append(
            "add_measurement_button",
            cps.DoSomething("", "Add another measurement",
                            self.add_measurement, group))
        self.add_measurement(group, False if not can_delete else True)
        if can_delete:
            group.append(
                "remover",
                cps.RemoveSettingButton("", "Remove this flag", self.flags,
                                        group))
        group.append("divider2", cps.Divider(line=True))
        self.flags.append(group)
Пример #27
0
    def create_settings(self):
        '''Create the settings for the module'''
        logger.debug("Creating RunImageJ module settings")
        J.activate_awt()
        logger.debug("Activated AWT")

        self.command_or_macro = cps.Choice("Run an ImageJ command or macro?",
                                           [CM_COMMAND, CM_SCRIPT, CM_MACRO],
                                           doc="""
            This setting determines whether <b>RunImageJ</b> runs either a:
            <ul>
            <li><i>%(CM_COMMAND)s:</i> Select from a list of available ImageJ commands
            (those items contained in the ImageJ menus); or</li>
            <li><i>%(CM_SCRIPT)s:</i> A script written in one of ImageJ 2.0's
            supported scripting languages.</li>
            <li><i>%(CM_MACRO)s:</i> An ImageJ 1.x macro, written in the
            ImageJ 1.x macro language. <b>Run_ImageJ</b> runs ImageJ in 1.x
            compatability mode.</li>
            </ul>""" % globals())
        #
        # Load the commands in visible_settings so that we don't call
        # ImageJ unless someone tries the module
        #
        self.command = self.make_command_choice("Command",
                                                doc="""
            <i>(Used only if running a %(CM_COMMAND)s)</i><br>
            The command to execute when the module runs.""" % globals())

        self.command_settings_dictionary = {}
        self.command_settings = []
        self.command_settings_count = cps.HiddenCount(
            self.command_settings, "Command settings count")
        self.pre_command_settings_dictionary = {}
        self.pre_command_settings = []
        self.pre_command_settings_count = cps.HiddenCount(
            self.pre_command_settings, "Prepare group command settings count")
        self.post_command_settings_dictionary = {}
        self.post_command_settings = []
        self.post_command_settings_count = cps.HiddenCount(
            self.post_command_settings, "Post-group command settings count")

        self.macro = cps.Text("Macro",
                              """import imagej.command.CommandService;
cmdSvcClass = CommandService.class;
cmdSvc = ImageJ.getService(cmdSvcClass);
cmdSvc.run("imagej.core.commands.assign.InvertDataValues", new Object [] {"allPlanes", true}).get();""",
                              multiline=True,
                              doc="""
            <i>(Used only if running a %(CM_MACRO)s)</i><br>
            This is the ImageJ macro to be executed. The syntax for ImageJ
            macros depends on the scripting language engine chosen.
            We suggest that you use the Beanshell scripting language
            <a href="http://www.beanshell.org/manual/contents.html">
            (Beanshell documentation)</a>.""" % globals())

        all_engines = ij2.get_script_service(get_context()).getLanguages()
        self.language_dictionary = dict([(engine.getLanguageName(), engine)
                                         for engine in all_engines])

        self.macro_language = cps.Choice(
            "Macro language",
            choices=self.language_dictionary.keys(),
            doc="""
            This setting chooses the scripting language used to execute
            any macros in this module""")

        self.wants_to_set_current_image = cps.Binary(
            "Input the currently active image in ImageJ?",
            True,
            doc="""
            Select <i>%(YES)s</i> if you want to set the currently 
            active ImageJ image using an image from a 
            prior CellProfiler module.
            <p>Select <i>%(NO)s</i> to use the currently 
            active image in ImageJ. You may want to do this if you
            have an output image from a prior <b>RunImageJ</b>
            that you want to perform further operations upon
            before retrieving the final result back to CellProfiler.</p>""" %
            globals())

        self.current_input_image_name = cps.ImageNameSubscriber(
            "Select the input image",
            doc="""
            <i>(Used only if setting the currently active image)</i><br>
            This is the CellProfiler image that will become 
            ImageJ's currently active image.
            The ImageJ commands and macros in this module will perform 
            their operations on this image. You may choose any image produced
            by a prior CellProfiler module.""")

        self.wants_to_get_current_image = cps.Binary(
            "Retrieve the currently active image from ImageJ?",
            True,
            doc="""
            Select <i>%(YES)s</i> if you want to retrieve ImageJ's
            currently active image after running the command or macro. 
            <p>Select <i>%(NO)s</i> if the pipeline does not need to access
            the current ImageJ image. For example, you might want to run
            further ImageJ operations with additional <b>RunImageJ</b>
            upon the current image prior to retrieving the final image 
            back to CellProfiler.</p>""" % globals())

        self.current_output_image_name = cps.ImageNameProvider(
            "Name the current output image",
            "ImageJImage",
            doc="""
            <i>(Used only if retrieving the currently active image from ImageJ)</i><br>
            This is the CellProfiler name for ImageJ's current image after
            processing by the command or macro. The image will be a
            snapshot of the current image after the command has run, and
            will be available for processing by subsequent CellProfiler modules."""
        )

        self.pause_before_proceeding = cps.Binary(
            "Wait for ImageJ before continuing?",
            False,
            doc="""
            Some ImageJ commands and macros are interactive; you
            may want to adjust the image in ImageJ before continuing. 
            Select <i>%(YES)s</i> to stop CellProfiler while you adjust the image in
            ImageJ. Select <i>%(NO)s</i> to immediately use the image.
            <p>This command will not wait if CellProfiler is executed in
            batch mode. See <i>%(BATCH_PROCESSING_HELP_REF)s</i> for more
            details on batch processing.</p>""" % globals())

        self.prepare_group_choice = cps.Choice(
            "Function to run before each group of images?",
            [CM_NOTHING, CM_COMMAND, CM_SCRIPT, CM_MACRO],
            doc="""
            You can run an ImageJ 2.0 script, an ImageJ 1.x macro or a command <i>before</i> each group of
            images. This can be useful in order to set up ImageJ before
            processing a stack of images. Choose <i>%(CM_NOTHING)s</i> if
            you do not want to run a command or macro, <i>%(CM_COMMAND)s</i>
            to choose a command to run, <i>%(CM_SCRIPT)s</i> to run an
            ImageJ 2.0 script or <i>%(CM_MACRO)s</i> to run an ImageJ 1.x
            macro in ImageJ 1.x compatibility mode.
            """ % globals())

        logger.debug("Finding ImageJ commands")

        self.prepare_group_command = self.make_command_choice("Command",
                                                              doc="""
            <i>(Used only if running a command before an image group)</i><br>
            Select the command to execute before processing a group of images."""
                                                              )

        self.prepare_group_macro = cps.Text("Macro",
                                            'run("Invert");',
                                            multiline=True,
                                            doc="""
            <i>(Used only if running a macro before an image group)</i><br>
            This is the ImageJ macro to be executed before processing
            a group of images. For help on writing macros, see 
            <a href="http://rsb.info.nih.gov/ij/developer/macro/macros.html">here</a>."""
                                            )

        self.post_group_choice = cps.Choice(
            "Function to run after each group of images?",
            [CM_NOTHING, CM_COMMAND, CM_SCRIPT, CM_MACRO],
            doc="""
            You can run an ImageJ 2.0 script, an ImageJ macro or a command <i>after</i> each group of
            images. This can be used to do some sort of operation on a whole
            stack of images that have been accumulated by the group operation.
            Choose <i>%(CM_NOTHING)s</i> if
            you do not want to run a command or macro, <i>%(CM_COMMAND)s</i>
            to choose a command to run, <i>%(CM_SCRIPT)s</i> to run an
            ImageJ 2.0 script or <i>%(CM_MACRO)s</i> to run an ImageJ 1.x
            macro in ImageJ 1.x compatibility mode.
            """ % globals())

        self.post_group_command = self.make_command_choice("Command",
                                                           doc="""
            <i>(Used only if running a command after an image group)</i><br>
            The command to execute after processing a group of images.""")

        self.post_group_macro = cps.Text("Macro",
                                         'run("Invert");',
                                         multiline=True,
                                         doc="""
            <i>(Used only if running a macro after an image group)</i><br>
            This is the ImageJ macro to be executed after processing
            a group of images. For help on writing macros, see 
            <a href="http://rsb.info.nih.gov/ij/developer/macro/macros.html">here</a>."""
                                         )

        self.wants_post_group_image = cps.Binary(
            "Retrieve the image output by the group operation?",
            False,
            doc="""
            You can retrieve the image that is currently active in ImageJ
            at the end of macro processing and use it later in CellProfiler.
            The image will only be available during the last cycle of the
            image group. 
            <p>Select <i>%(YES)s</i> to retrieve the active image for use in CellProfiler.
            Select <i>%(NO)s</i> if you do not want to retrieve the active image.</p>
            """ % globals())

        self.post_group_output_image = cps.ImageNameProvider(
            "Name the group output image",
            "ImageJGroupImage",
            doc="""
            <i>(Used only if retrieving an image after an image group operation)</i><br>
            This setting names the output image produced by the
            ImageJ command or macro that CellProfiler runs after processing
            all images in the group. The image is only available at the
            last cycle in the group""",
            provided_attributes={
                cps.AGGREGATE_IMAGE_ATTRIBUTE: True,
                cps.AVAILABLE_ON_LAST_ATTRIBUTE: True
            })

        self.show_imagej_button = cps.DoSomething("Show ImageJ",
                                                  "Show",
                                                  self.on_show_imagej,
                                                  doc="""
            Press this button to show the ImageJ user interface.
            You can use the user interface to run ImageJ commands or
            set up ImageJ before a CellProfiler run.""")

        logger.debug("Finished creating settings")
Пример #28
0
    def create_settings(self):
        self.scheme_choice = cps.Choice(
            "Select a color scheme",
            [SCHEME_RGB, SCHEME_CMYK, SCHEME_STACK, SCHEME_COMPOSITE],
            doc="""
            This module can use one of two color schemes to combine images:<br/>
            <ul><li><i>%(SCHEME_RGB)s</i>: Each input image determines the intensity of
            one of the color channels: red, green, and blue.</li>
            <li><i>%(SCHEME_CMYK)s</i>: Three of the input images are combined to determine
            the colors (cyan, magenta, and yellow) and a fourth is used only for brightness. The cyan
            image adds equally to the green and blue intensities. The magenta
            image adds equally to the red and blue intensities. The yellow
            image adds equally to the red and green intensities.</li>
            <li><i>%(SCHEME_STACK)s</i>: The channels are stacked in order. An arbitrary number of
            channels is allowed.</li>
            <li><i>%(SCHEME_COMPOSITE)s</i>: A color is assigned to each grayscale
            image. Each grayscale image is converted to color by multiplying
            the intensity by the color and the resulting color images are
            added together. An arbitrary number of channels can be composited
            into a single color image.</li>
            </ul>""" % globals())

        # # # # # # # # # # # # # # # #
        #
        # RGB settings
        #
        # # # # # # # # # # # # # # # #
        self.red_image_name = cps.ImageNameSubscriber(
            "Select the image to be colored red",
            can_be_blank=True,
            blank_text=LEAVE_THIS_BLACK)

        self.green_image_name = cps.ImageNameSubscriber(
            "Select the image to be colored green",
            can_be_blank=True,
            blank_text=LEAVE_THIS_BLACK)

        self.blue_image_name = cps.ImageNameSubscriber(
            "Select the image to be colored blue",
            can_be_blank=True,
            blank_text=LEAVE_THIS_BLACK)

        self.rgb_image_name = cps.ImageNameProvider("Name the output image",
                                                    "ColorImage")

        self.red_adjustment_factor = cps.Float(
            "Relative weight for the red image",
            value=1,
            minval=0,
            doc='''
            <i>(Used only if %(SCHEME_RGB)s is selected as the color scheme)</i><br>
            Enter the relative weight for the red image. 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.''' % globals())

        self.green_adjustment_factor = cps.Float(
            "Relative weight for the green image",
            value=1,
            minval=0,
            doc='''
            <i>(Used only if %(SCHEME_RGB)s is selected as the color scheme)</i><br>
            Enter the relative weight for the green image. 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.''' % globals())

        self.blue_adjustment_factor = cps.Float(
            "Relative weight for the blue image",
            value=1,
            minval=0,
            doc='''
            <i>(Used only if %(SCHEME_RGB)s is selected as the color scheme)</i><br>
            Enter the relative weight for the blue image. 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.''' % globals())
        # # # # # # # # # # # # # #
        #
        # CYMK settings
        #
        # # # # # # # # # # # # # #
        self.cyan_image_name = cps.ImageNameSubscriber(
            "Select the image to be colored cyan",
            can_be_blank=True,
            blank_text=LEAVE_THIS_BLACK)

        self.magenta_image_name = cps.ImageNameSubscriber(
            "Select the image to be colored magenta",
            can_be_blank=True,
            blank_text=LEAVE_THIS_BLACK)

        self.yellow_image_name = cps.ImageNameSubscriber(
            "Select the image to be colored yellow",
            can_be_blank=True,
            blank_text=LEAVE_THIS_BLACK)

        self.gray_image_name = cps.ImageNameSubscriber(
            "Select the image that determines brightness",
            can_be_blank=True,
            blank_text=LEAVE_THIS_BLACK)

        self.cyan_adjustment_factor = cps.Float(
            "Relative weight for the cyan image",
            value=1,
            minval=0,
            doc='''
            <i>(Used only if %(SCHEME_CMYK)s is selected as the color scheme)</i><br>
            Enter the relative weight for the cyan image. If all relative weights are equal, all
            colors contribute equally in the final image. To weight colors relative to each other,
            increase or decrease the relative weights.''' % globals())

        self.magenta_adjustment_factor = cps.Float(
            "Relative weight for the magenta image",
            value=1,
            minval=0,
            doc='''
            <i>(Used only if %(SCHEME_CMYK)s is selected as the color scheme)</i><br>
            Enter the relative weight for the magenta image. If all relative weights are equal, all
            colors contribute equally in the final image. To weight colors relative to each other,
            increase or decrease the relative weights.''' % globals())

        self.yellow_adjustment_factor = cps.Float(
            "Relative weight for the yellow image",
            value=1,
            minval=0,
            doc='''
            <i>(Used only if %(SCHEME_CMYK)s is selected as the color scheme)</i><br>
            Enter the relative weight for the yellow image. If all relative weights are equal, all
            colors contribute equally in the final image. To weight colors relative to each other,
            increase or decrease the relative weights.''' % globals())

        self.gray_adjustment_factor = cps.Float(
            "Relative weight for the brightness image",
            value=1,
            minval=0,
            doc='''
            <i>(Used only if %(SCHEME_CMYK)s is selected as the color scheme)</i><br>
            Enter the relative weight for the brightness image. If all relative weights are equal, all
            colors contribute equally in the final image. To weight colors relative to each other,
            increase or decrease the relative weights.''' % globals())

        # # # # # # # # # # # # # #
        #
        # Stack settings
        #
        # # # # # # # # # # # # # #

        self.stack_channels = []
        self.stack_channel_count = cps.HiddenCount(self.stack_channels)
        self.add_stack_channel_cb(can_remove=False)
        self.add_stack_channel = cps.DoSomething("", "Add another channel",
                                                 self.add_stack_channel_cb)
Пример #29
0
    def add_image(self, can_remove=True):
        group = GranularitySettingsGroup()
        group.can_remove = can_remove
        if can_remove:
            group.append("divider", cps.Divider(line=True))

        group.append(
            "image_name",
            cps.ImageNameSubscriber("Select an image to measure",
                                    cps.NONE,
                                    doc="""
            Select the grayscale images whose granularity you want to measure."""
                                    ))

        group.append(
            "subsample_size",
            cps.Float("Subsampling factor for granularity measurements",
                      0.25,
                      minval=np.finfo(float).eps,
                      maxval=1,
                      doc='''
            If the textures of 
            interest are larger than a few pixels, we recommend you subsample the image with a factor 
            &lt;1 to speed up the processing. Down sampling the image will let you detect larger 
            structures with a smaller sized structure element. A factor &gt;1 might increase the accuracy 
            but also require more processing time. Images are typically of higher resolution than is 
            required for granularity measurements, so the default value is 0.25. For low-resolution images, 
            increase the subsampling fraction; for high-resolution images, decrease the subsampling 
            fraction. Subsampling by 1/4 reduces computation time by (1/4)<sup>3</sup> because the size
            of the image is (1/4)<sup>2</sup> of original and the range of granular spectrum can
            be 1/4 of original. Moreover, the results are sometimes actually a little better
            with subsampling, which is probably because with subsampling the
            individual granular spectrum components can be used as features, whereas
            without subsampling a feature should be a sum of several adjacent
            granular spectrum components. The recommendation on the numerical value
            cannot be determined in advance; an analysis as in this reference may be
            required before running the whole set.
            See this <a href="http://www.ravkin.net/presentations/Statistical%20properties%20of%20algorithms%20for%20analysis%20of%20cell%20images.pdf">
            pdf</a>, slides 27-31, 49-50.'''))

        group.append(
            "image_sample_size",
            cps.Float("Subsampling factor for background reduction",
                      .25,
                      minval=np.finfo(float).eps,
                      maxval=1,
                      doc='''
            It is important to 
            remove low frequency image background variations as they will affect the final granularity 
            measurement. Any method can be used as a pre-processing step prior to this module; 
            we have chosen to simply subtract a highly open image. To do it quickly, we subsample the image 
            first. The subsampling factor for background reduction is usually [0.125 &ndash; 0.25].  This is 
            highly empirical, but a small factor should be used if the structures of interest are large. The 
            significance of background removal in the context of granulometry is that image 
            volume at certain granular size is normalized by total image volume, which depends on 
            how the background was removed.'''))

        group.append(
            "element_size",
            cps.Integer("Radius of structuring element",
                        10,
                        minval=1,
                        doc='''
            This radius should correspond to the radius of the textures of interest <i>after</i> 
            subsampling; i.e., if textures in the original image scale have a radius of 40 
            pixels, and a subsampling factor of 0.25 is used, the structuring element size should be
            10 or slightly smaller, and the range of the spectrum defined below will cover more sizes.'''
                        ))

        group.append(
            "granular_spectrum_length",
            cps.Integer("Range of the granular spectrum",
                        16,
                        minval=1,
                        doc='''
            You may need a trial run to see which granular 
            spectrum range yields informative measurements. Start by using a wide spectrum and 
            narrow it down to the informative range to save time.'''))

        group.append(
            "add_objects_button",
            cps.DoSomething("",
                            "Add another object",
                            group.add_objects,
                            doc="""
            Press this button to add granularity measurements for
            objects, such as those identified by a prior 
            <b>IdentifyPrimaryObjects</b> module. <b>MeasureGranularity</b>
            will measure the image's granularity within each object at the
            requested scales."""))

        group.objects = []

        group.object_count = cps.HiddenCount(group.objects, "Object count")

        if can_remove:
            group.append(
                "remover",
                cps.RemoveSettingButton("", "Remove this image", self.images,
                                        group))
        self.images.append(group)
        return group
Пример #30
0
    def create_settings(self):
        '''Create the initial settings and name the module'''
        self.target_name = cps.ObjectNameProvider('Name the output objects',
                                                  'FilteredBlue',
                                                  doc="""
                                What do you want to call the filtered objects? This will be the name for 
                                the collection of objects that are retained after applying the filter(s)."""
                                                  )

        self.object_name = cps.ObjectNameSubscriber(
            'Select the object to filter',
            'None',
            doc="""
                                What object would you like to filter? This setting 
                                also controls which measurement choices appear for filtering:
                                you can only filter based on measurements made on the object you select.
                                If you intend to use a measurement 
                                calculated by the <b>CalculateMath</b> module to to filter objects, select
                                the first operand's object here, because <b>CalculateMath</b> measurements
                                are stored with the first operand's object.""")

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

        self.rules_or_measurement = cps.Choice(
            'Filter using classifier rules or measurements?',
            [ROM_MEASUREMENTS, ROM_RULES],
            doc="""You can choose either a measurement made on the objects or
            a rules file produced by CellProfiler Analyst. If you choose
            <i>Rules</i>, you will have to ensure that this pipeline makes every
            measurement in that rules file.""")
        self.spacer_2 = cps.Divider(line=False)

        self.measurements = []
        self.measurement_count = cps.HiddenCount(self.measurements,
                                                 "Measurement count")
        self.add_measurement(False)
        self.add_measurement_button = cps.DoSomething(
            "Add another measurement", "Add", self.add_measurement)
        self.filter_choice = cps.Choice("Select the filtering method",
                                        FI_ALL,
                                        FI_LIMITS,
                                        doc="""
                                <i>(Used only if filtering using measurements)</i><br>
                                There are five different ways to filter objects:
                                <ul>
                                <li><i>Limits:</i> Keep an object if its measurement value falls within a range you specify.</li> 
                                <li><i>Maximal:</i> Keep the object with the maximum value for the measurement
                                of interest. If multiple objects share a maximal value, retain one object 
                                selected arbitrarily per image.</li>
                                <li><i>Minimal:</i> Keep the object with the minimum value for the measurement
                                of interest. If multiple objects share a minimal value, retain one object 
                                selected arbitrarily per image.</li>
                                <li><i>Maximal per object:</i> This option requires you to choose a parent object.
                                The parent object might contain several child objects of
                                choice (for instance, mitotic spindles within a cell or FISH
                                probe spots within a nucleus). Only the child object whose measurements equal the maximum child-measurement
                                value among that set of child objects will be kept 
                                (for example, the longest spindle
                                in each cell).  You do not have to explicitly relate objects before using this module.</li>
                                <li><i>Minimal per object:</i> Same as <i>Maximal per object</i>, except filtering is based on the minimum value.</li>
                                </ul>""")

        self.enclosing_object_name = cps.ObjectNameSubscriber(
            'Select the objects that contain the filtered objects',
            'None',
            doc="""
                                <i>(Used only if a per-object filtering method is selected)</i><br>
                                This setting selects the container (i.e., parent) objects for the <i>Maximal per object</i> 
                                and <i>Minimal per object</i> filtering choices."""
        )

        self.rules_directory = cps.DirectoryPath(
            "Rules file location",
            doc="""<i>(Used only when filtering by rules)</i>
            <br>
            Select the location of the rules file that will be used for filtering.
            %(IO_FOLDER_CHOICE_HELP_TEXT)s""" % globals())

        def get_directory_fn():
            '''Get the directory for the rules file name'''
            return self.rules_directory.get_absolute_path()

        def set_directory_fn(path):
            dir_choice, custom_path = self.rules_directory.get_parts_from_path(
                path)
            self.rules_directory.join_parts(dir_choice, custom_path)

        self.rules_file_name = cps.FilenameText(
            "Rules file name",
            "rules.txt",
            get_directory_fn=get_directory_fn,
            set_directory_fn=set_directory_fn,
            doc="""<i>(Used only when filtering using rules)</i>
            <br>The name of the file holding the rules. Each line of
            this file should be a rule naming a measurement to be made
            on the object you selected, for instance:
            <br><tt>
            IF (Nuclei_AreaShape_Area < 351.3, [0.79, -0.79], [-0.94, 0.94])
            </tt><br>
            The above rule will score +.79 for the positive category and -0.94
            for the negative category for nuclei whose area is less than 351.3 
            pixels and will score the opposite for nuclei whose area is larger.
            The filter adds positive and negative and keeps only objects whose
            positive score is higher than the negative score""")

        self.wants_outlines = cps.Binary(
            'Retain outlines of the identified objects?', False)

        self.outlines_name = cps.OutlineNameProvider('Name the outline image',
                                                     'FilteredObjects',
                                                     doc='''
                                 <i>(Used only if the outline image is to be retained for later use in the  
                                 pipeline)</i> <br> Choose a name by which the outline image can be 
                                 selected later in the pipeline.
                                 <p><i>Special note on saving images:</i> You can use the settings in this module
                                 to pass object outlines along to the module <b>OverlayOutlines</b>, and then save
                                 them with the <b>SaveImages</b> module. Also, the identified objects themselves
                                 can be passed along to the object processing module <b>ConvertToImage</b>
                                 and then saved with the <b>SaveImages</b> module.'''
                                                     )
        self.additional_objects = []
        self.additional_object_count = cps.HiddenCount(
            self.additional_objects, "Additional object count")
        self.spacer_3 = cps.Divider(line=False)

        self.additional_object_button = cps.DoSomething(
            'Relabel additional objects to match the filtered object?',
            'Add an additional object',
            self.add_additional_object,
            doc="""
                                Click this button to add an object to receive the same post-filtering labels as
                                the filtered object. This is useful in making sure that labeling is maintained 
                                between related objects (e.g., primary and secondary objects) after filtering."""
        )