Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cellprofiler.modules.straightenworms.F_LENGTH,
)
)
m.add_measurement(OBJECTS_NAME, feature, lengths)
image_set_list = cellprofiler.image.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.add(IMAGE_NAME, cellprofiler.image.Image(image, mask))
if auximage is not None:
image_set.add(AUX_IMAGE_NAME, cellprofiler.image.Image(auximage))
module.add_image()
module.images[1].image_name.value = AUX_IMAGE_NAME
module.images[1].straightened_image_name.value = AUX_STRAIGHTENED_IMAGE_NAME
object_set = cellprofiler.object.ObjectSet()
objects = cellprofiler.object.Objects()
labels = numpy.zeros(image.shape, int)
for i in range(control_points.shape[2]):
if lengths[i] == 0:
continue
rebuild_worm_from_control_points_approx(
control_points[:, :, i], radii, labels, i + 1
)
objects.segmented = labels
object_set.add_objects(objects, OBJECTS_NAME)
workspace = cellprofiler.workspace.Workspace(
pipeline, module, image_set, object_set, m, image_set_list
)
return workspace, module
module.images[0].common_text.value = "C0.stk"
module.images[0].channels[0].image_name.value = "MyImage"
module.location.dir_choice = cellprofiler.setting.ABSOLUTE_FOLDER_NAME
module.location.custom_path = path
module.set_module_num(1)
pipeline = cellprofiler.pipeline.Pipeline()
pipeline.add_module(module)
pipeline.add_listener(error_callback)
image_set_list = cellprofiler.image.ImageSetList()
m = cellprofiler.measurement.Measurements()
workspace = cellprofiler.workspace.Workspace(
pipeline, module, None, None, m, image_set_list
)
module.prepare_run(workspace)
workspace = cellprofiler.workspace.Workspace(
pipeline, module, m, cellprofiler.object.ObjectSet(), m, image_set_list
)
module.run(workspace)
image = m.get_image("MyImage")
pixel_data = image.pixel_data
assert tuple(pixel_data.shape) == (800, 800, 3)
x.size_range.min = min_size
for unclump_method in (
cellprofiler.modules.identifyprimaryobjects.UN_INTENSITY,
cellprofiler.modules.identifyprimaryobjects.UN_SHAPE,
):
x.unclump_method.value = unclump_method
for watershed_method in (
cellprofiler.modules.identifyprimaryobjects.WA_INTENSITY,
cellprofiler.modules.identifyprimaryobjects.WA_SHAPE,
cellprofiler.modules.identifyprimaryobjects.WA_PROPAGATE
):
x.watershed_method.value = watershed_method
image_set_list = cellprofiler.image.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.add(x.image_name.value, image)
object_set = cellprofiler.object.ObjectSet()
measurements = cellprofiler.measurement.Measurements()
x.run(cellprofiler.workspace.Workspace(pipeline, x, image_set, object_set, measurements, None))
module.images[i].image_name.value = name
img = cellprofiler.image.Image(pixel_data, mask=mask, crop_mask=cropping)
image_set.add(name, img)
module.output_image_name.value = "outputimage"
if modify_module_fn is not None:
modify_module_fn(module)
pipeline = cellprofiler.pipeline.Pipeline()
pipeline.add_module(module)
measurements = cellprofiler.measurement.Measurements()
if measurement is not None:
measurements.add_image_measurement(MEASUREMENT_NAME, str(measurement))
workspace = cellprofiler.workspace.Workspace(
pipeline,
module,
image_set,
cellprofiler.object.ObjectSet(),
measurements,
image_set_list,
)
module.run(workspace)
return image_set.get_image("outputimage")
pipeline, module, csv_name = make_pipeline(csv_text)
assert isinstance(pipeline, cellprofiler.pipeline.Pipeline)
assert isinstance(module, cellprofiler.modules.loaddata.LoadData)
module.wants_images.value = True
try:
image_set_list = cellprofiler.image.ImageSetList()
measurements = cellprofiler.measurement.Measurements()
workspace = cellprofiler.workspace.Workspace(
pipeline, module, None, None, measurements, image_set_list
)
pipeline.prepare_run(workspace)
key_names, g = pipeline.get_groupings(workspace)
assert len(g) == 1
module.prepare_group(workspace, g[0][0], g[0][1])
image_set = image_set_list.get_image_set(g[0][1][0] - 1)
object_set = cellprofiler.object.ObjectSet()
workspace = cellprofiler.workspace.Workspace(
pipeline, module, image_set, object_set, measurements, image_set_list
)
module.run(workspace)
objects = object_set.get_objects(OBJECTS_NAME)
assert numpy.all(objects.segmented == labels)
assert (
measurements.get_current_image_measurement(
cellprofiler.measurement.FF_COUNT % OBJECTS_NAME
)
== 9
)
for feature in (
cellprofiler.measurement.M_LOCATION_CENTER_X,
cellprofiler.measurement.M_LOCATION_CENTER_Y,
cellprofiler.measurement.M_NUMBER_OBJECT_NUMBER,
"""Run the module, returning the measurements
image - matrix representing the image to be analyzed
labels - labels matrix of objects to be analyzed
center_labels - labels matrix of alternate centers or None for self
centers
bin_count - # of radial bins
"""
module = (
cellprofiler.modules.measureobjectintensitydistribution.MeasureObjectIntensityDistribution()
)
module.wants_zernikes.value = wants_zernikes
module.zernike_degree.value = zernike_degree
module.images[0].image_name.value = IMAGE_NAME
module.objects[0].object_name.value = OBJECT_NAME
object_set = cellprofiler.object.ObjectSet()
main_objects = cellprofiler.object.Objects()
main_objects.segmented = labels
object_set.add_objects(main_objects, OBJECT_NAME)
if center_labels is None:
module.objects[
0
].center_choice.value = (
cellprofiler.modules.measureobjectintensitydistribution.C_SELF
)
else:
module.objects[0].center_choice.value = center_choice
module.objects[0].center_object_name.value = CENTER_NAME
center_objects = cellprofiler.object.Objects()
center_objects.segmented = center_labels
object_set.add_objects(center_objects, CENTER_NAME)
module.bin_counts[0].bin_count.value = bin_count
def make_workspace(image, mask):
"""Make a workspace for testing FilterByObjectMeasurement"""
module = cellprofiler.modules.smooth.Smooth()
pipeline = cellprofiler.pipeline.Pipeline()
object_set = cellprofiler.object.ObjectSet()
image_set_list = cellprofiler.image.ImageSetList()
image_set = image_set_list.get_image_set(0)
workspace = cellprofiler.workspace.Workspace(
pipeline,
module,
image_set,
object_set,
cellprofiler.measurement.Measurements(),
image_set_list,
)
image_set.add(INPUT_IMAGE_NAME, cellprofiler.image.Image(image, mask))
module.image_name.value = INPUT_IMAGE_NAME
module.filtered_image_name.value = OUTPUT_IMAGE_NAME
return workspace, module
image = cpi.Image(img, file_name="test_03_01_simple_fitting")
image_set_list = cpi.ImageSetList()
image_set = image_set_list.get_image_set(0)
image_set.providers.append(cpi.VanillaImageProvider(IMAGE_NAME, image))
old_params = ast.literal_eval(x.autoadapted_params.value)
input_processed, background_processed, ignore_mask_processed = x.preprocess_images(img, None, None)
x.fit_parameters(input_processed, background_processed, ignore_mask_processed, label,
x.autoadaptation_steps.value * 2, lambda x: True, lambda secs: time.sleep(secs))
new_params = ast.literal_eval(x.autoadapted_params.value)
self.assertNotEqual(old_params[0], new_params[0])
self.assertNotEqual(old_params[1], new_params[1])
# now if we use new parameters option we should find these cells
object_set = cpo.ObjectSet()
measurements = cpmeas.Measurements()
pipeline = cellprofiler.pipeline.Pipeline()
x.segmentation_precision.value = 11
x.run(Workspace(pipeline, x, image_set, object_set, measurements, None))
objects = object_set.get_objects(OBJECTS_NAME)
self.assertEqual(4, objects.segmented.max())
colours = sorted([objects.segmented[100, 100], objects.segmented[120, 120], objects.segmented[110, 70],
objects.segmented[160, 160]])
self.assertEqual(colours[0], 1)
self.assertEqual(colours[1], 2)
self.assertEqual(colours[2], 3)
self.assertEqual(colours[3], 4)
def test_image_measurement(output_dir):
"""Test writing an image measurement"""
path = os.path.join(output_dir, "my_file.csv")
module = cellprofiler.modules.exporttospreadsheet.ExportToSpreadsheet()
module.set_module_num(1)
module.wants_everything.value = False
module.wants_prefix.value = False
module.object_groups[0].name.value = cellprofiler.measurement.IMAGE
module.object_groups[0].file_name.value = path
module.object_groups[0].wants_automatic_file_name.value = False
m = cellprofiler.measurement.Measurements()
m.add_image_measurement("my_measurement", "Hello, world")
image_set_list = cellprofiler.image.ImageSetList()
image_set = image_set_list.get_image_set(0)
object_set = cellprofiler.object.ObjectSet()
workspace = cellprofiler.workspace.Workspace(
make_measurements_pipeline(m), module, image_set, object_set, m, image_set_list
)
module.post_run(workspace)
fd = open(path, "r")
try:
reader = csv.reader(fd, delimiter=module.delimiter_char)
header = next(reader)
assert len(header) == 2
assert header[0] == "ImageNumber"
assert header[1] == "my_measurement"
row = next(reader)
assert row[0] == "1"
assert row[1] == "Hello, world"
with pytest.raises(StopIteration):
reader.__next__()
fs.file_name.value = filename
fs.image_objects_choice.value = (
cellprofiler.modules.loadsingleimage.IO_OBJECTS
)
fs.objects_name.value = OBJECTS_NAME
fs.wants_outlines.value = True
fs.outlines_name.value = OUTLINES_NAME
pipeline = cellprofiler.pipeline.Pipeline()
def callback(caller, event):
assert not isinstance(event, cellprofiler.pipeline.RunExceptionEvent)
pipeline.add_listener(callback)
pipeline.add_module(module)
m = cellprofiler.measurement.Measurements()
object_set = cellprofiler.object.ObjectSet()
image_set_list = cellprofiler.image.ImageSetList()
image_set = image_set_list.get_image_set(0)
workspace = cellprofiler.workspace.Workspace(
pipeline, module, image_set, object_set, m, image_set_list
)
module.prepare_run(workspace)
module.run(workspace)
outlines = image_set.get_image(OUTLINES_NAME)
numpy.testing.assert_equal(outlines.pixel_data, expected_outlines)
finally:
try:
os.remove(os.path.join(directory, filename))
os.rmdir(directory)
except:
print(("Failed to delete directory " + directory))