Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (not from_matlab) and variable_revision_number == 2:
# add otsu threshold settings
assert len(setting_values) % 8 == 0
num_images = len(setting_values) / 8
new_settings = []
for idx in range(num_images):
new_settings += setting_values[(idx * 8):(idx * 8 + 8)]
new_settings += [O_TWO_CLASS, O_WEIGHTED_VARIANCE,
O_FOREGROUND]
setting_values = new_settings
variable_revision_number = 3
return setting_values, variable_revision_number, from_matlab
class MeasureImageQualitySettingsGroup(cps.SettingsGroup):
@property
def threshold_algorithm(self):
'''The thresholding algorithm to run'''
return self.threshold_method.value.split(' ')[0]
@property
def threshold_feature_name(self):
'''The feature name of the threshold measurement generated'''
scale = self.threshold_scale
if scale is None:
return "%s_%s%s_%s"%(IMAGE_QUALITY, THRESHOLD,
self.threshold_algorithm,
self.image_name.value)
else:
return "%s_%s%s_%s_%s" % (IMAGE_QUALITY, THRESHOLD,
self.threshold_algorithm,
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><i>Natural Shape and Location:</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>
""")
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>
The automatic method uses the average diameter of previously identified guiding
objects as the diameter. The manual method lets you specify the
diameter directly, as a number.""")
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. You can use <i>Tools > Show Pixel Data</i> on an open image to measure distances in pixels.""")
self.guiding_object_name = cps.ObjectNameSubscriber(
"Select the guiding objects", "None",
doc="""<i>(Used only if Circle is selected as object shape and diameter is </i>
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():
if self.dir_choice == DIR_DEFAULT_IMAGE_FOLDER:
return cpprefs.get_default_image_directory()
elif self.dir_choice == DIR_DEFAULT_OUTPUT_FOLDER:
return cpprefs.get_default_output_directory()
elif self.dir_choice == DIR_CUSTOM_FOLDER:
return self.custom_directory.value
return os.curdir()
group.append("file_name", cps.FilenameText(
"Filename of the image to load (Include the extension, e.g., .tif)",
"None",
get_directory_fn = get_directory_fn,
exts = [("Tagged image file (*.tif)","*.tif"),
def add_object(self, can_delete = True):
'''Add an object to the object_groups collection'''
group = cps.SettingsGroup()
if can_delete:
group.append("divider", cps.Divider(line=False))
group.append("object_name", cps.ObjectNameSubscriber('Select an object to measure','None',
doc = '''What is the name of objects to be measured?'''))
if can_delete:
group.append("remover", cps.RemoveSettingButton('', 'Remove this object', self.object_groups, group))
self.object_groups.append(group)
def create_settings(self):
self.flags = []
self.flag_count = cps.HiddenCount(self.flags)
self.add_flag_button = cps.DoSomething("", "Add another flag",
self.add_flag)
self.spacer_1 = cps.Divider()
self.add_flag(can_delete = False)
custom_label = self.module_panel.FindWindowByName(custom_ctrl_label_name)
browse_ctrl = self.module_panel.FindWindowByName(browse_ctrl_name)
if dir_ctrl.StringSelection != v.dir_choice:
dir_ctrl.StringSelection = v.dir_choice
if v.is_custom_choice:
if not custom_ctrl.IsShown():
custom_ctrl.Show()
if not custom_label.IsShown():
custom_label.Show()
if not browse_ctrl.IsShown():
browse_ctrl.Show()
if v.dir_choice in (cps.DEFAULT_INPUT_SUBFOLDER_NAME,
cps.DEFAULT_OUTPUT_SUBFOLDER_NAME):
custom_label.Label = "Sub-folder:"
elif v.dir_choice == cps.URL_FOLDER_NAME:
if v.support_urls == cps.SUPPORT_URLS_SHOW_DIR:
custom_label.Label = "URL:"
custom_label.Show()
custom_ctrl.Show()
else:
custom_label.Hide()
custom_ctrl.Hide()
browse_ctrl.Hide()
if custom_ctrl.Value != v.custom_path:
custom_ctrl.Value = v.custom_path
else:
custom_label.Hide()
custom_ctrl.Hide()
browse_ctrl.Hide()
return control
def add_image(self, can_delete = True):
'''Add an image to the image_groups collection
can_delete - set this to False to keep from showing the "remove"
button for images that must be present.
'''
group = cps.SettingsGroup()
if can_delete:
group.append("divider", cps.Divider(line=False))
group.append("image_name", cps.ImageNameSubscriber('Select an image to measure','None',
doc = '''What is the name of an image to be measured?'''))
if len(self.image_groups) == 0: # Insert space between 1st two images for aesthetics
group.append("extra_divider", cps.Divider(line=False))
if can_delete:
group.append("remover", cps.RemoveSettingButton("","Remove this image", self.image_groups, group))
self.image_groups.append(group)
def create_settings(self):
self.image_name = cps.ImageNameSubscriber(
'Select the input image','None',
doc = '''What did you call the images to be made into a projection?''')
self.projection_type = cps.Choice('Type of projection',
P_ALL, doc = '''
What kind of projection would you like to make?
<ul><li>Average: Use the average pixel intensity at each pixel position
to create the final image.</li>
<li>Maximum: Use the maximum pixel value at each pixel position to
create the final image.</li></ul>''')
self.projection_image_name = cps.ImageNameProvider(
'Name the output image',
'ProjectionBlue',
doc = '''What do you want to call the projected image?''',
provided_attributes={cps.AGGREGATE_IMAGE_ATTRIBUTE: True,
cps.AVAILABLE_ON_LAST_ATTRIBUTE: True } )
def add_object(self, can_remove = True):
'''Add an object to the object_groups collection
can_delete - set this to False to keep from showing the "remove"
button for images that must be present.
'''
group = cps.SettingsGroup()
if can_remove:
group.append("divider", cps.Divider(line=False))
group.append("name", cps.ObjectNameSubscriber("Select objects to measure","None", doc =
"""What did you call the objects whose intensities you want to measure?"""))
if can_remove:
group.append("remover", cps.RemoveSettingButton("", "Remove this object", self.objects, group))
self.objects.append(group)
def add_bin_count(self, can_remove = True):
'''Add another radial bin count at which to measure'''
group = cps.SettingsGroup()
if can_remove:
group.append("divider", cps.Divider(line=False))
group.append("bin_count", cps.Integer(
"Number of bins",4, 2, doc="""How many bins do you want to use to measure
the distribution?
The radial distribution is measured with respect to a series
of concentric rings starting from the object center (or
more generally, between contours at a normalized distance
from the object center). This number
specifies the number of rings that the distribution is to
be divided into. Additional ring counts can be specified
by clicking the <i>Add another set of bins</i> button."""))
if can_remove:
group.append("remover", cps.RemoveSettingButton("", "Remove this set of bins", self.bin_counts, group))
self.bin_counts.append(group)