Skip to content

Commit

Permalink
Further improve the projections skimage napari implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jun 30, 2024
1 parent e6f514c commit 4d89406
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions _includes/projections/projections_act1_skimage_napari.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@

# %%
# As this is an anisotropic image, we view it scaled
# - Napari: Use 3-D rendering see all the spots
viewer = Viewer()
viewer.add_image(image, scale=scales)

# %%
# Napari:
# - View the image also in 3-D to see all the spots

# %%
# Create and view a maximum projection along z-axis, i.e. axis = 0
# - Observe that this gives a nice "quick overview" of the data content
# - Observe how the maximum gives a nice "quick overview" of the data content
# - In order to see it at the same scale as the original image we need to scale in in x&y
# - Napari: observe that the image layer context menu also allows one to create projections
# - Napari: *Toggle grid mode (Ctrl + G)* to view images side by side
Expand All @@ -37,8 +34,9 @@
# %%
# Compute sum projection along z-axis
# and display it in napari
# - Napari: Observe a current BUG where it does not properly render the sum projection pixel values;
# a workaround will be given later (see below)
# - Napari: There is an an issue rendering the sum projection pixel values:
# some high values appear dark. More details and a possible work-around is given at
# the end of this script.
sum_z_image = np.sum(image, axis=0)
viewer.add_image(sum_z_image, scale=scales[1:3])

Expand All @@ -60,16 +58,17 @@
print("actual max sum in this image:", sum_z_image.max())
print("max sum supported by projection:", np.iinfo(sum_z_image.dtype).max)

# %%
# Optional workaround for the above mentioned BUG:
# Convert sum projection to float to properly visualize it
sum_z_image_float = sum_z_image.astype(float)
viewer.add_image(sum_z_image_float, scale=scales[1:3])

# %%
# Compute maximum projection along x-axis and y-axis
# and show in viewer with correct scaling
max_x_image = np.max(image, axis=2)
max_y_image = np.max(image, axis=1)
viewer.add_image(max_x_image, scale=[scales[0], scales[1]])
viewer.add_image(max_y_image, scale=[scales[0], scales[2]])
viewer.add_image(max_y_image, scale=[scales[0], scales[2]])

# %%
# Optional work-around for the above mentioned issue when rendering
# certain data types (https://github.com/NEUBIAS/training-resources/issues/570)
# Convert sum projection to float to properly visualize it
sum_z_image_float = sum_z_image.astype(float)
viewer.add_image(sum_z_image_float, scale=scales[1:3])

0 comments on commit 4d89406

Please sign in to comment.