Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates to python activities on multiscale and spatial calibration #656

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# %% [markdown]
# ## Explore a 3D image
# %%
# Explore a 3D image

# %%
# Load the image
# Imports
from OpenIJTIFF import open_ij_tiff
from napari.viewer import Viewer

# %%
# Load the image
image, axes, scales, units = open_ij_tiff("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyz_8bit__chromosomes.tif")

# View the image in napari
from napari.viewer import Viewer
napari_viewer = Viewer()
napari_viewer.add_image(image)

# %% [markdown]
# **Napari GUI** Explore different sliders and values in the bottom left part \
# **Napari GUI** Show in 3D. Note that the scalings are not yet correct.
# [markdown]
# Napari GUI: Explore different sliders and values in the bottom left part.
# Napari GUI: Show in 3D. Note that the scalings are not yet correct.

# %%
# Print image axes metadata
Expand All @@ -23,8 +26,8 @@
print("Units: ", units)

# %%
# Add image with scaling.
napari_viewer.add_image(image, name = "Scaled image", scale = scales)
# Add image with scaling.
napari_viewer.add_image(image, name = "Scaled image", scale = scales)

# %% [markdown]
# **Napari GUI** View scaled image in 3D. Note that the scaling is now correct.
# %%
# Napari GUI: View scaled image in 3D. Note that the scaling is now correct.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# %% [markdown]
# %%
# ## Explore a 3D multi-channel image

# %%
# Load the image
# Imports
from OpenIJTIFF import open_ij_tiff
from napari.viewer import Viewer

# %%
# Load the image
image, axes, scales, units = open_ij_tiff("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyzc_8bit_beads_p_open.tif")

# %%
Expand All @@ -15,13 +19,12 @@

# %%
# View the image
from napari.viewer import Viewer
napari_viewer = Viewer()
napari_viewer.add_image(image, scale = scales)

# %% [markdown]
# **Napari GUI** Explore different sliders and values in the bottom left part \
# **Napari GUI** Delete the image
# %%
# Napari GUI: Explore different sliders and values in the bottom left part.
# Napari GUI: Delete the image.

# %%
# Create images as separate channels
Expand All @@ -41,5 +44,5 @@
napari_viewer.add_image(image_ch0, name = 'Ch0_ns', colormap = 'magenta')
napari_viewer.add_image(image_ch1, name = 'Ch1_ns', colormap = 'green', blending='additive')

# %% [markdown]
# **Napari GUI** Explore different blending modes and LUTs
# %%
# Napari GUI: Explore different blending modes and LUTs.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# %% [markdown]
# ## Inspect a 3D time-lapse image
# %%
# Inspect a 3D time-lapse image

# %%
# Load the image
# Imports
from OpenIJTIFF import open_ij_tiff
from napari.viewer import Viewer

# %%
# Load the image
image, axes, scales, units = open_ij_tiff("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyzt_8bit__starfish_chromosomes.tif")

# %%
Expand All @@ -15,10 +19,9 @@

# %%
# View the image
from napari.viewer import Viewer
napari_viewer = Viewer()
napari_viewer.add_image(image, scale = scales)

# %% [markdown]
# **Napari GUI** Explore different axes sliders and values in the bottom left part \
# **Napari GUI** Show in 3D.
# %%
# Napari GUI: Explore different axes sliders and values in the bottom left part.
# Napari GUI: Show in 3D.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# %% [markdown]
# ## Explore a 5D image (3D image + channels + time)
# %%
# Explore a 5D image (3D image + channels + time)

# %%
# Load the image
# Imports
from OpenIJTIFF import open_ij_tiff
from napari.viewer import Viewer
import numpy as np

# %%
# Load the image
image, axes, scales, units = open_ij_tiff("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyzct_16bit__metaphase_eb3_cenpa.tif")

# %%
Expand All @@ -15,14 +20,14 @@

# %%
# Display image in napari
from napari.viewer import Viewer
napari_viewer = Viewer()
napari_viewer.add_image(image, scale = scales)

# %% [markdown]
# **Napari GUI** Explore different sliders and values in the bottom left part \
# **Napari GUI** Show in 3D. Note that the order of axes is not yet correct.\ Napari expects that the last 3 dimension are ZYX\
# **Napari GUI** Delete image
# %%
# Napari GUI: Explore different sliders and values in the bottom left part.
# Napari GUI: Show in 3D. Note that the order of axes is not yet correct.
# Napari expects that the last 3 dimension are ZYX.
# Napari GUI: Delete image.

# %%
# Remove channel from scale
Expand All @@ -36,23 +41,22 @@
napari_viewer.add_image(image[:,:,0,:,:], scale = scales_tzyx, name = 'Ch0', colormap = 'magenta')
napari_viewer.add_image(image[:,:,1,:,:], scale = scales_tzyx, name = 'Ch1', colormap = 'green', blending='additive')

# %% [markdown]
# **Napari GUI** Explore different sliders and values in the bottom left part \
# **Napari GUI** delete image and try direct loading
# %%
# Napari GUI: Explore different sliders and values in the bottom left part.
# Napari GUI: delete image and try direct loading.

# %%
# View image as separate channels in one step
napari_viewer.add_image(image, channel_axis = 2, scale = scales_tzyx, name = ['Ch0', 'Ch1'])

# %% [markdown]
# **Napari GUI** delete image
# %%
# Napari GUI: delete image.

# %%
# Loading with numpy transpose
import numpy as np
image_transpose = np.transpose(image, (2, 0, 1, 3, 4))
scales_transpose = [scales[2],scales[0],scales[1],scales[3],scales[4]]
napari_viewer.add_image(image_transpose, scale = scales_transpose)

# %% [markdown]
# **Napari GUI** Right mouse click on image and `split stack`. This will generate visible two channels
# %%
# Napari GUI: Right mouse click on image and `split stack`. This will generate visible two channels.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# %% [markdown]
# ## Spatial image calibration
# #### Requirements
# - [skimage and napari](https://neubias.github.io/training-resources/tool_installation/index.html#skimage_napari)
# %%
# Spatial image calibration

# %%
# Import python packages.
Expand All @@ -27,15 +25,15 @@
napari_viewer = Viewer()
napari_viewer.add_image(image, scale=voxel_size)

# %% [markdown]
# **Napari GUI**: Change the axes order using the corresponding button. \
# **Napari GUI**: Use the 3D viewer button to render the image in 3D.
# %%
# Napari GUI: Change the viewer dimension order using the corresponding button.
# Napari GUI: Use the 3D viewer button to render the image in 3D.

# %% [markdown]
# ### Compute distances between points
# %%
# Compute distances between points
#
# **Napari GUI** use the `New points layer button` to create a new points layer \
# **Napari GUI** use `Add points` to add two points somewhere on the meta-phase plate \
# Napari GUI: use the `New points layer button` to create a new points layer.
# Napari GUI: use `Add points` to add two points somewhere on the meta-phase plate.

# %%
# extract point coordinates
Expand All @@ -51,7 +49,7 @@
print("Voxel size: ", voxel_size)

# %%
points_cal = points * scale
points_cal = points * scale
print("Points :\n", points)
print("Calibrated points :\n", points_cal)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# %% [markdown]
# ## Spatial image calibration
# #### Requirements
# - [skimage and napari](https://neubias.github.io/training-resources/tool_installation/index.html#skimage_napari)
# %%
# Spatial image calibration

# %%
# Import python packages.
import os
from OpenIJTIFF import open_ij_tiff, save_ij_tiff
import numpy as np
from napari.viewer import Viewer
import numpy as np

# %%
# Open a 2D image and its axes metadata
Expand Down Expand Up @@ -39,9 +37,9 @@
# %%
# Note that the 3D image does not have calibrated metadata.
# Let's add spatial calibration using the x&y voxel_size from the 2D image
# and also add a z scaling
# and also add a z scaling
voxel_size_image_3D = [0.52, voxel_size_image_2D[1], voxel_size_image_2D[0]]
units_image_3D = ["um","um","um"]
units_image_3D = ["um", "um", "um"]

# %%
# Inspect the metadata for the 3D image
Expand All @@ -51,13 +49,11 @@
print("Units: ", units_image_3D)

# %%
# Open napari and add the images with their voxel sizes as scaling
# Open napari and add the 3D image with voxel_size
napari_viewer = Viewer()
napari_viewer.add_image(image_2D, scale=voxel_size_image_2D, name='image_2D')
napari_viewer.add_image(image_3D, scale=voxel_size_image_3D, name='image_3D')

# %% [markdown]
# Napari GUI: Change the axes order using the corresponding button. \
# %%
# Napari GUI: Use the 3D viewer button to render the image in 3D.

# %%
Expand All @@ -73,3 +69,21 @@

# %%
# Open the above file in FIJI and verify image scales were properly saved.

# %%
# Measure the length of the nucleus (as exercise)
# Napari GUI: use the `New points layer button` to create a new points layer.
# Napari GUI: use `Add points` to add two points along the longest axis

# %%
# points = napari_viewer.layers['Points'].data
# scale = napari_viewer.layers['Points'].scale
# points_cal = points * scale
# print("Points :\n", points)
# print("Calibrated points :\n", points_cal)

# %%
# diff_vector = points_cal[1] - points_cal[0]
# sqr_diff_vector = diff_vector ** 2
# distance = np.sqrt(sqr_diff_vector.sum())
# print('Distance:', distance)
Loading