Skip to content

Commit

Permalink
bugfix: parametric images didn't work with timelapse data
Browse files Browse the repository at this point in the history
  • Loading branch information
haesleinhuepf committed May 5, 2022
1 parent 648ce9c commit 9350db8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions napari_skimage_regionprops/_parametric_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
import numpy

@register_function(menu="Visualization > Measurements on labels (nsr)")
def visualize_measurement_on_labels(labels_layer:"napari.layers.Labels", column:str = "label") -> "napari.types.ImageData":
def visualize_measurement_on_labels(labels_layer:"napari.layers.Labels", column:str = "label", viewer:"napari.Viewer" = None) -> "napari.types.ImageData":
import pandas as pd

labels = labels_layer.data
table = labels_layer.properties
table = pd.DataFrame(labels_layer.properties)

if len(labels.shape) == 4:
current_timepoint = viewer.dims.current_step[0]
labels = labels[current_timepoint]

if "frame" in table.keys():
table = table[table['frame'] == current_timepoint]

measurements = table[column]

if isinstance(measurements, numpy.ndarray):
measurements = measurements.tolist()

try:
import pyclesperanto_prototype as cle; return cle.pull(cle.replace_intensities(labels, numpy.asarray([0] + measurements)))
import pyclesperanto_prototype as cle
return cle.pull(cle.replace_intensities(labels, numpy.asarray([0] + measurements)))
except ImportError:
return relabel_numpy(labels, measurements)

Expand Down
2 changes: 1 addition & 1 deletion napari_skimage_regionprops/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _double_clicked_table(self):
print("Selected column", selected_column)
if selected_column is not None:
from ._parametric_images import visualize_measurement_on_labels
new_layer = self._viewer.add_image(visualize_measurement_on_labels(self._layer, selected_column),
new_layer = self._viewer.add_image(visualize_measurement_on_labels(self._layer, selected_column, self._viewer),
name=selected_column + " in " + self._layer.name)
new_layer.contrast_limits = [np.min(self._table[selected_column]), np.max(self._table[selected_column])]
new_layer.colormap = "jet"
Expand Down

0 comments on commit 9350db8

Please sign in to comment.