Skip to content
Snippets Groups Projects
Commit 449e8420 authored by Kai Schleicher's avatar Kai Schleicher
Browse files

Add and use function to measure shape features

parent 5f9d8db0
Branches
Tags
No related merge requests found
...@@ -349,6 +349,59 @@ def measure_intensity_sum(imp, rm): ...@@ -349,6 +349,59 @@ def measure_intensity_sum(imp, rm):
return label_id, sum_intensity return label_id, sum_intensity
def measure_shape_parameters(imp, rm):
"""
Measure theraw integrated intensity for all rois in target imp.
Parameters
----------
imp : ImagePlus
The image from which the intensity will be measured.
rm : RoiManager
The ROI Manager containing the regions of interest to be analyzed.
Returns
-------
label_id : list of str
A list of labels corresponding to each ROI.
area : list of int
A list of the areas for each ROI.
perimeter : list of int
A list of the perimeters for each ROI.
min_feret : list of int
A list of the min feret diameters for each ROI.
Notes
-----
The results are stored in a `ij.ResultsTable`,
from which the values are extracted.
Example
-------
>>> label_id, area, perimeter, min_feret = measure_shape_parameters(imp, roi_manager)
"""
rt_ = ResultsTable()
options = M.FERET | M.AREA | M.PERIMETER
an = Analyzer (imp, options, rt_)
an.setPrecision(1)
label_id = []
area = []
perimeter = []
min_feret = []
for index, roi in enumerate(rm.getRoisAsArray()):
imp.setRoi(roi)
an.measure()
label_id.append(roi.getName())
area.append(int(rt_.getColumn("Area")[index]))
perimeter.append(int(rt_.getColumn("MinFeret")[index]))
min_feret.append(int(rt_.getColumn("Perim.")[index]))
return label_id, area, perimeter, min_feret
def add_results_to_resultstable(results_table, column, values): def add_results_to_resultstable(results_table, column, values):
"""Add values to the ResultsTable starting from row 0 of a given column. """Add values to the ResultsTable starting from row 0 of a given column.
...@@ -451,6 +504,12 @@ dapi_binary = convert_to_binary(dapi_channel, threshold) ...@@ -451,6 +504,12 @@ dapi_binary = convert_to_binary(dapi_channel, threshold)
# detect spots and count them per fiber # detect spots and count them per fiber
results_table = ResultsTable() results_table = ResultsTable()
load_rois_from_zip(fiber_segmentation_roiset, rm)
fiber_label_IDs, area, perimeter, min_feret = measure_shape_parameters(dapi_binary, rm)
add_results_to_resultstable(results_table, "fiber label ID", fiber_label_IDs)
add_results_to_resultstable(results_table, "Area", area)
add_results_to_resultstable(results_table, "Perimeter", perimeter)
add_results_to_resultstable(results_table, "Min. Feret", min_feret)
for index, channel in enumerate(processing_channels): for index, channel in enumerate(processing_channels):
channel = int(channel) channel = int(channel)
quality_threshold = float(quality_thresholds[index]) quality_threshold = float(quality_thresholds[index])
...@@ -462,7 +521,7 @@ for index, channel in enumerate(processing_channels): ...@@ -462,7 +521,7 @@ for index, channel in enumerate(processing_channels):
dapi_negative_spots_binary = ImageCalculator.run(spots_binary_imp, dapi_positive_spots_binary, "Subtract create") dapi_negative_spots_binary = ImageCalculator.run(spots_binary_imp, dapi_positive_spots_binary, "Subtract create")
load_rois_from_zip(fiber_segmentation_roiset, rm) load_rois_from_zip(fiber_segmentation_roiset, rm)
fiber_label_IDs, n_spots_per_fiber = measure_intensity_sum(spots_binary_imp, rm) _, n_spots_per_fiber = measure_intensity_sum(spots_binary_imp, rm)
_, n_dapi_positive_spots_per_fiber = measure_intensity_sum(dapi_positive_spots_binary, rm) _, n_dapi_positive_spots_per_fiber = measure_intensity_sum(dapi_positive_spots_binary, rm)
_, n_dapi_negative_spots_per_fiber = measure_intensity_sum(dapi_negative_spots_binary, rm) _, n_dapi_negative_spots_per_fiber = measure_intensity_sum(dapi_negative_spots_binary, rm)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment