Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# The parent/child associations
#
for parent_objects_name, parents_of, child_count\
in ((self.primary_objects_name, primary_parents,child_count_of_primary),
(self.secondary_objects_name, secondary_parents, child_count_of_secondary)):
m.add_measurement(self.subregion_objects_name.value,
cpmi.FF_PARENT%(parent_objects_name.value),
parents_of)
m.add_measurement(parent_objects_name.value,
cpmi.FF_CHILDREN_COUNT%(self.subregion_objects_name.value),
child_count)
object_count = np.max(tertiary_labels)
#
# The object count
#
cpmi.add_object_count_measurements(workspace.measurements,
self.subregion_objects_name.value,
object_count)
#
# The object locations
#
cpmi.add_object_location_measurements(workspace.measurements,
self.subregion_objects_name.value,
tertiary_labels)
#
# The outlines
#
if self.use_outlines.value:
out_img = cpi.Image(tertiary_outlines.astype(bool),
parent_image = tertiary_image)
workspace.image_set.add(self.outlines_name.value, out_img)
filtered_objects_name)
#
# Add parent/child & other measurements
#
m = workspace.measurements
child_count, parents = orig_objects.relate_children(filtered_objects)
m.add_measurement(filtered_objects_name,
I.FF_PARENT%(orig_objects_name),
parents)
m.add_measurement(orig_objects_name,
I.FF_CHILDREN_COUNT%(filtered_objects_name),
child_count)
#
# The object count
#
I.add_object_count_measurements(m, filtered_objects_name,
object_count)
#
# The object locations
#
I.add_object_location_measurements(m, filtered_objects_name,
filtered_labels)
#
# Outlines if we want them
#
if self.wants_outlines:
outlines_name = self.outlines_name.value
outlines = outline(filtered_labels)
outlines_image = cpi.Image(outlines.astype(bool))
workspace.image_set.add(outlines_name, outlines_image)
#
# Do the drawing here
I.FF_PARENT % object_name,
parent_objects)
if np.max(original_objects.segmented) == 0:
child_count = np.array([],int)
else:
child_count = fix(scind.sum(labels, original_objects.segmented,
np.arange(1, nobjects+1)))
child_count = (child_count > 0).astype(int)
m.add_measurement(object_name,
I.FF_CHILDREN_COUNT % remaining_object_name,
child_count)
if self.retain_or_renumber == R_RETAIN:
remaining_object_count = nobjects
else:
remaining_object_count = len(unique_labels)
I.add_object_count_measurements(m, remaining_object_name,
remaining_object_count)
I.add_object_location_measurements(m, remaining_object_name, labels)
#
# Add an outline if asked to do so
#
if self.wants_outlines.value:
outline_image = cpi.Image(outline(labels) > 0,
parent_image = original_objects.parent_image)
workspace.image_set.add(self.outlines_name.value, outline_image)
#
# Save the input, mask and output images for display
#
if workspace.frame is not None:
workspace.display_data.original_labels = original_objects.segmented
workspace.display_data.final_labels = labels
workspace.display_data.mask = mask
#
children_per_parent, parents_of_children = \
objects.relate_children(objects_out)
measurements.add_measurement(self.primary_objects.value,
cpmi.FF_CHILDREN_COUNT%objname,
children_per_parent)
measurements.add_measurement(objname,
cpmi.FF_PARENT%self.primary_objects.value,
parents_of_children)
#
# If primary objects were created, add them
#
if self.wants_discard_edge and self.wants_discard_primary:
workspace.object_set.add_objects(new_objects,
self.new_primary_objects_name.value)
cpmi.add_object_count_measurements(measurements,
self.new_primary_objects_name.value,
np.max(new_objects.segmented))
cpmi.add_object_location_measurements(measurements,
self.new_primary_objects_name.value,
new_objects.segmented)
for parent_objects, parent_name, child_objects, child_name in (
(objects, self.primary_objects.value,
new_objects, self.new_primary_objects_name.value),
(new_objects, self.new_primary_objects_name.value,
objects_out, objname)):
children_per_parent, parents_of_children = \
parent_objects.relate_children(child_objects)
measurements.add_measurement(parent_name,
cpmi.FF_CHILDREN_COUNT%child_name,
children_per_parent)
measurements.add_measurement(child_name,
float(total_area))])
statistics.append(["Smoothing filter size",
"%.1f"%(self.calc_smoothing_filter_size())])
statistics.append(["Maxima suppression size",
"%.1f"%(maxima_suppression_size)])
workspace.display_data.image = image
workspace.display_data.labeled_image = labeled_image
workspace.display_data.outline_image = outline_image
workspace.display_data.outline_size_excluded_image = outline_size_excluded_image
workspace.display_data.outline_border_excluded_image = outline_border_excluded_image
workspace.display_data.statistics = statistics
# Add image measurements
objname = self.object_name.value
measurements = workspace.measurements
cpmi.add_object_count_measurements(measurements,
objname, object_count)
self.add_threshold_measurements(measurements, img, mask,
local_threshold, global_threshold,
self.object_name.value)
# Add label matrices to the object set
objects = cellprofiler.objects.Objects()
objects.segmented = labeled_image
objects.unedited_segmented = unedited_labels
objects.small_removed_segmented = small_removed_labels
objects.parent_image = image
workspace.object_set.add_objects(objects,self.object_name.value)
cpmi.add_object_location_measurements(workspace.measurements,
self.object_name.value,
labeled_image)
if self.should_save_outlines.value:
cpmi.FF_FINAL_THRESHOLD%(objname),
np.array([ave_threshold],
dtype=float))
measurements.add_measurement(cpmeas.IMAGE,
cpmi.FF_ORIG_THRESHOLD%(objname),
np.array([global_threshold],
dtype=float))
wv = cpthresh.weighted_variance(img, mask, local_threshold)
measurements.add_measurement(cpmeas.IMAGE,
cpmi.FF_WEIGHTED_VARIANCE%(objname),
np.array([wv],dtype=float))
entropies = cpthresh.sum_of_entropies(img, mask, local_threshold)
measurements.add_measurement(cpmeas.IMAGE,
cpmi.FF_SUM_OF_ENTROPIES%(objname),
np.array([entropies],dtype=float))
cpmi.add_object_count_measurements(measurements, objname, object_count)
cpmi.add_object_location_measurements(measurements, objname,
segmented_out)
#
# Relate the secondary objects to the primary ones and record
# the relationship.
#
children_per_parent, parents_of_children = \
objects.relate_children(objects_out)
measurements.add_measurement(self.primary_objects.value,
cpmi.FF_CHILDREN_COUNT%objname,
children_per_parent)
measurements.add_measurement(objname,
cpmi.FF_PARENT%self.primary_objects.value,
parents_of_children)
#
# If primary objects were created, add them
labels = np.zeros(pixel_data.shape[:2], int)
self.do_ui(workspace, pixel_data, labels)
objects = cpo.Objects()
objects.segmented = labels
workspace.object_set.add_objects(objects, objects_name)
##################
#
# Add measurements
#
m = workspace.measurements
#
# The object count
#
object_count = np.max(labels)
I.add_object_count_measurements(m, objects_name, object_count)
#
# The object locations
#
I.add_object_location_measurements(m, objects_name, labels)
#
# Outlines if we want them
#
if self.wants_outlines:
outlines_name = self.outlines_name.value
outlines = outline(labels)
outlines_image = cpi.Image(outlines.astype(bool))
workspace.image_set.add(outlines_name, outlines_image)
#
# Do the drawing here
#
if workspace.frame is not None: