diff --git a/napari_skimage_regionprops/_parametric_images.py b/napari_skimage_regionprops/_parametric_images.py index ba696d7..4cdab32 100644 --- a/napari_skimage_regionprops/_parametric_images.py +++ b/napari_skimage_regionprops/_parametric_images.py @@ -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) diff --git a/napari_skimage_regionprops/_table.py b/napari_skimage_regionprops/_table.py index 1ec197f..ad5192e 100644 --- a/napari_skimage_regionprops/_table.py +++ b/napari_skimage_regionprops/_table.py @@ -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"