def test_01_02_set_false(self): x = cps.Binary("text", True) x.value = False self.assertTrue(x.value == False)
def create_settings(self): self.input_image = cps.ImageNameSubscriber("Select an input image", "None", doc=""" What did you call the image to be tiled? Additional images within the cycle can be added later by choosing the <i>Across cycles</i> option.""") self.output_image = cps.ImageNameProvider("Name the output image", "TiledImage", doc=""" What do you want to call the final tiled image?""") self.additional_images = [] self.add_button = cps.DoSomething("", "Add another image", self.add_image) self.tile_method = cps.Choice("Tile within cycles or across cycles?", T_ALL, doc=''' How would you like to tile images? Two options are available:<br> <ul> <li><i>Tile within cycles:</i> If you have loaded more than one image for each cycle using modules upstream in the pipeline, the images can be tiled. For example, you may tile three different channels (OrigRed, OrigBlue, and OrigGreen), and a new tiled image will be created for every image cycle. This option takes the place of the obsolete <b>PlaceAdjacent</b> module. </li> <li><i>Tile across cycles:</i> If you want to tile images from multiple cycles together, select this option. For example, you may tile all the images of the same type (e.g., OrigBlue) across all fields of view in your experiment, which will result in one final tiled image when processing is complete.</li> </ul>''') self.rows = cps.Integer("Number of rows in final tiled image", 8, doc=''' How many rows would you like to have in the tiled image? For example, if you want to show your images in a 96-well format, enter 8. <p><i>Special cases:</i> Let <i>M</i> be the total number of slots for images (i.e, number of rows x number of columns) and <i>N</i> be the number of actual images. <ul> <li>If <i>M</i> > <i>N</i>, blanks will be used for the empty slots.</li> <li>If the <i>M</i> < <i>N</i>, an error will occur since there are not enough image slots. Check "Automatically calculate number of rows?" to avoid this error.</li> </ul></p>''') self.columns = cps.Integer( "Number of columns in final tiled image", 12, doc='''How many columns would you like to have in the tiled image? For example, if you want to show your images in a 96-well format, enter 12. <p><i>Special cases:</i> Let <i>M</i> be the total number of slots for images (i.e, number of rows x number of columns) and <i>N</i> be the number of actual images. <ul> <li>If <i>M</i> > <i>N</i>, blanks will be used for the empty slots.</li> <li>If the <i>M</i> < <i>N</i>, an error will occur since there are not enough image slots. Check "Automatically calculate number of columns?" to avoid this error.</li> </ul></p>''') self.place_first = cps.Choice( "Begin tiling in which corner of the final image?", P_ALL, doc=''' Where do you want the first image to be placed? Begin in the upper left-hand corner for a typical multi-well plate format where the first image is A01.''' ) self.tile_style = cps.Choice( "Begin tiling across a row, or down a column?", S_ALL, doc=''' Are the images arranged in rows or columns? If your images are named A01, A02, etc, enter <i>row</i>".''') self.meander = cps.Binary("Tile in meander mode?", False, doc=''' Meander mode tiles adjacent images in one direction, then the next row/column is tiled in the opposite direction. Some microscopes capture images in this fashion. The default mode is "comb", or "typewriter" mode; in this mode, when one row is completely tiled in one direction, the next row starts near where the first row started and tiles again in the same direction.''') self.wants_automatic_rows = cps.Binary( "Automatically calculate number of rows?", False, doc="""<b>Tile</b> can automatically calculate the number of rows in the grid based on the number of image cycles that will be processed. Check this box to create a grid that has the number of columns that you entered and enough rows to display all of your images. If you check both automatic rows and automatic columns, <b>Tile</b> will create a grid that has roughly the same number of rows and columns.""") self.wants_automatic_columns = cps.Binary( "Automatically calculate number of columns?", False, doc="""<b>Tile</b> can automatically calculate the number of columns in the grid from the number of image cycles that will be processed. Check this box to create a grid that has the number of rows that you entered and enough columns to display all of your images. If you check both automatic rows and automatic columns, <b>Tile</b> will create a grid that has roughly the same number of rows and columns.""")
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""")
def create_settings(self): self.sub_object_name = cps.ObjectNameSubscriber( 'Select the input child objects', 'None', doc=""" Child objects are defined as those objects contained within the parent object. For example, when relating speckles to the nuclei that contains them, the speckles are the children.""") self.parent_name = cps.ObjectNameSubscriber( 'Select the input parent objects', 'None', doc=""" Parent objects are defined as those objects which encompass the child object. For example, when relating speckles to the nuclei that contains them, the nuclei are the parents.""") self.find_parent_child_distances = cps.Choice("Calculate distances?", D_ALL, doc=""" Do you want to calculate the distances of each child to its parent? <br> <ul><li>The <i>minimum distance</i> is the distance from the centroid of the child object to the closest perimeter point on the parent object.</li> <li>The <i>centroid distance</i> is the distance from the centroid of the child object to the centroid of the parent. </li></ul>""") self.wants_step_parent_distances = cps.Binary( "Calculate distances to other parents?", False, doc= """<i>(Used only if calculating distances)</i><br>You can calculate the distances of the child objects to some other objects. These objects must be either parents or children of your parent object in order for this module to determine the distances. For instance, you might find "Nuclei" using <b>IdentifyPrimaryObjects</b>, find "Cells" using <b>IdentifySecondaryObjects</b> and find "Cytoplasm" using <b>IdentifyTertiaryObjects</b>. You can use <b>Relate</b> to relate speckles to cells and then measure distances to nuclei and cytoplasm. You could not use <b>RelateObjects</b> to relate speckles to cytoplasm and then measure distances to nuclei, because nuclei is neither a direct parent or child of cytoplasm.""") self.step_parent_names = [] self.add_step_parent(can_delete=False) self.add_step_parent_button = cps.DoSomething("", "Add another parent", self.add_step_parent) self.wants_per_parent_means = cps.Binary( 'Calculate per-parent means for all child measurements?', False, doc=""" For every measurement that has been made of the children objects upstream in the pipeline, this module calculates the mean value of that measurement over all children and stores it as a measurement for the parent, as "Mean_<child>_<category>_<feature>". For this reason, this module should be placed <i>after</i> all <b>Measure</b> modules that make measurements of the children objects.""")
def create_settings(self): """Create your settings by subclassing this function create_settings is called at the end of initialization. You should create the setting variables for your module here: # Ask the user for the input image self.image_name = cellprofiler.settings.ImageNameSubscriber(...) # Ask the user for the name of the output image self.output_image = cellprofiler.settings.ImageNameProvider(...) # Ask the user for a parameter self.smoothing_size = cellprofiler.settings.Float(...) """ self.object_name = cps.ObjectNameSubscriber( "Select the objects to be edited", cps.NONE,doc=""" Choose a set of previously identified objects for editing, such as those produced by one of the <b>Identify</b> modules.""") self.filtered_objects = cps.ObjectNameProvider( "Name the edited objects","EditedObjects",doc=""" Enter the name for the objects that remain after editing. These objects will be available for use by subsequent modules.""") self.allow_overlap = cps.Binary( "Allow overlapping objects?", False,doc = """ <b>EditObjectsManually</b> can allow you to edit an object so that it overlaps another or it can prevent you from overlapping one object with another. Objects such as worms or the neurites of neurons may cross each other and might need to be edited with overlapping allowed, whereas a monolayer of cells might be best edited with overlapping off. <br> Select <i>%(YES)s</i> to allow overlaps or select <i>%(NO)s</i> to prevent them."""%globals()) self.wants_outlines = cps.Binary( "Retain outlines of the edited objects?", False,doc=""" Select <i>%(YES)s</i> if you want to keep images of the outlines of the objects that remain after editing. This image can be saved by downstream modules or overlayed on other images using the <b>OverlayOutlines</b> module."""%globals()) self.outlines_name = cps.OutlineNameProvider( "Name the outline image", "EditedObjectOutlines", doc=""" <i>(Used only if you have selected to retain outlines of edited objects)</i><br> Enter a name for the outline image.""") self.renumber_choice = cps.Choice( "Numbering of the edited objects", [R_RENUMBER, R_RETAIN],doc=""" Choose how to number the objects that remain after editing, which controls how edited objects are associated with their predecessors: <ul> <li><i>%(R_RENUMBER)s:</i> The module will number the objects that remain using consecutive numbers. This is a good choice if you do not plan to use measurements from the original objects and you only want to use the edited objects in downstream modules; the objects that remain after editing will not have gaps in numbering where removed objects are missing.</li> <li><i>%(R_RETAIN)s:</i> This option will retain each object's original number so that the edited object's number matches its original number. This allows any measurements you make from the edited objects to be directly aligned with measurements you might have made of the original, unedited objects (or objects directly associated with them).</li> </ul>"""%globals()) self.wants_image_display = cps.Binary( "Display a guiding image?", True,doc = """ Select <i>%(YES)s</i> to display an image and outlines of the objects. <br> Select <i>%(NO)s</i> if you do not want a guide image while editing"""%globals()) self.image_name = cps.ImageNameSubscriber( "Select the guiding image", cps.NONE,doc = """ <i>(Used only if a guiding image is desired)</i><br> This is the image that will appear when editing objects. Choose an image supplied by a previous module.""")
def create_settings(self): '''Create the UI settings for the module''' self.seed_objects_name = cps.ObjectNameSubscriber( "Select the seed objects", "None", doc = """Select the previously identified objects that you want to use as the seeds for measuring branches and distances. Branches and trunks are assigned per seed object. Seed objects are typically not single points/pixels but instead are usually objects of varying sizes.""") self.image_name = cps.ImageNameSubscriber( "Select the skeletonized image", "None", doc = """Select the skeletonized image of the dendrites and / or axons as produced by the <b>Morph</b> module's <i>Skel</i> operation.""") self.wants_branchpoint_image = cps.Binary( "Retain the branchpoint image?", False, doc="""Check this setting if you want to save the color image of branchpoints and trunks. This is the image that is displayed in the output window for this module.""") self.branchpoint_image_name = cps.ImageNameProvider( "Name the branchpoint image","BranchpointImage", doc=""" <i>(Used only if a branchpoint image is to be retained)</i><br> Enter a name for the branchpoint image here. You can then use this image in a later module, such as <b>SaveImages</b>.""") self.wants_to_fill_holes = cps.Binary( "Fill small holes?", True, doc="""The algorithm reskeletonizes the image and this can leave artifacts caused by small holes in the image prior to skeletonizing. These holes result in false trunks and branchpoints. Check this setting to fill in these small holes prior to skeletonizing.""") self.maximum_hole_size = cps.Integer( "Maximum hole size:", 10, minval = 1, doc = """<i>(Used only when filling small holes)</i><br>This is the area of the largest hole to fill, measured in pixels. The algorithm will fill in any hole whose area is this size or smaller""") self.wants_neuron_graph = cps.Binary( "Do you want the neuron graph relationship?", False, doc = """Check this setting to produce an edge file and a vertex file that give the relationships between trunks, branchpoints and vertices""") self.intensity_image_name = cps.ImageNameSubscriber( "Intensity image:", "None", doc = """What is the name of the image to be used to calculate the total intensity along the edges between the vertices?""") self.directory = cps.DirectoryPath( "File output directory:", dir_choices = [ cps.DEFAULT_OUTPUT_FOLDER_NAME, cps.DEFAULT_INPUT_FOLDER_NAME, cps.ABSOLUTE_FOLDER_NAME, cps.DEFAULT_OUTPUT_SUBFOLDER_NAME, cps.DEFAULT_INPUT_SUBFOLDER_NAME]) self.vertex_file_name = cps.Text( "Vertex file name: ", "vertices.csv", doc = """Enter the name of the file that will hold the edge information. You can use metadata tags in the file name. Each line of the file is a row of comma-separated values. The first row is the header; this names the file's columns. Each subsequent row represents a vertex in the neuron skeleton graph: either a trunk, a branchpoint or an endpoint. The file has the following columns: <br><ul> <li><i>image_number</i> : the image number of the associated image</li> <li><i>vertex_number</i> : the number of the vertex within the image</li> <li><i>i</i> : The I coordinate of the vertex.</li> <li><i>j</i> : The J coordinate of the vertex.</li> <li><i>label</i> : The label of the seed object associated with the vertex.</li> <li><i>kind</i> : The kind of vertex it is. <ul><li><b>T</b>: trunk</li> <li><b>B</b>: branchpoint</li> <li><b>E</b>: endpoint</li></ul></li></ul> """) self.edge_file_name = cps.Text( "Edge file name:", "edges.csv", doc="""Enter the name of the file that will hold the edge information. You can use metadata tags in the file name. Each line of the file is a row of comma-separated values. The first row is the header; this names the file's columns. Each subsequent row represents an edge or connection between two vertices (including between a vertex and itself for certain loops). The file has the following columns: <br><ul> <li><i>image_number</i> : the image number of the associated image</li> <li><i>v1</i> : The zero-based index into the vertex table of the first vertex in the edge.</li> <li><i>v2</i> : The zero-based index into the vertex table of the second vertex in the edge.</li> <li><i>length</i> : The number of pixels in the path connecting the two vertices, including both vertex pixels</li> <li><i>total_intensity</i> : The sum of the intensities of the pixels in the edge, including both vertex pixel intensities.</li> </ul> """)
def create_settings(self): """Create your settings by subclassing this function create_settings is called at the end of initialization. """ self.grid_name = cps.GridNameSubscriber("Select the defined grid", cps.NONE, doc=""" Select the name of a grid created by a previous <b>DefineGrid</b> module.""") self.output_objects_name = cps.ObjectNameProvider( "Name the objects to be identified", "Wells", doc=""" Enter the name of the grid objects identified by this module. These objects will be available for further measurement and processing in subsequent modules.""" ) self.shape_choice = cps.Choice("Select object shapes and locations", [ SHAPE_RECTANGLE, SHAPE_CIRCLE_FORCED, SHAPE_CIRCLE_NATURAL, SHAPE_NATURAL ], doc=""" Use this setting to choose the method to be used to determine the grid objects' shapes and locations: <ul> <li><i>%(SHAPE_RECTANGLE)s:</i> Each object will be created as a rectangle, completely occupying the entire grid compartment (rectangle). This option creates the rectangular objects based solely on the grid's specifications, not on any previously identified guiding objects.</li> <li><i>%(SHAPE_CIRCLE_FORCED)s:</i> Each object will be created as a circle, centered in the middle of each grid compartment. This option places the circular objects' locations based solely on the grid's specifications, not on any previously identified guiding objects. The radius of all circles in a grid will be constant for the entire grid in each image cycle, and can be determined automatically for each image cycle based on the average radius of previously identified guiding objects for that image cycle, or instead it can be specified as a single radius for all circles in all grids in the entire analysis run.</li> <li><i>%(SHAPE_CIRCLE_NATURAL)s:</i> Each object will be created as a circle, and each circle's location within its grid compartment will be determined based on the location of any previously identified guiding objects within that grid compartment. Thus, if a guiding object lies within a particular grid compartment, that object's center will be the center of the created circular object. If no guiding objects lie within a particular grid compartment, the circular object is placed within the center of that grid compartment. If more than one guiding object lies within the grid compartment, they will be combined and the centroid of this combined object will be the location of the created circular object. Note that guiding objects whose centers are close to the grid edge are ignored.</li> <li><i>%(SHAPE_NATURAL)s:</i> Within each grid compartment, the object will be identified based on combining all of the parts of guiding objects, if any, that fall within the grid compartment. Note that guiding objects whose centers are close to the grid edge are ignored. If a guiding object does not exist within a grid compartment, an object consisting of one single pixel in the middle of the grid compartment will be created.</li> </ul>""" % globals()) self.diameter_choice = cps.Choice( "Specify the circle diameter automatically?", [AM_AUTOMATIC, AM_MANUAL], doc=""" <i>(Used only if Circle is selected as object shape)</i><br> There are two methods for selecting the circle diameter: <ul> <li><i>%(AM_AUTOMATIC)s:</i> Uses the average diameter of previously identified guiding objects as the diameter.</li> <li><i>%(AM_MANUAL)s:</i> Lets you specify the diameter directly, as a number.</li> </ul>""" % globals()) self.diameter = cps.Integer("Circle diameter", 20, minval=2, doc=""" <i>(Used only if Circle is selected as object shape and diameter is specified manually)</i><br> Enter the diameter to be used for each grid circle, in pixels. %(HELP_ON_MEASURING_DISTANCES)s""" % globals()) self.guiding_object_name = cps.ObjectNameSubscriber( "Select the guiding objects", cps.NONE, doc=""" <i>(Used only if Circle is selected as object shape and diameter is specified automatically, or if Natural Location is selected as the object shape)</i><br> Select the names of previously identified objects that will be used to guide the shape and/or location of the objects created by this module, depending on the method chosen.""") self.wants_outlines = cps.Binary( "Retain outlines of the identified objects?", False, doc=""" %(RETAINING_OUTLINES_HELP)s""" % globals()) self.outlines_name = cps.OutlineNameProvider("Name the outline image", "GridOutlines", doc=""" %(NAMING_OUTLINES_HELP)s""" % globals())
def create_settings(self): """Create the settings for the module Create the settings for the module during initialization. """ self.image_name = cps.ImageNameSubscriber("Select the input image", cps.NONE, doc=""" The name of a binary image from a previous module. <b>IdentifyDeadWorms</b> will use this image to establish the foreground and background for the fitting operation. You can use <b>ApplyThreshold</b> to threshold a grayscale image and create the binary mask. You can also use a module such as <b>IdentifyPrimaryObjects</b> to label each worm and then use <b>ConvertObjectsToImage</b> to make the result a mask.""") self.object_name = cps.ObjectNameProvider( "Name the dead worm objects to be identified", "DeadWorms", doc=""" This is the name for the dead worm objects. You can refer to this name in subsequent modules such as <b>IdentifySecondaryObjects</b>""") self.worm_width = cps.Integer("Worm width", 10, minval=1, doc=""" This is the width (the short axis), measured in pixels, of the diamond used as a template when matching against the worm. It should be less than the width of a worm.""") self.worm_length = cps.Integer("Worm length", 100, minval=1, doc=""" This is the length (the long axis), measured in pixels, of the diamond used as a template when matching against the worm. It should be less than the length of a worm""") self.angle_count = cps.Integer("Number of angles", 32, minval=1, doc=""" This is the number of different angles at which the template will be tried. For instance, if there are 12 angles, the template will be rotated by 0°, 15°, 30°, 45° ... 165°. The shape is bilaterally symmetric; that is, you will get the same shape after rotating it by 180°.""") self.wants_automatic_distance = cps.Binary( "Automatically calculate distance parameters?", True, doc=""" This setting determines whether or not <b>IdentifyDeadWorms</b> automatically calculates the parameters used to determine whether two found-worm centers belong to the same worm. <p>Select <i>%(YES)s</i> to have <b>IdentifyDeadWorms</b> automatically calculate the distance from the worm length and width. Select <i>%(NO)s</i> to set the distances manually.</p>""" % globals()) self.space_distance = cps.Float("Spatial distance", 5, minval=1, doc=""" <i>(Used only if not automatically calculating distance parameters)</i><br> Enter the distance for calculating the worm centers, in units of pixels. The worm centers must be at least many pixels apart for the centers to be considered two separate worms.""") self.angular_distance = cps.Float("Angular distance", 30, minval=1, doc=""" <i>(Used only if automatically calculating distance parameters)</i><br> <b>IdentifyDeadWorms</b> calculates the worm centers at different angles. Two worm centers are considered to represent different worms if their angular distance is larger than this number. The number is measured in degrees.""")
def create_settings(self): """Create the module settings create_settings is called at the end of initialization. """ self.object = cps.ObjectNameSubscriber( 'Select the object whose measurements will be displayed', 'None', doc=''' Choose the name of objects identified by some previous module (such as <b>IdentifyPrimaryObjects</b> or <b>IdentifySecondaryObjects</b>) whose measurements are to be displayed.''' ) self.x_axis = cps.Measurement('Select the object measurement to plot', self.get_object, 'None', doc=''' Choose the object measurement made by a previous module to plot.''') self.bins = cps.Integer('Number of bins', 100, 1, 1000, doc=''' Enter the number of equally-spaced bins that you want used on the X-axis.''') self.xscale = cps.Choice( 'Transform the data prior to plotting along the X-axis?', ['no', 'log'], None, doc=''' The measurement data can be scaled with either a linear scale (<i>No</i>) or a <i>log</i> (base 10) scaling. <p>Log scaling is useful when one of the measurements being plotted covers a large range of values; a log scale can bring out features in the measurements that would not easily be seen if the measurement is plotted linearly.<p>''') self.yscale = cps.Choice('How should the Y-axis be scaled?', ['linear', 'log'], None, doc=''' The Y-axis can be scaled either with either a <i>linear</i> scale or a <i>log</i> (base 10) scaling. <p>Log scaling is useful when one of the measurements being plotted covers a large range of values; a log scale can bring out features in the measurements that would not easily be seen if the measurement is plotted linearly.</p>''') self.title = cps.Text('Enter a title for the plot, if desired', '', doc=''' Enter a title for the plot. If you leave this blank, the title will default to <i>(cycle N)</i> where <i>N</i> is the current image cycle being executed.''') self.wants_xbounds = cps.Binary( 'Specify min/max bounds for the x-axis?', False, doc='''You can specifiy minimum and maximum values for the plot on the x-axis. This is helpful if an outlier bin skews the plot such that the bins of interest are no longer visible.''' ) self.xbounds = cps.FloatRange('Minimum/maximum values for the x-axis')
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.""")
def create_settings(self): self.input_image = cps.ImageNameSubscriber("Select an input image", cps.NONE, doc=""" Select the image to be tiled. Additional images within the cycle can be added later by choosing the "<i>%(T_ACROSS_CYCLES)s</i>"option below.""" % globals()) self.output_image = cps.ImageNameProvider("Name the output image", "TiledImage", doc=""" Enter a name for the final tiled image.""") self.additional_images = [] self.add_button = cps.DoSomething("", "Add another image", self.add_image) self.tile_method = cps.Choice("Tile assembly method", T_ALL, doc=''' This setting controls the method by which the final tiled image is asembled: <ul> <li><i>%(T_WITHIN_CYCLES)s:</i> If you have loaded more than one image for each cycle using modules upstream in the pipeline, the images can be tiled. For example, you may tile three different channels (OrigRed, OrigBlue, and OrigGreen), and a new tiled image will be created for every image cycle. </li> <li><i>%(T_ACROSS_CYCLES)s:</i> If you want to tile images from multiple cycles together, select this option. For example, you may tile all the images of the same type (e.g., OrigBlue) across all fields of view in your experiment, which will result in one final tiled image when processing is complete.</li> </ul>''' % globals()) self.rows = cps.Integer("Final number of rows", 8, doc=''' Specify the number of rows would you like to have in the tiled image. For example, if you want to show your images in a 96-well format, enter 8. <p><i>Special cases:</i> Let <i>M</i> be the total number of slots for images (i.e, number of rows x number of columns) and <i>N</i> be the number of actual images. <ul> <li>If <i>M</i> > <i>N</i>, blanks will be used for the empty slots.</li> <li>If the <i>M</i> < <i>N</i>, an error will occur since there are not enough image slots. Check "Automatically calculate number of rows?" to avoid this error.</li> </ul></p>''') self.columns = cps.Integer("Final number of columns", 12, doc=''' Specify the number of columns you like to have in the tiled image. For example, if you want to show your images in a 96-well format, enter 12. <p><i>Special cases:</i> Let <i>M</i> be the total number of slots for images (i.e, number of rows x number of columns) and <i>N</i> be the number of actual images. <ul> <li>If <i>M</i> > <i>N</i>, blanks will be used for the empty slots.</li> <li>If the <i>M</i> < <i>N</i>, an error will occur since there are not enough image slots. Check "Automatically calculate number of columns?" to avoid this error.</li> </ul></p>''') self.place_first = cps.Choice("Image corner to begin tiling", P_ALL, doc=''' Where do you want the first image to be placed? Begin in the upper left-hand corner for a typical multi-well plate format where the first image is A01.''' ) self.tile_style = cps.Choice("Direction to begin tiling", S_ALL, doc=''' This setting specifies the order that the images are to be arranged. If your images are named A01, A02, etc, enter <i>%(S_ROW)s</i>".''' % globals()) self.meander = cps.Binary("Use meander mode?", False, doc=''' Select <i>%(YES)s</i> to tile adjacent images in one direction, then the next row/column is tiled in the opposite direction. Some microscopes capture images in this fashion. The default mode is "comb", or "typewriter" mode; in this mode, when one row is completely tiled in one direction, the next row starts near where the first row started and tiles again in the same direction.''' % globals()) self.wants_automatic_rows = cps.Binary( "Automatically calculate number of rows?", False, doc=""" <b>Tile</b> can automatically calculate the number of rows in the grid based on the number of image cycles that will be processed. Select <i>%(YES)s</i> to create a grid that has the number of columns that you entered and enough rows to display all of your images. Select <i>%(NO)s</i> to specify the number of rows. <p>If you check both automatic rows and automatic columns, <b>Tile</b> will create a grid that has roughly the same number of rows and columns.</p>""" % globals()) self.wants_automatic_columns = cps.Binary( "Automatically calculate number of columns?", False, doc=""" <b>Tile</b> can automatically calculate the number of columns in the grid from the number of image cycles that will be processed. Select <i>%(YES)s</i> to create a grid that has the number of rows that you entered and enough columns to display all of your images. Select <i>%(NO)s</i> to specify the number of rows. <p>If you check both automatic rows and automatic columns, <b>Tile</b> will create a grid that has roughly the same number of rows and columns.</p>""" % globals())
def add_single_measurement(self, can_delete=True): '''Add a single measurement to the group of single measurements can_delete - True to include a "remove" button, False if you're not allowed to remove it. ''' group = cps.SettingsGroup() if can_delete: group.append("divider", cps.Divider(line=True)) group.append( "object_name", cps.ObjectNameSubscriber( "Select the object to be classified", cps.NONE, doc="""The name of the objects to be classified. You can choose from objects created by any previous module. See <b>IdentifyPrimaryObjects</b>, <b>IdentifySecondaryObjects</b>, or <b>IdentifyTertiaryObjects</b>.""")) def object_fn(): return group.object_name.value group.append( "measurement", cps.Measurement("Select the measurement to classify by", object_fn, doc=""" Select a measurement made by a previous module. The objects will be classified according to their values for this measurement.""")) group.append( "bin_choice", cps.Choice("Select bin spacing", [BC_EVEN, BC_CUSTOM], doc=""" Select how you want to define the spacing of the bins. You have the following options: <ul> <li><i>%(BC_EVEN)s:</i> Choose this if you want to specify bins of equal size, bounded by upper and lower limits. If you want two bins, choose this option and then provide a single threshold when asked.</li> <li><i>%(BC_CUSTOM)s:</i> Choose this option to create the indicated number of bins at evenly spaced intervals between the low and high threshold. You also have the option to create bins for objects that fall below or above the low and high threshold.</li> </ul> """ % globals())) group.append( "bin_count", cps.Integer("Number of bins", 3, minval=1, doc=""" This is the number of bins that will be created between the low and high threshold""")) group.append( "low_threshold", cps.Float("Lower threshold", 0, doc=""" <i>(Used only if "%(BC_EVEN)s" selected)</i><br> This is the threshold that separates the lowest bin from the others. The lower threshold, upper threshold, and number of bins define the thresholds of bins between the lowest and highest. """ % globals())) group.append( "wants_low_bin", cps.Binary("Use a bin for objects below the threshold?", False, doc=""" Select <i>%(YES)s</i> if you want to create a bin for objects whose values fall below the low threshold. Select <i>%(NO)s</i> if you do not want a bin for these objects. """ % globals())) def min_upper_threshold(): return group.low_threshold.value + np.finfo(float).eps group.append( "high_threshold", cps.Float("Upper threshold", 1, minval=cps.NumberConnector(min_upper_threshold), doc=""" <i>(Used only if "%(BC_EVEN)s" selected)</i><br> This is the threshold that separates the last bin from the others. <i>Note:</i> If you would like two bins, you should select <i>%(BC_CUSTOM)s</i>. """ % globals())) group.append( "wants_high_bin", cps.Binary("Use a bin for objects above the threshold?", False, doc=""" Select <i>%(YES)s</i> if you want to create a bin for objects whose values are above the high threshold. <br> Select <i>%(NO)s</i> if you do not want a bin for these objects.""" % globals())) group.append( "custom_thresholds", cps.Text( "Enter the custom thresholds separating the values between bins", "0,1", doc=""" <i>(Used only if "%(BC_CUSTOM)s" selected)</i><br> This setting establishes the threshold values for the bins. You should enter one threshold between each bin, separating thresholds with commas (for example, <i>0.3, 1.5, 2.1</i> for four bins). The module will create one more bin than there are thresholds. """ % globals())) group.append( "wants_custom_names", cps.Binary("Give each bin a name?", False, doc=""" Select <i>%(YES)s</i> to assign custom names to bins you have specified. <p>Select <i>%(NO)s</i> for the module to automatically assign names based on the measurements and the bin number.""" % globals())) group.append( "bin_names", cps.Text("Enter the bin names separated by commas", cps.NONE, doc=""" <i>(Used only if Give each bin a name? is checked)</i><br> Enter names for each of the bins, separated by commas. An example including three bins might be <i>First,Second,Third</i>.""" )) group.append( "wants_images", cps.Binary("Retain an image of the classified objects?", False, doc=""" Select <i>%(YES)s</i> to keep an image of the objects which is color-coded according to their classification, for use later in the pipeline (for example, to be saved by a <b>SaveImages</b> module).""" % globals())) group.append( "image_name", cps.ImageNameProvider("Name the output image", "ClassifiedNuclei", doc=""" Enter the name to be given to the classified object image.""")) group.can_delete = can_delete def number_of_bins(): '''Return the # of bins in this classification''' if group.bin_choice == BC_EVEN: value = group.bin_count.value else: value = len(group.custom_thresholds.value.split(",")) - 1 if group.wants_low_bin: value += 1 if group.wants_high_bin: value += 1 return value group.number_of_bins = number_of_bins def measurement_name(): '''Get the measurement name to use inside the bin name Account for conflicts with previous measurements ''' measurement_name = group.measurement.value other_same = 0 for other in self.single_measurements: if id(other) == id(group): break if other.measurement.value == measurement_name: other_same += 1 if other_same > 0: measurement_name += str(other_same) return measurement_name def bin_feature_names(): '''Return the feature names for each bin''' if group.wants_custom_names: return [ name.strip() for name in group.bin_names.value.split(",") ] return [ '_'.join((measurement_name(), 'Bin_%d' % (i + 1))) for i in range(number_of_bins()) ] group.bin_feature_names = bin_feature_names def validate_group(): bin_name_count = len(bin_feature_names()) bin_count = number_of_bins() if bin_count < 1: bad_setting = (group.bin_count if group.bin_choice == BC_EVEN else group.custom_thresholds) raise cps.ValidationError( "You must have at least one bin in order to take measurements. " "Either add more bins or ask for bins for objects above or below threshold", bad_setting) if bin_name_count != number_of_bins(): raise cps.ValidationError( "The number of bin names (%d) does not match the number of bins (%d)." % (bin_name_count, bin_count), group.bin_names) for bin_feature_name in bin_feature_names(): cps.AlphanumericText.validate_alphanumeric_text( bin_feature_name, group.bin_names, True) if group.bin_choice == BC_CUSTOM: try: [ float(x.strip()) for x in group.custom_thresholds.value.split(",") ] except ValueError: raise cps.ValidationError( 'Custom thresholds must be a comma-separated list ' 'of numbers (example: "1.0, 2.3, 4.5")', group.custom_thresholds) group.validate_group = validate_group if can_delete: group.remove_settings_button = cps.RemoveSettingButton( "", "Remove this classification", self.single_measurements, group) self.single_measurements.append(group)
def test_01_01_set_true(self): x = cps.Binary("text", False) x.value = True self.assertTrue(x.value == True)
def test_00_02_init_false(self): x = cps.Binary("text", False) self.assertTrue(x.value == False) self.assertFalse(x == True) self.assertFalse(x != False) self.assertTrue(x != True)
def add_file(self, can_remove=True): """Add settings for another file to the list""" group = cps.SettingsGroup() if can_remove: group.append("divider", cps.Divider(line=False)) def get_directory_fn(): return self.directory.get_absolute_path() group.append( "file_name", cps.FilenameText( FILE_TEXT, cps.NONE, metadata=True, get_directory_fn=get_directory_fn, exts=[("TIF - Tagged Image File format (*.tif,*.tiff)", "*.tif,*.tiff"), ("PNG - Portable Network Graphics (*.png)", "*.png"), ("JPG/JPEG file (*.jpg,*.jpeg)", "*.jpg,*.jpeg"), ("BMP - Windows Bitmap (*.bmp)", "*.bmp"), ("Compuserve GIF file (*.gif)", "*.gif"), ("MATLAB image (*.mat)", "*.mat"), ("All files (*.*)", "*.*")], doc=""" The filename can be constructed in one of two ways: <ul> <li>As a fixed filename (e.g., <i>Exp1_D03f00d0.tif</i>). </li> <li>Using the metadata associated with an image set in <b>LoadImages</b> or <b>LoadData</b>. This is especially useful if you want your output given a unique label according to the metadata corresponding to an image group. The name of the metadata to substitute is included in a special tag format embedded in your file specification. %(USING_METADATA_TAGS_REF)s%(USING_METADATA_HELP_REF)s.</li> </ul> <p>Keep in mind that in either case, the image file extension, if any, must be included.""" % globals())) group.append( "image_objects_choice", cps.Choice('Load as images or objects?', IO_ALL, doc=""" This setting determines whether you load an image as image data or as segmentation results (i.e., objects): <ul> <li><i>%(IO_IMAGES)s:</i> The input image will be given a user-specified name by which it will be refered downstream. This is the most common usage for this module.</li> <li><i>%(IO_OBJECTS)s:</i> Use this option if the input image is a label matrix and you want to obtain the objects that it defines. A <i>label matrix</i> is a grayscale or color image in which the connected regions share the same label, and defines how objects are represented in CellProfiler. The labels are integer values greater than or equal to 0. The elements equal to 0 are the background, whereas the elements equal to 1 make up one object, the elements equal to 2 make up a second object, and so on. This option allows you to use the objects without needing to insert an <b>Identify</b> module to extract them first. See <b>IdentifyPrimaryObjects</b> for more details.</li> </ul>""" % globals())) group.append( "image_name", cps.FileImageNameProvider("Name the image that will be loaded", "OrigBlue", doc=''' <i>(Used only if an image is output)</i><br> Enter the name of the image that will be loaded. You can use this name to select the image in downstream modules.''' )) group.append( "rescale", cps.Binary("Rescale intensities?", True, doc=""" <i>(Used only if an image is output)</i><br> This option determines whether image metadata should be used to rescale the image's intensities. Some image formats save the maximum possible intensity value along with the pixel data. For instance, a microscope might acquire images using a 12-bit A/D converter which outputs intensity values between zero and 4095, but stores the values in a field that can take values up to 65535. <p>Select <i>%(YES)s</i> to rescale the image intensity so that saturated values are rescaled to 1.0 by dividing all pixels in the image by the maximum possible intensity value. </p> <p>Select <i>%(NO)s</i> to ignore the image metadata and rescale the image to 0 – 1.0 by dividing by 255 or 65535, depending on the number of bits used to store the image.</p>""" % globals())) group.append( "objects_name", cps.ObjectNameProvider( 'Name this loaded object', "Nuclei", doc="""<i>(Used only if objects are output)</i><br> This is the name for the objects loaded from your image""") ) group.append( "wants_outlines", cps.Binary("Retain outlines of loaded objects?", False, doc=""" <i>(Used only if objects are output)</i><br> Select <i>%(YES)s</i> if you want to save an image of the outlines of the loaded objects.""" % globals())) group.append( "outlines_name", cps.OutlineNameProvider('Name the outlines', 'NucleiOutlines', doc=""" <i>(Used only if objects are output)</i><br> Enter a name that will allow the outlines to be selected later in the pipeline.""" )) if can_remove: group.append( "remove", cps.RemoveSettingButton("", "Remove this image", self.file_settings, group)) self.file_settings.append(group)
def create_settings(self): # the list of per image settings (name & scaling factor) self.images = [] # create the first two images (the default number) self.add_image(False) self.add_image(False) # other settings self.operation = cps.Choice("Operation", [O_ADD, O_SUBTRACT, O_DIFFERENCE, O_MULTIPLY, O_DIVIDE, O_AVERAGE, O_MAXIMUM, O_INVERT, O_LOG_TRANSFORM, O_NONE], doc= """What operation would you like performed? <p><i>Note:</i> If more than 2 images are chosen, then operations will be performed sequentially from first to last, e.g., for "Divide", (Image1 / Image2) / Image3 <ul> <li><i>Add</i> adds the first image to the second, and so on.</li> <li><i>Subtract</i> subtracts the second image from the first.</li> <li><i>Multiply</i> multiplies the first image by the second.</li> <li><i>Divide </i> divides the first image by the second.</li> <li><i>Average</i> calculates the mean intensity of the images loaded in the module. This is equivalent to the Add option divided by the number of images loaded by this module. If you would like to average all of the images in an entire pipeline, i.e., across cycles, you should instead use the <b>CorrectIlluminationCalculate</b> module and choose the <i>All</i> (vs. <i>Each</i>) option.</li> <li><i>Maximum </i> returns the element-wise maximum value at each pixel location.</li> <li><i>Invert</i> subtracts the image intensities from 1. This makes the darkest color the brightest and vice-versa.</li> <li><i>Log transform (base 2)</i> log transforms each pixel's intensity. </li> <li><i>None</i> is useful if you simply want to select some of the later options in the module, such as adding, multiplying, or exponentiating your image by a constant.</li> </ul> <p>Note that <i>Invert</i>, <i>Log Transform</i>, and <i>None</i> operate on only a single image. """) self.divider_top = cps.Divider(line=False) self.exponent = cps.Float("Raise the power of the result by", 1, doc=""" Enter an exponent to raise the result to *after* the chosen operation""") self.after_factor = cps.Float("Multiply the result by", 1, doc=""" Enter a factor to multiply the result by *after* the chosen operation""") self.addend = cps.Float("Add to result", 0, doc =""" Enter a number to add to the result *after* the chosen operation""") self.truncate_low = cps.Binary("Set values less than 0 equal to 0?", True, doc=""" Do you want negative values to be set to 0? Values outside the range 0 to 1 might not be handled well by other modules. Here you have the option of setting negative values to 0.""") self.truncate_high = cps.Binary("Set values greater than 1 equal to 1?", True, doc =""" Do you want values greater than one to be set to 1? Values outside the range 0 to 1 might not be handled well by other modules. Here you have the option of setting values greater than 1 to a maximum value of 1.""") self.ignore_mask = cps.Binary("Ignore the image masks?", False, doc = """Usually, the smallest mask of all image operands is applied after image math has been completed. Choosing to ignore the masks will set equal to zero all previously masked pixels and operate on the masked images as if no mask had been applied.""") self.output_image_name = cps.ImageNameProvider("Name the output image", "ImageAfterMath", doc="""What do you want to call the resulting image?""") self.add_button = cps.DoSomething("", "Add another image", self.add_image) self.divider_bottom = cps.Divider(line=False)
def create_settings(self): '''Create the settings that control this module''' self.object_name = cps.ObjectNameSubscriber( "Select objects to be masked", cps.NONE, doc=""" Select the objects that will be masked (that is, excluded in whole or in part based on the other settings in the module). You can choose from any objects created by a previous object processing module, such as <b>IdentifyPrimaryObjects</b>, <b>IdentifySecondaryObjects</b> or <b>IdentifyTertiaryObjects</b>.""" ) self.remaining_objects = cps.ObjectNameProvider( "Name the masked objects", "MaskedNuclei", doc=""" Enter a name for the objects that remain after the masking operation. You can refer to the masked objects in subsequent modules by this name.""") self.mask_choice = cps.Choice( "Mask using a region defined by other objects or by binary image?", [MC_OBJECTS, MC_IMAGE], doc=""" You can mask your objects by defining a region using objects you previously identified in your pipeline (<i>%(MC_OBJECTS)s</i>) or by defining a region based on the white regions in a binary image (<i>%(MC_IMAGE)s</i>).""" % globals()) self.masking_objects = cps.ObjectNameSubscriber( "Select the masking object", cps.NONE, doc=""" Select the objects that will be used to define the masking region. You can choose from any objects created by a previous object processing module, such as <b>IdentifyPrimaryObjects</b>, <b>IdentifySecondaryObjects</b>, or <b>IdentifyTertiaryObjects</b>.""" ) self.masking_image = cps.ImageNameSubscriber( "Select the masking image", cps.NONE, doc=""" Select an image that was either loaded or created by a previous module. The image should be a binary image where the white portion of the image is the region(s) you will use for masking. Binary images can be loaded from disk using the <b>NamesAndTypes</b> module by selecting "Binary mask" for the image type. You can also create a binary image from a grayscale image using <b>ApplyThreshold</b>.""") self.wants_inverted_mask = cps.Binary("Invert the mask?", False, doc=""" This option reverses the foreground/background relationship of the mask. <ul> <li>Select <i>%(NO)s</i> for the mask to be composed of the foregound (white portion) of the masking image or the area within the masking objects.</li> <li>Select <i>%(YES)s</i> for the mask to instead be composed of the <i>background</i> (black portions) of the masking image or the area <i>outside</i> the masking objects.</li> </ul>""" % globals()) self.overlap_choice = cps.Choice( "Handling of objects that are partially masked", [P_MASK, P_KEEP, P_REMOVE, P_REMOVE_PERCENTAGE], doc=""" An object might partially overlap the mask region, with pixels both inside and outside the region. <b>MaskObjects</b> can handle this in one of three ways:<br> <ul> <li><i>%(P_MASK)s:</i> Choosing this option will reduce the size of partially overlapping objects. The part of the object that overlaps the region will be retained. The part of the object that is outside of the region will be removed.</li> <li><i>%(P_KEEP)s:</i> If you choose this option, <b>MaskObjects</b> will keep the whole object if any part of it overlaps the masking region.</li> <li><i>%(P_REMOVE)s:</i> Objects that are partially outside of the masking region will be completely removed if you choose this option.</li> <li><i>%(P_REMOVE_PERCENTAGE)s:</i> Determine whether to remove or keep an object depending on how much of the object overlaps the masking region. <b>MaskObjects</b> will keep an object if at least a certain fraction (which you enter below) of the object falls within the masking region. <b>MaskObjects</b> completely removes the object if too little of it overlaps the masking region.</li> </ul>""" % globals()) self.overlap_fraction = cps.Float( "Fraction of object that must overlap", .5, minval=0, maxval=1, doc=""" <i>(Used only if removing based on a overlap)</i><br> Specify the minimum fraction of an object that must overlap the masking region for that object to be retained. For instance, if the fraction is 0.75, then 3/4 of an object must be within the masking region for that object to be retained.""" ) self.retain_or_renumber = cps.Choice("Numbering of resulting objects", [R_RENUMBER, R_RETAIN], doc=""" Choose how to number the objects that remain after masking, which controls how remaining objects are associated with their predecessors: <ul> <li><i>%(R_RENUMBER)s:</i> The objects that remain will be renumbered using consecutive numbers. This is a good choice if you do not plan to use measurements from the original objects; your object measurements for the masked objects will not have gaps (where removed objects are missing).</li> <li><i>%(R_RETAIN)s:</i>: The original labels for the objects will be retained. This allows any measurements you make from the masked objects to be directly aligned with measurements you might have made of the original, unmasked objects (or objects directly associated with them).</li> </ul>""" % globals()) self.wants_outlines = cps.Binary( "Retain outlines of the resulting objects?", False, doc=""" %(RETAINING_OUTLINES_HELP)s""" % globals()) self.outlines_name = cps.OutlineNameProvider("Name the outline image", "MaskedOutlines", doc=""" %(NAMING_OUTLINES_HELP)s""" % globals())
def create_settings(self): '''Create the settings for the module's UI''' self.warning = cps.Divider( "This module allows you to rename (overwrite) your files. Please " "see the help for this module for warnings.") self.image_name = cps.FileImageNameSubscriber('Select the input image', cps.NONE, doc=""" Select the images associated with the files you want to rename. This should be an image loaded by the <b>Input</b> modules. Be very careful because you will be renaming these files!""") self.number_characters_prefix = cps.Integer( "Number of characters to retain at start of file name", 6, minval=0, doc=""" Number of characters at the start of the old file name that will be copied over verbatim to the new file name. For instance, if this setting is "6" and the file name is "Image-734.tif", the output file name will also start with "Image-".""") self.number_characters_suffix = cps.Integer( "Number of characters to retain at the end of file name", 4, minval=0, doc=""" Number of characters at the end of the old file name that will be copied over verbatim to the new file name. For instance, if this setting is "4" and the file name is "Image-734.tif", the output file name will also end with ".tif".""" ) self.action = cps.Choice("Handling of remaining characters", [A_RENUMBER, A_DELETE], doc=""" You can either treat the characters between the start and end as numbers or you can delete them. If you treat them as numbers, you will be given the opportunity to pad the numbers with zeros so that all of your file names will have a uniform length. For instance, if you were to renumber the highlighted portion of the file "Image-<u>734</u>.tif" using four digits, the result would be "Image-0734.tif".""") self.number_digits = cps.Integer("Number of digits for numbers", 4, minval=0, doc=""" <i>(Used only if %(A_RENUMBER)s is selected)</i><br> Use this setting to pad numbers with zeros so that they all have a uniform number of characters. For instance, padding with four digits has the following result:<br> <code><table> <tr><th>Original</th><th>Padded</th></tr> <tr><td>1</td><td>0001</td></tr> <tr><td>10</td><td>0010</td></tr> <tr><td>100</td><td>0100</td></tr> <tr><td>1000</td><td>1000</td></tr> </table></code>""" % globals()) self.wants_text = cps.Binary("Add text to the file name?", False, doc=""" Select <i>%(YES)s</i> if you want to add text to the file name. If you had chosen <i>%(A_RENUMBER)s</i> above, the module will add the text after your number. If you had chosen <i>%(A_DELETE)s</i>, the module will replace the deleted text with the text you enter here.""" % globals()) self.text_to_add = cps.Text("Replacement text", "", doc=""" <i>(Used only if you chose to add text to the file name)</i><br> Enter the text that you want to add to each file name.""") self.wants_to_replace_spaces = cps.Binary("Replace spaces?", False, doc=""" Select <i>%(YES)s</i> to replace spaces in the final version of the file name with some other text. <p>Select <i>%(NO)s</i> if the file name can have spaces or if none of the file names have spaces.</p>""" % globals()) self.space_replacement = cps.Text("Space replacement", "_", doc=""" This is the text that will be substituted for spaces in your file name.""")
def create_settings(self): self.orig_image_name = cps.ImageNameSubscriber( "Select the input images", "None", doc="""Select the images to display on the web page.""") self.wants_thumbnails = cps.Binary( "Use thumbnail images?", False, doc= """Check this option to display thumbnail images (small versions of the images) on the web page that link to the full images. Leave it unchecked to display the full image directly on the web page. <p>If you are going to use thumbnails, you will need to load them using <b>LoadImages</b> or <b>LoadData</b>; you can run a separate pipeline prior to this one to create thumbnails from your originals using the <b>Resize</b> and <b>SaveImages</b> modules. For some high-content screening systems, thumbnail files are automatically created and have the text "thumb" in the name.</p>""") self.thumbnail_image_name = cps.ImageNameSubscriber( "Select the thumbnail images", "None", doc=""" <i>(Used only if using thumbnails)</i><br> Select the name of the images to use for thumbnails.""") self.web_page_file_name = cps.Text( "Webpage file name", "images1", metadata=True, doc= """Enter the desired file name for the web page. <b>CreateWebPage</b> will add the .html extension if no extension is specified. If you have metadata associated with your images, you can name the file using metadata tags. %(USING_METADATA_TAGS_REF)s<br> For instance, if you have metadata tags named "Plate" and "Well", you can create separate per-plate, per-well web pages based on your metadata by inserting the tags "Plate_Well" to specify the name. %(USING_METADATA_HELP_REF)s.""" % globals()) self.directory_choice = cps.Choice( "Select the folder for the .html file", [DIR_SAME, DIR_ABOVE], doc="""This setting determines how <b>CreateWebPage</b> selects the folder for the .html file(s) it creates. <ul> <li><i>%(DIR_SAME)s</i>: Place the .html file(s) in the same folder as the files.</li> <li><i>%(DIR_ABOVE)s</i>: Place the .html file(s) in the image files' parent folder.</li> </ul>""" % globals()) self.title = cps.Text( "Webpage title", "Image", metadata=True, doc="""This is the title that appears at the top of the browser window. If you have metadata associated with your images, you can name the file using metadata tags. %(USING_METADATA_TAGS_REF)sFor instance, if you have a metadata tag named "Plate", you can type "Plate: " and then insert the metadata tag "Plate" to display the plate metadata item. %(USING_METADATA_HELP_REF)s.""" % globals()) self.background_color = cps.Color( "Webpage background color", "White", doc= """This setting controls the background color for the web page.""") self.columns = cps.Integer( "Number of columns", 1, minval=1, doc="""This setting determines how many images are displayed in each row.""") self.table_border_width = cps.Integer( "Table border width", 1, minval=0, doc="""The table border width determines the width of the border around the entire grid of displayed images (i.e., the "table" of images) and is measured in pixels. This value can be set to zero, in which case you will not see the table border.""") self.table_border_color = cps.Color("Table border color", "White") self.image_spacing = cps.Integer( "Image spacing", 1, minval=0, doc="""The spacing between images ("table cells"), in pixels.""") self.image_border_width = cps.Integer( "Image border width", 1, minval=0, doc="""The image border width determines the width of the border around each image and is measured in pixels. This value can be set to zero, in which case you will not see the image border.""") self.create_new_window = cps.Choice( "Open new window when viewing full image?", [OPEN_ONCE, OPEN_EACH, OPEN_NO], doc="""This controls the behavior of the thumbnail links. If you select, <i>%(OPEN_ONCE)s</i>, your browser will open a new window when you click on the first thumbnail and will display subsequent images in the newly opened window. If you select <i> %(OPEN_EACH)s</i>, the browser will open a new window each time you click on a link. If you select, <i>%(OPEN_NO)s</i>, the browser will reuse the current window to display the image""" % globals()) self.wants_zip_file = cps.Binary( "Make a ZIP file containing the full-size images?", False, doc=""" ZIP files are a common archive and data compression file format, making it convenient to download all of the images represented on the web page with a single click. Check this box to create a ZIP file that contains all your images, compressed to reduce file size.""") self.zipfile_name = cps.Text("Enter the ZIP file name", "Images.zip", metadata=True, doc=""" <i>(Used only if creating a ZIP file)</i><br> Specify the name for the ZIP file.""")
def create_settings(self): self.image_name = cps.ImageNameSubscriber("Select the input image", cps.NONE) self.output_name = cps.ImageNameProvider("Name the output image", "FlippedOrigBlue") self.flip_choice = cps.Choice("Select method to flip image", FLIP_ALL, doc=""" Select how the image is to be flipped.""") self.rotate_choice = cps.Choice("Select method to rotate image", ROTATE_ALL, doc=''' <ul> <li><i>%(ROTATE_NONE)s:</i> Leave the image unrotated. This should be used if you want to flip the image only.</li> <li><i>%(ROTATE_ANGLE)s:</i> Provide the numerical angle by which the image should be rotated.</li> <li><i>%(ROTATE_COORDINATES)s:</i> Provide the X,Y pixel locations of two points in the image that should be aligned horizontally or vertically.</li> <li><i>%(ROTATE_MOUSE)s:</i> CellProfiler will pause so you can select the rotation interactively. When prompted during the analysis run, grab the image by clicking the left mouse button, rotate the image by dragging with the mouse, then release the mouse button. Press the <i>Done</i> button on the image after rotating the image appropriately.</li> </ul>''' % globals()) self.wants_crop = cps.Binary("Crop away the rotated edges?", True, doc=''' <i>(Used only when rotating images)</i> <br> When an image is rotated, there will be black space at the corners/edges; select <i>%(YES)s</i> to crop away the incomplete rows and columns of the image, or select <i>%(NO)s</i> to leave it as-is. <p>This cropping will produce an image that is not exactly the same size as the original, which may affect downstream modules.</p>''' % globals()) self.how_often = cps.Choice("Calculate rotation", IO_ALL, doc=''' <i>(Used only when using "%(ROTATE_MOUSE)s" to rotate images)</i> <br> Select the cycle(s) at which the calculation is requested and calculated. <ul> <li><i>%(IO_INDIVIDUALLY)s:</i> Determine the amount of rotation for each image individually, e.g., for each cycle.</li> <li><i>%(IO_ONCE)s:</i> Define the rotation only once (on the first image), then then apply it to all images.</li> </ul>''' % globals()) self.first_pixel = cps.Coordinates( "Enter coordinates of the top or left pixel", (0, 0)) self.second_pixel = cps.Coordinates( "Enter the coordinates of the bottom or right pixel", (0, 100)) self.horiz_or_vert = cps.Choice( "Select how the specified points should be aligned", C_ALL, doc=""" <i>(Used only when using "%(ROTATE_COORDINATES)s" to rotate images)</i><br> Specify whether you would like the coordinate points that you entered to be horizontally or vertically aligned after the rotation is complete.""" % globals()) self.angle = cps.Float("Enter angle of rotation", 0, doc=""" <i>(Used only when using "%(ROTATE_ANGLE)s" to rotate images)</i> <br> Enter the angle you would like to rotate the image. This setting is in degrees, with positive angles corresponding to counterclockwise and negative as clockwise.""" % globals())
def create_settings(self): """Create your settings by subclassing this function create_settings is called at the end of initialization. You should create the setting variables for your module here: # Ask the user for the input image self.image_name = cellprofiler.settings.ImageNameSubscriber(...) # Ask the user for the name of the output image self.output_image = cellprofiler.settings.ImageNameProvider(...) # Ask the user for a parameter self.smoothing_size = cellprofiler.settings.Float(...) """ self.objects_or_image = cps.Choice( "Display object or image measurements?", [OI_OBJECTS, OI_IMAGE], doc=""" <ul> <li><i>%(OI_OBJECTS)s</i> displays measurements made on objects.</li> <li><i>%(OI_IMAGE)s</i> displays a single measurement made on an image.</li> </ul>""" % globals()) self.objects_name = cps.ObjectNameSubscriber( "Select the input objects", cps.NONE, doc=""" <i>(Used only when displaying object measurements)</i><br> Choose the name of objects identified by some previous module (such as <b>IdentifyPrimaryObjects</b> or <b>IdentifySecondaryObjects</b>).""") def object_fn(): if self.objects_or_image == OI_OBJECTS: return self.objects_name.value else: return cpmeas.IMAGE self.measurement = cps.Measurement("Measurement to display", object_fn, doc=""" Choose the measurement to display. This will be a measurement made by some previous module on either the whole image (if displaying a single image measurement) or on the objects you selected.""") self.wants_image = cps.Binary( "Display background image?", True, doc="""Choose whether or not to display the measurements on a background image. Usually, you will want to see the image context for the measurements, but it may be useful to save just the overlay of the text measurements and composite the overlay image and the original image later. Choose "Yes" to display the measurements on top of a background image or "No" to display the measurements on a black background.""") self.image_name = cps.ImageNameSubscriber( "Select the image on which to display the measurements", cps.NONE, doc=""" Choose the image to be displayed behind the measurements. This can be any image created or loaded by a previous module. If you have chosen not to display the background image, the image will only be used to determine the dimensions of the displayed image""" ) self.color_or_text = cps.Choice( "Display mode", [CT_TEXT, CT_COLOR], doc="""<i>(Used only when displaying object measurements)</i><br> Choose how to display the measurement information. If you choose %(CT_TEXT)s, <b>DisplayDataOnImage</b> will display the numeric value on top of each object. If you choose %(CT_COLOR)s, <b>DisplayDataOnImage</b> will convert the image to grayscale, if necessary, and display the portion of the image within each object using a hue that indicates the measurement value relative to the other objects in the set using the default color map. """ % globals()) self.colormap = cps.Colormap( "Color map", doc="""<i>(Used only when displaying object measurements)</i><br> This is the color map used as the color gradient for coloring the objects by their measurement values. """) self.text_color = cps.Color("Text color", "red", doc=""" This is the color that will be used when displaying the text. """) self.display_image = cps.ImageNameProvider( "Name the output image that has the measurements displayed", "DisplayImage", doc=""" The name that will be given to the image with the measurements superimposed. You can use this name to refer to the image in subsequent modules (such as <b>SaveImages</b>).""") self.font_size = cps.Integer("Font size (points)", 10, minval=1) self.decimals = cps.Integer("Number of decimals", 2, minval=0) self.saved_image_contents = cps.Choice("Image elements to save", [E_IMAGE, E_FIGURE, E_AXES], doc=""" This setting controls the level of annotation on the image: <ul> <li><i>%(E_IMAGE)s:</i> Saves the image with the overlaid measurement annotations.</li> <li><i>%(E_AXES)s:</i> Adds axes with tick marks and image coordinates.</li> <li><i>%(E_FIGURE)s:</i> Adds a title and other decorations.</li></ul>""" % globals()) self.offset = cps.Integer("Annotation offset (in pixels)", 0, doc=""" Add a pixel offset to the measurement. Normally, the text is placed at the object (or image) center, which can obscure relevant features of the object. This setting adds a specified offset to the text, in a random direction.""")
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")
def create_settings(self): self.image_name = cps.ImageNameSubscriber('Select the input image', 'None') self.filtered_image_name = cps.ImageNameProvider( 'Name the output image', 'FilteredImage') self.smoothing_method = cps.Choice('Select smoothing method', [ FIT_POLYNOMIAL, GAUSSIAN_FILTER, MEDIAN_FILTER, SMOOTH_KEEPING_EDGES, CIRCULAR_AVERAGE_FILTER, SM_TO_AVERAGE ], doc=""" This module smooths images using one of several filters. Fitting a polynomial is fastest but does not allow a very tight fit compared to the other methods: <ul> <li><i>Fit Polynomial:</i> This method treats the intensity of the image pixels as a polynomial function of the x and y position of each pixel. It fits the intensity to the polynomial, <i>A x<sup>2</sup> + B y<sup>2</sup> + C x*y + D x + E y + F</i>. This will produce a smoothed image with a single peak or trough of intensity that tapers off elsewhere in the image. For many microscopy images (where the illumination of the lamp is brightest in the center of field of view), this method will produce an image with a bright central region and dimmer edges. But, in some cases the peak/trough of the polynomial may actually occur outside of the image itself.</li> <li><i>Gaussian Filter:</i> This method convolves the image with a Gaussian whose full width at half maximum is the artifact diameter entered. Its effect is to blur and obscure features smaller than the artifact diameter and spread bright or dim features larger than the artifact diameter.</li> <li><i>Median Filter:</i> This method finds the median pixel value within the artifact diameter you specify. It removes bright or dim features that are much smaller than the artifact diameter.</li> <li><i>Smooth Keeping Edges:</i> This method uses a bilateral filter which limits Gaussian smoothing across an edge while applying smoothing perpendicular to an edge. The effect is to respect edges in an image while smoothing other features. <i>Smooth Keeping Edges</i> will filter an image with reasonable speed for artifact diameters greater than 10 and for intensity differences greater than 0.1. The algorithm will consume more memory and operate more slowly as you lower these numbers.</li> <li><i>Circular Average Filter:</i> This method convolves the image with a uniform circular averaging filter whose size is the artifact diameter entered. This filter is useful for re-creating an out-of-focus blur to an image.</li> <li><i>Smooth to Average:</i> Creates a flat, smooth image where every pixel of the image equals the average value of the original image.</li> </ul>""") self.wants_automatic_object_size = cps.Binary( 'Calculate artifact diameter automatically?', True, doc=""" <i>(Used only if Gaussian, Median, Smooth Keeping Edges or Circular Average Filter is selected)</i><br> If this box is checked, the module will choose an artifact diameter based on the size of the image. The minimum size it will choose is 30 pixels, otherwise the size is 1/40 of the size of the image.""") self.object_size = cps.Float('Typical artifact diameter, in pixels', 16.0, doc=""" <i>(Used only if choosing the artifact diameter automatically is unchecked)</i><br> Enter the approximate diameter of the features to be blurred by the smoothing algorithm. This value is used to calculate the size of the spatial filter. %(HELP_ON_MEASURING_DISTANCES)s For most smoothing methods, selecting a diameter over ~50 will take substantial amounts of time to process.""" % globals()) self.sigma_range = cps.Float('Edge intensity difference', .1, doc=""" <i>(Used only if Smooth Keeping Edges is selected)</i><br> What are the differences in intensity in the edges that you want to preserve? Enter the intensity step that indicates an edge in an image. Edges are locations where the intensity changes precipitously, so this setting is used to adjust the rough magnitude of these changes. A lower number will preserve weaker edges. A higher number will preserve only stronger edges. Values should be between zero and one. %(HELP_ON_PIXEL_INTENSITIES)s""" % globals()) self.clip = cps.Binary( 'Clip intensity at 0 and 1', True, doc="""<i>(Used only if Fit Polynomial is selected)</i> The Fit Polynomial is the only smoothing option that can yield an output image whose values are outside of the values of the input image. This setting controls whether to limit the image intensity to the 0 - 1 range used by CellProfiler. Check this setting to set all output image pixels less than zero to zero and all pixels greater than one to one. Uncheck the setting to allow values less than zero and greater than one in the output image. """)
def create_settings(self): self.blank_image = cps.Binary("Display outlines on a blank image?", False, doc=""" Select <i>%(YES)s</i> to produce an image of the outlines on a black background. <p>Select <i>%(NO)s</i>, the module will overlay the outlines on an image of your choosing.</p>""" % globals()) self.image_name = cps.ImageNameSubscriber( "Select image on which to display outlines", cps.NONE, doc=""" <i>(Used only when a blank image has not been selected)</i> <br> Choose the image to serve as the background for the outlines. You can choose from images that were loaded or created by modules previous to this one.""") self.line_width = cps.Float("Width of outlines", "1", doc=""" Enter the width, in pixels, of the outlines to be displayed on the image.""") self.output_image_name = cps.ImageNameProvider("Name the output image", "OrigOverlay", doc=""" Enter the name of the output image with the outlines overlaid. This image can be selected in later modules (for instance, <b>SaveImages</b>).""" ) self.wants_color = cps.Choice("Outline display mode", [WANTS_COLOR, WANTS_GRAYSCALE], doc=""" Specify how to display the outline contours around your objects. Color outlines produce a clearer display for images where the cell borders have a high intensity, but take up more space in memory. Grayscale outlines are displayed with either the highest possible intensity or the same intensity as the brightest pixel in the image.""") self.spacer = cps.Divider(line=False) self.max_type = cps.Choice( "Select method to determine brightness of outlines", [MAX_IMAGE, MAX_POSSIBLE], doc=""" <i>(Used only when outline display mode is grayscale)</i> <br> The following options are possible for setting the intensity (brightness) of the outlines: <ul> <li><i>%(MAX_IMAGE)s:</i> Set the brighness to the the same as the brightest point in the image.</li> <li><i>%(MAX_POSSIBLE)s:</i> Set to the maximum possible value for this image format.</li> </ul> If your image is quite dim, then putting bright white lines onto it may not be useful. It may be preferable to make the outlines equal to the maximal brightness already occurring in the image.""" % globals()) self.outlines = [] self.add_outline(can_remove=False) self.add_outline_button = cps.DoSomething("", "Add another outline", self.add_outline)
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="""Check this box if you need to enter a username and password to authenticate.""") 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 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""")
def create_settings(self): self.objects_name = cps.ObjectNameSubscriber( "Select the input objects", cps.NONE, doc=""" Select the objects whose object numbers you want to reassign. You can use any objects that were created in previous modules, such as <b>IdentifyPrimaryObjects</b> or <b>IdentifySecondaryObjects</b>.""" ) self.output_objects_name = cps.ObjectNameProvider( "Name the new objects", "RelabeledNuclei", doc=""" Enter a name for the objects whose numbers have been reassigned. You can use this name in subsequent modules that take objects as inputs.""" ) self.relabel_option = cps.Choice("Operation", [OPTION_UNIFY, OPTION_SPLIT], doc=""" You can choose one of the following options: <ul> <li><i>%(OPTION_UNIFY)s:</i> Assign adjacent or nearby objects the same label based on certain criteria. It can be useful, for example, to merge together touching objects that were incorrectly split into two pieces by an <b>Identify</b> module.</li> <li><i>%(OPTION_SPLIT)s:</i> Assign a unique number to separate objects that currently share the same label. This can occur if you applied certain operations with the <b>Morph</b> module to objects.</li> </ul>""" % globals()) self.unify_option = cps.Choice("Unification method", [UNIFY_DISTANCE, UNIFY_PARENT], doc=""" <i>(Used only with the %(OPTION_UNIFY)s option)</i><br> You can unify objects in one of two ways: <ul> <li><i>%(UNIFY_DISTANCE)s: </i> All objects within a certain pixel radius from each other will be unified</li> <li><i>%(UNIFY_PARENT)s: </i>All objects which share the same parent relationship to another object will be unified. This is not be confused with using the <b>RelateObjects</b> module, in which the related objects remain as individual objects. See <b>RelateObjects</b> for more details.</li> </ul> """ % globals()) self.parent_object = cps.Choice("Select the parent object", [cps.NONE], choices_fn=self.get_parent_choices, doc=""" Select the parent object that will be used to unify the child objects. Please note the following: <ul> <li>You must have established a parent-child relationship between the objects using a prior <b>RelateObjects</b> module.</li> <li>Primary objects and their associated secondary objects are already in a one-to-one parent-child relationship, so it makes no sense to unify them here.</li> </ul>""") self.distance_threshold = cps.Integer( "Maximum distance within which to unify objects", 0, minval=0, doc=""" <i>(Used only with the %(OPTION_UNIFY)s option and the %(UNIFY_DISTANCE)s method)</i><br> Objects that are less than or equal to the distance you enter here, in pixels, will be unified. If you choose zero (the default), only objects that are touching will be unified. Note that <i>%(OPTION_UNIFY)s </i> will not actually connect or bridge the two objects by adding any new pixels; it simply assigns the same object number to the portions of the object. The new, unified object may therefore consist of two or more unconnected components.""" % globals()) self.wants_image = cps.Binary("Unify using a grayscale image?", False, doc=""" <i>(Used only with the %(OPTION_UNIFY)s option)</i><br> Select <i>%(YES)s</i> to use the objects' intensity features to determine whether two objects should be unified. If you choose to use a grayscale image, <i>%(OPTION_UNIFY)s</i> will unify two objects only if they are within the distance you have specified <i>and</i> certain criteria about the objects within the grayscale image are met.""" % globals()) self.image_name = cps.ImageNameSubscriber( "Select the grayscale image to guide unification", cps.NONE, doc=""" <i>(Used only if a grayscale image is to be used as a guide for unification)</i><br> Select the name of an image loaded or created by a previous module.""" ) self.minimum_intensity_fraction = cps.Float( "Minimum intensity fraction", .9, minval=0, maxval=1, doc=""" <i>(Used only if a grayscale image is to be used as a guide for unification)</i><br> Select the minimum acceptable intensity fraction. This will be used as described for the method you choose in the next setting.""") self.where_algorithm = cps.Choice("Method to find object intensity", [CA_CLOSEST_POINT, CA_CENTROIDS], doc=""" <i>(Used only if a grayscale image is to be used as a guide for unification)</i><br> You can use one of two methods to determine whether two objects should unified, assuming they meet the distance criteria (as specified above): <ul> <li><i>%(CA_CENTROIDS)s:</i> When the module considers merging two objects, this method identifies the centroid of each object, records the intensity value of the dimmer of the two centroids, multiplies this value by the <i>minimum intensity fraction</i> to generate a threshold, and draws a line between the centroids. The method will unify the two objects only if the intensity of every point along the line is above the threshold. For instance, if the intensity of one centroid is 0.75 and the other is 0.50 and the <i>minimum intensity fraction</i> has been chosen to be 0.9, all points along the line would need to have an intensity of min(0.75, 0.50) * 0.9 = 0.50 * 0.9 = 0.45.<br> This method works well for round cells whose maximum intensity is in the center of the cell: a single cell that was incorrectly segmented into two objects will typically not have a dim line between the centroids of the two halves and will be correctly unified.</li> <li><i>%(CA_CLOSEST_POINT)s:</i> This method is useful for unifying irregularly shaped cells which are connected. It starts by assigning background pixels in the vicinity of the objects to the nearest object. Objects are then unified if each object has background pixels that are: <ul> <li>Within a distance threshold from each object;</li> <li>Above the minimum intensity fraction of the nearest object pixel;</li> <li>Adjacent to background pixels assigned to a neighboring object.</li> </ul> An example of a feature that satisfies the above constraints is a line of pixels that connect two neighboring objects and is roughly the same intensity as the boundary pixels of both (such as an axon connecting two neurons).</li> </ul>""" % globals()) self.wants_outlines = cps.Binary( "Retain outlines of the relabeled objects?", False, doc=""" %(RETAINING_OUTLINES_HELP)s""" % globals()) self.outlines_name = cps.OutlineNameProvider('Name the outlines', 'RelabeledNucleiOutlines', doc=""" %(NAMING_OUTLINES_HELP)s""" % globals())
def add_extraction_method(self, can_remove=True): group = cps.SettingsGroup() self.extraction_methods.append(group) if can_remove: group.append("divider", cps.Divider()) group.append( "extraction_method", cps.Choice("Extraction method", X_ALL_EXTRACTION_METHODS, doc=""" The <b>Metadata</b> module can extract metadata from the images one of three ways: <ul> <li><i>%(X_AUTOMATIC_EXTRACTION)s</i>: From the structure of the file format itself.</li> <li><i>%(X_MANUAL_EXTRACTION)s</i>: From the file nomenclature and/or location, often structure according to the user or acquistion software vendor.</li> <li><i>%(X_IMPORTED_EXTRACTION)s</i>: From a comma-delimited list (csv) of information; provided as one type of metadata per column, and one row of metadata per image. This is a convenient way for you to add data from your own sources to the output generated by CellProfiler.</li> </ul> For more details on how metadata is used downstream from this module, see the help for the <b>NamesAndTypes</b> or <b>Groups</b> module, or <i>%(METADATA_HELP_REF)s</i>""" % globals())) group.append( "source", cps.Choice("Source", [XM_FILE_NAME, XM_FOLDER_NAME], doc=""" Do you want to extract metadata from the image's file name or from its folder name?""")) group.append( "file_regexp", cps.RegexpText( "Regular expression", '^(?P<Plate>.*)_(?P<Well>[A-P][0-9]{2})_s(?P<Site>[0-9])_w(?P<ChannelNumber>[0-9])', get_example_fn=self.example_file_fn, doc=""" <a name='regular_expression'><i>(Used only if you want to extract metadata from the file name)</i><br> The regular expression to extract the metadata from the file name is entered here. Note that this field is available whether you have selected <i>Text-Regular expressions</i> to load the files or not. Please see the general module help for more information on construction of a regular expression.</a> <p>Clicking the magnifying glass icon to the right will bring up a tool for checking the accuracy of your regular expression. The regular expression syntax can be used to name different parts of your expression. The syntax <i>(?P<fieldname>expr)</i> will extract whatever matches <i>expr</i> and assign it to the measurement,<i>fieldname</i> for the image. <p>For instance, a researcher uses plate names composed of a string of letters and numbers, followed by an underscore, then the well, followed by another underscore, followed by an "s" and a digit representing the site taken within the well (e.g., <i>TE12345_A05_s1.tif</i>). The following regular expression will capture the plate, well, and site in the fields "Plate", "Well", and "Site":<br><br> <table border = "1"> <tr><td colspan = "2">^(?P<Plate>.*)_(?P<Well>[A-P][0-9]{1,2})_s(?P<Site>[0-9])</td></tr> <tr><td>^</td><td>Start only at beginning of the file name</td></tr> <tr><td>(?P<Plate></td><td>Name the captured field <i>Plate</i></td></tr> <tr><td>.*</td><td>Capture as many characters as follow</td></tr> <tr><td>_</td><td>Discard the underbar separating plate from well</td></tr> <tr><td>(?P<Well></td><td>Name the captured field <i>Well</i></td></tr> <tr><td>[A-P]</td><td>Capture exactly one letter between A and P</td></tr> <tr><td>[0-9]{1,2}</td><td>Capture one or two digits that follow</td></tr> <tr><td>_s</td><td>Discard the underbar followed by <i>s</i> separating well from site</td></tr> <tr><td>(?P<Site></td><td>Name the captured field <i>Site</i></td></tr> <tr><td>[0-9]</td><td>Capture one digit following</td></tr> </table> <p>The regular expression can be typed in the upper text box, with a sample file name given in the lower text box. Provided the syntax is correct, the corresponding fields will be highlighted in the same color in the two boxes. Press <i>Submit</i> to enter the typed regular expression.</p> <p>You can create metadata tags for any portion of the filename or path, but if you are specifying metadata for multiple images in a single <b>LoadImages</b> module, an image cycle can only have one set of values for each metadata tag. This means that you can only specify the metadata tags which have the same value across all images listed in the module. For example, in the example above, you might load two wavelengths of data, one named <i>TE12345_A05_s1_w1.tif</i> and the other <i>TE12345_A05_s1_w2.tif</i>, where the number following the <i>w</i> is the wavelength. In this case, a "Wavelength" tag <i>should not</i> be included in the regular expression because while the "Plate", "Well" and "Site" metadata is identical for both images, the wavelength metadata is not.</p> <p>Note that if you use the special fieldnames <i><WellColumn></i> and <i><WellRow></i> together, LoadImages will automatically create a <i><Well></i> metadata field by joining the two fieldname values together. For example, if <i><WellRow></i> is "A" and <i><WellColumn></i> is "01", a field <i><Well></i> will be "A01". This is useful if your well row and column names are separated from each other in the filename, but you want to retain the standard well nomenclature.</p>""")) group.append( "folder_regexp", cps.RegexpText("Regular expression", '(?P<Date>[0-9]{4}_[0-9]{2}_[0-9]{2})$', get_example_fn=self.example_directory_fn, doc=""" <i>(Used only if you want to extract metadata from the path)</i><br> Enter the regular expression for extracting the metadata from the path. Note that this field is available whether you have selected <i>Text-Regular expressions</i> to load the files or not. <p>Clicking the magnifying glass icon to the right will bring up a tool that will allow you to check the accuracy of your regular expression. The regular expression syntax can be used to name different parts of your expression. The syntax <i>(?<fieldname>expr)</i> will extract whatever matches <i>expr</i> and assign it to the image's <i>fieldname</i> measurement. <p>For instance, a researcher uses folder names with the date and subfolders containing the images with the run ID (e.g., <i>./2009_10_02/1234/</i>) The following regular expression will capture the plate, well, and site in the fields <i>Date</i> and <i>Run</i>:<br> <table border = "1"> <tr><td colspan = "2">.*[\\\/](?P<Date>.*)[\\\\/](?P<Run>.*)$</td></tr> <tr><td>.*[\\\\/]</td><td>Skip characters at the beginning of the pathname until either a slash (/) or backslash (\\) is encountered (depending on the operating system)</td></tr> <tr><td>(?P<Date></td><td>Name the captured field <i>Date</i></td></tr> <tr><td>.*</td><td>Capture as many characters that follow</td></tr> <tr><td>[\\\\/]</td><td>Discard the slash/backslash character</td></tr> <tr><td>(?P<Run></td><td>Name the captured field <i>Run</i></td></tr> <tr><td>.*</td><td>Capture as many characters as follow</td></tr> <tr><td>$</td><td>The <i>Run</i> field must be at the end of the path string, i.e., the last folder on the path. This also means that the Date field contains the parent folder of the Date folder.</td></tr> </table></p>""")) group.append( "filter_choice", cps.Choice("Extract metadata from:", [F_ALL_IMAGES, F_FILTERED_IMAGES], doc=""" Do you want to extract metadata from all of the images chosen by the <b>Images</b> module or on a subset of the images? <p>This setting controls how different image types (e.g., an image of the GFP stain and a brightfield image) have different metadata extracted. There are two choices:<br> <ul> <li><i>%(F_ALL_IMAGES)s</i>: Extract metadata from all images specified in <b>Images</b>. This is the simplest choice and the appropriate one if you have only one kind of image (or only one image). CellProfiler will extract metadata from all images using the same method per iteration.</li> <li><i>%(F_FILTERED_IMAGES)s</i>: Extract metadata depending on specific file attributes. This is the appropriate choice if more than one image was taken of each imaging site. You can specify distinctive criteria for each image subset with matching metadata.</li> </ul></p>""" % globals())) group.append( "filter", cps.Filter( "", [FilePredicate(), DirectoryPredicate(), ExtensionPredicate()], 'and (file does contain "")', doc=""" Check this setting to display and use rules to select files for metadata extraction. <p>%(FILTER_RULES_BUTTONS_HELP)s</p>""" % globals())) group.append( "csv_location", cps.Pathname( "Metadata file location:", wildcard="Metadata files (*.csv)|*.csv|All files (*.*)|*.*")) group.append( "csv_joiner", cps.Joiner( "Match file and image metadata", allow_none=False, doc="""Match columns in your .csv file to image metadata items <hr> This setting controls how rows in your .csv file are matched to different images. The setting displays the columns in your .csv file in one of its columns and the metadata in your images in the other, including the metadata extracted by previous metadata extractors in this module. """)) group.append( "wants_case_insensitive", cps.Binary( "Case insensitive matching", False, doc="""This setting controls whether row matching takes the metadata case into account when matching. If this setting is not checked, metadata entries that only differ by case (for instance, "A01" and "a01") will not match. If this setting is checked, then metadata entries that only differ by case will match. Check this setting if your CSV metadata is not being applied because the case does not match.""")) group.append( "update_metadata", cps.DoSomething( "Update", "Update metadata", lambda: self.do_update_metadata(group), doc="""Press this button to automatically extract metadata from your image files.""")) group.can_remove = can_remove if can_remove: group.append( "remover", cps.RemoveSettingButton('Remove above extraction method', 'Remove', self.extraction_methods, group))
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.""" )
def create_settings(self): self.object_name = cps.ObjectNameSubscriber( "Select the input objects", cps.NONE, doc=''' Select the objects that you want to expand or shrink.''') self.output_object_name = cps.ObjectNameProvider( "Name the output objects", "ShrunkenNuclei", doc=''' Enter a name for the resulting objects.''') self.operation = cps.Choice( "Select the operation", O_ALL, doc=''' Select the operation that you want to perform: <ul> <li><i>%(O_SHRINK_INF)s:</i> Remove all pixels but one from filled objects. Thin objects with holes to loops unless the "fill" option is checked.</li> <li><i>%(O_EXPAND_INF)s:</i> Expand objects, assigning every pixel in the image to an object. Background pixels are assigned to the nearest object.</li> <li><i>%(O_DIVIDE)s:</i> Remove pixels from an object that are adjacent to another object's pixels unless doing so would change the object's Euler number (break an object in two, remove the object completely or open a hole in an object).</li> <li><i>%(O_SHRINK)s:</i> Remove pixels around the perimeter of an object unless doing so would change the object's Euler number (break the object in two, remove the object completely or open a hole in the object). You can specify the number of times perimeter pixels should be removed. Processing stops automatically when there are no more pixels to remove.</li> <li><i>%(O_EXPAND)s:</i> Expand each object by adding background pixels adjacent to the image. You can choose the number of times to expand. Processing stops automatically if there are no more background pixels.</li> <li><i>%(O_SKELETONIZE)s:</i> Erode each object to its skeleton.</li> <li><i>%(O_SPUR)s:</i> Remove or reduce the length of spurs in a skeletonized image. The algorithm reduces spur size by the number of pixels indicated in the setting <i>Number of pixels by which to expand or shrink</i>.</li> </ul>''' % globals()) self.iterations = cps.Integer( "Number of pixels by which to expand or shrink", 1, minval=1) self.wants_fill_holes = cps.Binary( "Fill holes in objects so that all objects shrink to a single point?", False, doc=""" <i>(Used only if one of the "shrink" options selected)</i><br> Select <i>%(YES)s</i> to ensure that each object will shrink to a single point, by filling the holes in each object. <p>Select <i>%(NO)s</i> to preserve the Euler number. in this case, the shrink algorithm preserves each object's Euler number, which means that it will erode an object with a hole to a ring in order to keep the hole. An object with two holes will be shrunk to two rings connected by a line in order to keep from breaking up the object or breaking the hole.</p>""" % globals()) self.wants_outlines = cps.Binary( "Retain the outlines of the identified objects?", False, doc=""" %(RETAINING_OUTLINES_HELP)s""" % globals()) self.outlines_name = cps.OutlineNameProvider( "Name the outline image", "ShrunkenNucleiOutlines", doc=""" %(NAMING_OUTLINES_HELP)s""" % globals())
def create_settings(self): # # The ImageNameSubscriber "subscribes" to all ImageNameProviders in # prior modules. Modules before yours will put images into CellProfiler. # The ImageSubscriber gives your user a list of these images # which can then be used as inputs in your module. # self.input_image_name = cps.ImageNameSubscriber( # The text to the left of the edit box "Input image name:", # HTML help that gets displayed when the user presses the # help button to the right of the edit box doc="""This is the image that the module operates on. You can choose any image that is made available by a prior module. <br> <b>ImageTemplate</b> will do something to this image. """) # # The ImageNameProvider makes the image available to subsequent # modules. # self.output_image_name = cps.ImageNameProvider( "Output image name:", # The second parameter holds a suggested name for the image. "OutputImage", doc="""This is the image resulting from the operation.""") # # Here's a choice box - the user gets a drop-down list of what # can be done. # self.gradient_choice = cps.Choice( "Gradient choice:", # The choice takes a list of possibilities. The first one # is the default - the one the user will typically choose. [GRADIENT_MAGNITUDE, GRADIENT_DIRECTION_X, GRADIENT_DIRECTION_Y], # # Here, in the documentation, we do a little trick so that # we use the actual text that's displayed in the documentation. # # %(GRADIENT_MAGNITUDE)s will get changed into "Gradient magnitude" # etc. Python will look in globals() for the "GRADIENT_" names # and paste them in where it sees %(GRADIENT_...)s # # The <ul> and <li> tags make a neat bullet-point list in the docs # doc="""Choose what to calculate: <ul> <li><i>%(GRADIENT_MAGNITUDE)s</i> to calculate the magnitude of the gradient at each pixel.</li> <li><i>%(GRADIENT_DIRECTION_X)s</i> to get the relative contribution of the gradient in the X direction (.5 = no contribution, 0 to .5 = decreasing with increasing X, .5 to 1 = increasing with increasing X).</li> <li><i>%(GRADIENT_DIRECTION_Y)s</i> to get the relative contribution of the gradient in the Y direction.</li></ul> """ % globals()) # # A binary setting displays a checkbox. # self.automatic_smoothing = cps.Binary( "Automatically choose the smoothing scale?", # The default value is to choose automatically True, doc="""The module will automatically choose a smoothing scale for you if you leave this checked.""") # # We do a little smoothing which supplies a scale to the gradient. # # We use a float setting so that the user can give us a number # for the scale. The control will turn red if the user types in # an invalid scale. # self.scale = cps.Float( "Scale:", # The default value is 1 - a short-range scale 1, # We don't let the user type in really small values minval=.1, # or large values maxval=100, doc="""This is a scaling factor that supplies the sigma for a gaussian that's used to smooth the image. The gradient is calculated on the smoothed image, so large scales will give you long-range gradients and small scales will give you short-range gradients""")