Skip to content

Commit

Permalink
Merge pull request #65 from zoccoler/compute_pixel_coords_chunck_sizes
Browse files Browse the repository at this point in the history
compute pixel coords chunck sizes (fix dask Error)
  • Loading branch information
zoccoler authored Aug 14, 2024
2 parents 54b49f8 + 7201748 commit 6fe4149
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ Alternatively, clone this repository and install the latest plugin development v

pip install git+https://github.com/zoccoler/napari-flim-phasor-plotter.git

_Optional, but we **strongly** recommend having the `devbio-napari` plugin bundle also installed for post-processing. This can be done with:_

mamba install -c conda-forge devbio-napari=0.10.0 scikit-image=0.24.0

## Usage

### Loading Raw FLIM Data
Expand Down Expand Up @@ -157,7 +153,7 @@ A common step is to select a single cluster of interest for further processing.

To connect small isolated regions and remove small holes within the mask, we can use the `smooth_cluster_mask` function. This can be accessed via `Plugins -> FLIM phasor plotter -> Smooth Cluster Mask`. This will remove holes with an area smaller than the specified `fill area px` in total number of pixels and connect regions within a given `smooth radius`. Don't forget to select the layer containing the mask before running the function, because this function expects a layer with a single label (like a binary mask).

Beyond this point, we can use other plugins, like the `devbio-napari` plugin bundle, to further process the mask. For example, we can perform instance segmentation on the mask via `Tools -> Segmentation / labeling -> Connectec component labeling (scikit-image, nsbatwm)`. We can also extract features from the objects via `Tools -> Measurement tables -> Objetct Features/Properties (scikit-image, nsr)`.
Beyond this point, we can use other plugins, like the `napari-segment-blobs-and-things-with-membranes` and `napari-skimage-regionprops` plugins, to further process the mask. For example, we can perform instance segmentation on the mask via `Tools -> Segmentation / labeling -> Connectec component labeling (scikit-image, nsbatwm)`. We can also extract features from the objects via `Tools -> Measurement tables -> Objetct Features/Properties (scikit-image, nsr)`.

Below is a demonstration of the post-processing steps:

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ install_requires =
magicgui
qtpy
napari>=0.4.19
napari-clusters-plotter>=0.8.0
napari-clusters-plotter>=0.8.1
ptufile
sdtfile
natsort
Expand Down
2 changes: 1 addition & 1 deletion src/napari_flim_phasor_plotter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1.1"
__version__ = "0.1.2"

from ._reader import napari_get_reader
from ._sample_data import load_seminal_receptacle_image, load_hazelnut_image, load_hazelnut_z_stack, load_lifetime_cat_synthtetic_single_image
Expand Down
27 changes: 20 additions & 7 deletions src/napari_flim_phasor_plotter/_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from magicgui import magic_factory
from magicgui.widgets import Container, PushButton, ComboBox, SpinBox
from typing import List
from importlib.metadata import version

if TYPE_CHECKING:
import napari
import pandas

napari_version = tuple(map(int, list(version("napari").split(".")[:2])))

def connect_events(widget):
'''
Expand Down Expand Up @@ -90,11 +92,16 @@ def make_flim_phasor_plot(image_layer: "napari.layers.Image",

g_flat_masked = np.ravel(g[space_mask])
s_flat_masked = np.ravel(s[space_mask])
t_coords, z_coords, y_coords, x_coords = np.where(space_mask)
if isinstance(g, da.Array):
g_flat_masked.compute_chunk_sizes()
s_flat_masked.compute_chunk_sizes()
if isinstance(space_mask, da.Array):
t_coords.compute_chunk_sizes()
z_coords.compute_chunk_sizes()
y_coords.compute_chunk_sizes()
x_coords.compute_chunk_sizes()

t_coords, z_coords, y_coords, x_coords = np.where(space_mask)
phasor_components = pd.DataFrame({
'label': np.ravel(label_image[space_mask]),
'G': g_flat_masked,
Expand Down Expand Up @@ -233,10 +240,13 @@ def manual_label_extract(cluster_labels_layer: "napari.layers.Labels", label_num
unitary_dims = [i for i, size in enumerate(np.asarray(cluster_labels_layer.data).shape) if size == 1]
labels_data = np.squeeze(np.asarray(cluster_labels_layer.data).copy())
labels_data[labels_data != label_number] = 0
# TODO: update to use DirectLabelColormap once napari-clusters-plotter has this issue fixed
label_color = cluster_labels_layer.color
if napari_version >= (0, 5):
colormap = cluster_labels_layer.colormap
else:
label_color = cluster_labels_layer.color
colormap = DirectLabelColormap(color_dict=label_color)
new_scale = np.array([scale for i, scale in enumerate(cluster_labels_layer.scale) if i not in unitary_dims])
return Labels(labels_data, colormap=DirectLabelColormap(color_dict=label_color), name=f'Cluster Label #{label_number}', scale=new_scale)
return Labels(labels_data, colormap=colormap, name=f'Cluster Label #{label_number}', scale=new_scale)

def get_n_largest_cluster_labels(features_table: 'pandas.DataFrame', n: int=1, clustering_id: str='MANUAL_CLUSTER_ID') -> List[int]:
"""Get the labels of the n largest clusters in a features table
Expand Down Expand Up @@ -419,7 +429,10 @@ def smooth_cluster_mask(cluster_mask_layer: "napari.layers.Labels", fill_area_px
labels_data = morphology.isotropic_opening(labels_data, smooth_radius)
# Restore label number
labels_data = labels_data.astype(cluster_mask_layer.data.dtype)*cluster_mask_layer.data.max()
# TODO: update to use DirectLabelColormap once napari-clusters-plotter has this issue fixed
label_color = cluster_mask_layer.color
if napari_version >= (0, 5):
colormap = cluster_mask_layer.colormap
else:
label_color = cluster_mask_layer.color
colormap = DirectLabelColormap(color_dict=label_color)
new_scale = np.array([scale for i, scale in enumerate(cluster_mask_layer.scale) if i not in unitary_dims])
return Labels(labels_data, colormap=DirectLabelColormap(color_dict=label_color), scale=new_scale, name=cluster_mask_layer.name + ' smoothed')
return Labels(labels_data, colormap=colormap, scale=new_scale, name=cluster_mask_layer.name + ' smoothed')

0 comments on commit 6fe4149

Please sign in to comment.