Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
FILTER_CHOICE_IMAGES = "Images only"
FILTER_CHOICE_CUSTOM = "Custom"
FILTER_CHOICE_ALL = [FILTER_CHOICE_NONE, FILTER_CHOICE_IMAGES, FILTER_CHOICE_CUSTOM]
FILTER_DEFAULT = (
'and (extension does isimage) (directory doesnot containregexp "[\\\\\\\\/]\\\\.")'
)
class Images(cellprofiler.module.Module):
variable_revision_number = 2
module_name = "Images"
category = "File Processing"
MI_SHOW_IMAGE = "Show image"
MI_REMOVE = cellprofiler.setting.FileCollectionDisplay.DeleteMenuItem(
"Remove from list"
)
MI_REFRESH = "Refresh"
def create_settings(self):
self.workspace = None
module_explanation = [
"To begin creating your project, use the %s module to compile"
% self.module_name,
"a list of files and/or folders that you want to analyze. You can also specify a set of rules",
"to include only the desired files in your selected folders.",
]
self.set_notes([" ".join(module_explanation)])
self.path_list_display = cellprofiler.setting.PathListDisplay()
predicates = [FilePredicate(), DirectoryPredicate(), ExtensionPredicate()]
group.append(
"image_name",
cps.ImageNameSubscriber(
"Image name",
cps.NONE,
doc="""\
*(Used only if "%(SCHEME_STACK)s" or "%(SCHEME_COMPOSITE)s" is chosen)*
Select the input image to add to the stacked image.
"""
% globals(),
),
)
group.append(
"color",
cps.Color(
"Color",
default_color,
doc="""\
*(Used only if "%(SCHEME_COMPOSITE)s" is chosen)*
The color to be assigned to the above image.
"""
% globals(),
),
)
group.append(
"weight",
cps.Float(
"Weight",
1.0,
minval=0.5 / 255,
def add_image(self, can_delete=True):
"""Add an image and its settings to the list of images"""
image_name = cps.ImageNameSubscriber(
"Select the input image", cps.NONE, doc="Select the image to be corrected."
)
corrected_image_name = cps.ImageNameProvider(
"Name the output image",
"CorrBlue",
doc="Enter a name for the corrected image.",
)
illum_correct_function_image_name = cps.ImageNameSubscriber(
"Select the illumination function",
cps.NONE,
doc="""\
Select the illumination correction function image that will be used to
carry out the correction. This image is usually produced by another
module or loaded as a .mat or .npy format image using the **Images** module
or a **Load** module, most commonly **LoadSingleImage**.
Note that loading .mat format images is deprecated and will be removed in
a future version of CellProfiler. You can export .mat format images as
def create_settings(self):
self.image_names = []
self.add_image(False)
self.add_button = cps.DoSomething('', 'Add another image name', self.add_image)
def add_image(self, can_remove=True):
'''Add an image to the list of image names'''
group = cps.SettingsGroup()
group.append('divider', cps.Divider(line=False))
group.append('image_name', cps.ExternalImageNameSubscriber('Select an image a name to export'))
if can_remove:
group.append('remover', cps.RemoveSettingButton('', 'Remove this image name', self.image_names, group))
self.image_names.append(group)
def add_outline(self, can_remove=True):
group = cellprofiler.setting.SettingsGroup()
if can_remove:
group.append("divider", cellprofiler.setting.Divider(line=False))
group.append(
"objects_name",
cellprofiler.setting.ObjectNameSubscriber(
"Select objects to display",
cellprofiler.setting.NONE,
doc="Choose the objects whose outlines you would like to display.",
),
)
default_color = (
COLOR_ORDER[len(self.outlines)]
if len(self.outlines) < len(COLOR_ORDER)
else COLOR_ORDER[0]
)
group.append(
"color",
cellprofiler.setting.Color(
"Select outline color",
if removable:
divider = cellprofiler.setting.Divider(line=False)
group.append("divider", divider)
image = cellprofiler.setting.ImageNameSubscriber(
doc="Select the grayscale images whose texture you want to measure.",
text="Select an image to measure",
value=cellprofiler.setting.NONE,
)
group.append("image_name", image)
if removable:
remove_setting = cellprofiler.setting.RemoveSettingButton(
entry=group, label="Remove this image", list=self.image_groups, text=""
)
group.append("remover", remove_setting)
self.image_groups.append(group)
cellprofiler.setting.NO,
output_image,
]
module_name = "ImageMath"
variable_revision_number = 2
if from_matlab and variable_revision_number == 1 and module_name == "ImageMath":
image_names = [setting_values[1]]
input_factors = [float(setting_values[4])]
operation = setting_values[3]
factors = []
# The user could type in a constant for the second image name
try:
factors += [float(setting_values[2]) * float(setting_values[5])]
except ValueError:
if setting_values[2] != cellprofiler.setting.DO_NOT_USE:
image_names += [setting_values[2]]
input_factors += [float(setting_values[5])]
exponent = 1.0
multiplier = 1.0
addend = 0
wants_truncate_low = setting_values[6]
wants_truncate_high = setting_values[7]
output_image_name = setting_values[0]
old_operation = operation
if operation == O_DIVIDE and len(factors):
multiplier /= numpy.product(factors)
elif operation == O_MULTIPLY and len(factors):
multiplier *= numpy.product(factors)
elif operation == O_ADD and len(factors):
addend = numpy.sum(factors)
elif operation == O_SUBTRACT:
(on a Windows machine, for instance) and the cluster machine sees the same folder like this:
``/server_name/your_name/your_data/images``
you would enter ``Z:\`` in the previous setting for the local root
path and ``/server_name/your_name/`` here for the cluster root path.""",
),
)
group.append(
"remover",
cps.RemoveSettingButton(
"", "Remove this path mapping", self.mappings, group
),
)
group.append("divider", cps.Divider(line=False))
self.mappings.append(group)
self.repack = cps.Binary(
"Repack after analysis", True,
doc="""
This setting determines whether CellProfiler in multiprocessing mode
repacks the data at the end of analysis. If you select <i>%(YES)s</i>,
CellProfiler will combine all of the satellite files into a single
file upon completion. This option requires some extra temporary disk
space and takes some time at the end of analysis, but results in
a single file which may occupy less disk space. If you select
<i>%(NO)s</i>, CellProfiler will create a master file using the
name that you give and this file will have links to individual
data files that contain the actual data. Using the data generated by
this option requires that you keep the master file and the linked
files together when copying them to a new folder.
""" % globals())
self.plate_metadata = cps.Choice(
"Plate metadata", [], value="Plate",
choices_fn=self.get_metadata_choices,
doc="""
This is the metadata tag that identifies the plate name of
the images for the current cycle. Choose <i>None</i> if
your assay does not have metadata for plate name. If your
assay is slide-based, you can use a metadata item that identifies
the slide as the choice for this setting and set the well
and site metadata items to <i>None</i>.""")
self.well_metadata = cps.Choice(
"Well metadata", [], value="Well",
choices_fn=self.get_metadata_choices,
doc="""This is the metadata tag that identifies the well name
for the images in the current cycle. Choose <i>None</i> if
your assay does not have metadata for the well.""")
self.site_metadata = cps.Choice(