Skip to content

Commit

Permalink
Implement 12 bit saturation activity for datatypes module
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jun 30, 2024
1 parent 345476a commit c6d11b1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
30 changes: 24 additions & 6 deletions _includes/datatypes/inspect_12bit_saturation_skimage_napari.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import matplotlib.pyplot as plt
from OpenIJTIFF import open_ij_tiff

viewer = napari.Viewer()

# %%
# Open an image and view it
# Open an image and view it in napari
image, *_ = open_ij_tiff('https://github.com/NEUBIAS/training-resources/raw/master/image_data/xy_12bit__saturated_plant.tif')
viewer = napari.Viewer()
viewer.add_image(image)

# %%
# Napari:
# - Hover with the mouse to look for saturation

# %%
# Check the image's datatype
print(image.dtype)
Expand All @@ -27,6 +30,21 @@
# - Important algorithms, e.g. for spot detection, do not work well in regions with intensity clipping
print("Min:", image.min()) # Are there any clipped pixels?
print("Max:", image.max()) # Are there any clipped pixels?
print("Number of 0 pixels:", np.sum(image==0)) # How many clipped pixels are there?
print("Number of 255 pixels:", np.sum(image==255))
plt.hist(image.flatten(), bins=np.arange(image.min(), image.max() + 1));

# %%
# Compute the maximal value of various data types,
# and observe that, suspiciously, our image's maximum value
# matches that of a 12-bit image
print("8 bit max:", 2**8-1)
print("12 bit max:", 2**12-1)
print("16 bit max:", 2**16-1)

# %%
# Check how many satured pixels we have
print("Number of 4095 pixels:", np.sum(image==4095))

# %%
# To double check that this really is a 12 bit image
# you can try to inspect the image metadata
# - If you open the image in Fiji you can do: Image > Show Info
# - TODO: find out how to do this in python
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
print("Max:", image.max()) # Are there any clipped pixels?
print("Number of 0 pixels:", np.sum(image==0)) # How many clipped pixels are there?
print("Number of 255 pixels:", np.sum(image==255))
plt.hist(image.flatten(), bins=np.arange(image.min(), image.max() + 1));
plt.hist(image.flatten(), bins=np.arange(image.min(), image.max() + 1));
2 changes: 2 additions & 0 deletions courses/2024_07_IDIP-Heidelberg_skimage_napari_beginners.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ The first day is an onboarding day to bring everyone to the same level on basic
- Felix Schneider
1. [Spatial image calibration](https://neubias.github.io/training-resources/spatial_calibration/index.html)
- Christian Tischer
- [8 bit saturation]()
- [12 bit saturation]()
1. [N-dimensional images](https://neubias.github.io/training-resources/multidimensional_image_basics/index.html)
- Arif Khan
1. [Image data types](https://neubias.github.io/training-resources/datatypes/index.html)
Expand Down

0 comments on commit c6d11b1

Please sign in to comment.