Skip to content

Commit

Permalink
update example notebooks
Browse files Browse the repository at this point in the history
- update argument from measure_labels_in_labels from 'labels_to_mearue' to 'label_image_other_channel'
- sort output of merge_measurements_to_reference by reference label column
  • Loading branch information
zoccoler committed Mar 13, 2023
1 parent d18cc3c commit 321b671
Show file tree
Hide file tree
Showing 6 changed files with 1,940 additions and 1,928 deletions.
1,471 changes: 1,471 additions & 0 deletions demo/measure_relationship_to_other_channels_functions.ipynb

Large diffs are not rendered by default.

429 changes: 429 additions & 0 deletions demo/measure_relationship_to_other_channels_plugin.ipynb

Large diffs are not rendered by default.

1,471 changes: 0 additions & 1,471 deletions demo/measure_things_inside_things_functions.ipynb

This file was deleted.

418 changes: 0 additions & 418 deletions demo/measure_things_inside_things_plugin.ipynb

This file was deleted.

78 changes: 39 additions & 39 deletions napari_skimage_regionprops/_multichannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def regionprops_measure_relationship_to_other_channels(
if new_suffix not in suffixes:
suffixes.append(new_suffix)
else:
# labels_to_measure layer is a duplicated reference
# label_image_other_channel layer is a duplicated reference
n_leading_zeros = len(label_images_other_channels) // 10
suffixes.append(new_suffix + str(i+1).zfill(1+n_leading_zeros))
# Ensures proper iterable inputs
Expand Down Expand Up @@ -340,7 +340,7 @@ def regionprops_measure_relationship_to_other_channels(
if intensity == False:
table = measure_labels_in_labels(
label_image_reference=label_image_reference,
labels_to_measure=label_images_other_channels,
label_image_other_channel=label_images_other_channels,
size=size,
perimeter=perimeter,
shape=shape,
Expand All @@ -362,9 +362,9 @@ def regionprops_measure_relationship_to_other_channels(
return
table = measure_labels_in_labels_with_intensity(
label_image_reference=label_image_reference,
labels_to_measure=label_images_other_channels,
label_image_other_channel=label_images_other_channels,
intensity_image_reference=intensity_image_reference,
intensity_image_of_labels_to_measure=intensity_images_other_channels,
intensity_image_other_channel=intensity_images_other_channels,
size=size, perimeter=perimeter,
shape=shape, position=position,
moments=moments,
Expand All @@ -391,7 +391,7 @@ def regionprops_measure_relationship_to_other_channels(


def link_two_label_images(label_image_reference: "napari.types.LabelsData",
labels_to_measure: "napari.types.LabelsData",
label_image_other_channel: "napari.types.LabelsData",
intersection_over_target_obj_area: float = 0.5
) -> "pandas.DataFrame":
"""
Expand All @@ -406,7 +406,7 @@ def link_two_label_images(label_image_reference: "napari.types.LabelsData",
----------
label_image_reference : napari.types.LabelsData
a label image to be used as reference labels.
labels_to_measure : napari.types.LabelsData
label_image_other_channel : napari.types.LabelsData
a label image to be used as target labels.
intersection_over_target_obj_area : float, optional
an area ratio threshold value that determines if a label in
Expand Down Expand Up @@ -480,7 +480,7 @@ def highest_overlap(regionmask, label_image_reference,

# Create table that links labels from scanning channel to reference channel
table_linking_labels = pd.DataFrame(
sk_regionprops_table(label_image=np.asarray(labels_to_measure).astype(int),
sk_regionprops_table(label_image=np.asarray(label_image_other_channel).astype(int),
intensity_image=np.asarray(label_image_reference).astype(int),
properties=['label', ],
extra_properties=[highest_overlap]
Expand Down Expand Up @@ -622,7 +622,7 @@ def measure_labels_with_intensity(


def measure_labels_in_labels(label_image_reference: "napari.types.LabelsData",
labels_to_measure: List["napari.types.LabelsData"],
label_image_other_channel: List["napari.types.LabelsData"],
size: bool = True,
perimeter: bool = False,
shape: bool = False,
Expand All @@ -639,13 +639,13 @@ def measure_labels_in_labels(label_image_reference: "napari.types.LabelsData",
one or more target label images. It returns a table
where each column is a feature and each row associates
a label (and its features) from `label_image_reference`
to a target label (and its features) from `labels_to_measure`.
to a target label (and its features) from `label_image_other_channel`.
Parameters
----------
label_image_reference : napari.types.LabelsData
a reference label image to measure features.
labels_to_measure : List[napari.types.LabelsData]
label_image_other_channel : List[napari.types.LabelsData]
a list of target label images to measure features.
size : bool, optional
measure size related features.
Expand Down Expand Up @@ -698,14 +698,14 @@ def measure_labels_in_labels(label_image_reference: "napari.types.LabelsData",
)
list_table_linking_labels = []
list_table_other_channel_labels_properties = []
# Make labels_to_measure iterable
if not isinstance(labels_to_measure, list):
labels_to_measure = [labels_to_measure]
# Link each labels_to_measure image to reference and get their properties
for label_image in labels_to_measure:
# Make label_image_other_channel iterable
if not isinstance(label_image_other_channel, list):
label_image_other_channel = [label_image_other_channel]
# Link each label_image_other_channel image to reference and get their properties
for label_image in label_image_other_channel:
table_linking_labels = link_two_label_images(
label_image_reference=label_image_reference,
labels_to_measure=label_image,
label_image_other_channel=label_image,
intersection_over_target_obj_area=intersection_over_target_obj_area
)
list_table_linking_labels.append(table_linking_labels)
Expand Down Expand Up @@ -734,9 +734,9 @@ def measure_labels_in_labels(label_image_reference: "napari.types.LabelsData",

def measure_labels_in_labels_with_intensity(
label_image_reference: "napari.types.LabelsData",
labels_to_measure: List["napari.types.LabelsData"],
label_image_other_channel: List["napari.types.LabelsData"],
intensity_image_reference: "napari.types.ImageData",
intensity_image_of_labels_to_measure: List["napari.types.ImageData"] = None,
intensity_image_other_channel: List["napari.types.ImageData"] = None,
size: bool = True,
perimeter: bool = False,
shape: bool = False,
Expand All @@ -754,17 +754,17 @@ def measure_labels_in_labels_with_intensity(
images. It returns a table
where each column is a feature and each row associates
a label (and its features) from `label_image_reference`
to a target label (and its features) from `labels_to_measure`.
to a target label (and its features) from `label_image_other_channel`.
Parameters
----------
label_image_reference : napari.types.LabelsData
a reference label image to measure features.
labels_to_measure : List[napari.types.LabelsData], array_like
label_image_other_channel : List[napari.types.LabelsData], array_like
a list of target label images to measure features.
intensity_image_reference : napari.types.ImageData, array_like
a reference intensity image to measure intensity features.
intensity_image_of_labels_to_measure : List[napari.types.ImageData],
intensity_image_other_channel : List[napari.types.ImageData],
array_like, optional
a list of target intensity images to measure intensity features.
If None (default), intensity features are extracted from
Expand Down Expand Up @@ -821,31 +821,31 @@ def measure_labels_in_labels_with_intensity(
)
list_table_linking_labels = []
list_table_other_channel_labels_properties = []
# Make labels_to_measure iterable
if not isinstance(labels_to_measure, list):
labels_to_measure = [labels_to_measure]
# If no intensity_image_of_labels_to_measure provided, use reference
# Make label_image_other_channel iterable
if not isinstance(label_image_other_channel, list):
label_image_other_channel = [label_image_other_channel]
# If no intensity_image_other_channel provided, use reference
# intensity
if intensity_image_of_labels_to_measure is None:
intensity_image_of_labels_to_measure = [intensity_image_reference] * \
len(labels_to_measure)
# If intensity_image_of_labels_to_measure provided, check if sizes match
if intensity_image_other_channel is None:
intensity_image_other_channel = [intensity_image_reference] * \
len(label_image_other_channel)
# If intensity_image_other_channel provided, check if sizes match
else:
# Make intensity_image_of_labels_to_measure iterable
if not isinstance(intensity_image_of_labels_to_measure, list):
intensity_image_of_labels_to_measure = \
[intensity_image_of_labels_to_measure]
if len(intensity_image_of_labels_to_measure) != len(labels_to_measure):
print(('Error! Length of intensity_image_of_labels_to_measure and'
'labels_to_measure must match.'))
# Make intensity_image_other_channel iterable
if not isinstance(intensity_image_other_channel, list):
intensity_image_other_channel = \
[intensity_image_other_channel]
if len(intensity_image_other_channel) != len(label_image_other_channel):
print(('Error! Length of intensity_image_other_channel and'
'label_image_other_channel must match.'))
return

# Link each labels_to_measure image to reference and get their properties
# Link each label_image_other_channel image to reference and get their properties
for label_image, intensity_image in zip(
labels_to_measure, intensity_image_of_labels_to_measure):
label_image_other_channel, intensity_image_other_channel):
table_linking_labels = link_two_label_images(
label_image_reference=label_image_reference,
labels_to_measure=label_image,
label_image_other_channel=label_image,
intersection_over_target_obj_area=intersection_over_target_obj_area
)
list_table_linking_labels.append(table_linking_labels)
Expand Down
1 change: 1 addition & 0 deletions napari_skimage_regionprops/_process_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def merge_measurements_to_reference(
for column in output_table.columns:
if column.startswith('label'):
output_table[column] = output_table[column].astype(int)
output_table = output_table.sort_values(by='label' + suffixes[0])
# Append output table to list (each table may have different shapes)
output_table_list.append(output_table)
return output_table_list
Expand Down

0 comments on commit 321b671

Please sign in to comment.