# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] slideshow={"slide_type": "slide"}
# # Insights into Microscopy Images

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Learning Objectives
#
# * Learn how to **run** cells in **a Jupyter Notebook**
# * Run a segmentation example that demonstrates **ITK**'s ability to provide **insight into images**
# * Understand the **purpose and capabilities** of the toolkit

# + [markdown] slideshow={"slide_type": "slide"}
# ## Jupyter Notebooks

# + [markdown] slideshow={"slide_type": "subslide"}
# These are [Jupyter Notebooks](https://jupyter.org/), an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text.
#
# To run cells in the notebook, press *shift + enter*.
#
# For more information, see the [Notebook Help](https://nbviewer.jupyter.org/github/ipython/ipython/blob/3.x/examples/Notebook/Index.ipynb)

# + [markdown] slideshow={"slide_type": "slide"}
# ## What is in my image?

# + slideshow={"slide_type": "slide"}
import itk

image = itk.imread('data/6001240.tif')

# +
from itkwidgets import view

view(image, gradient_opacity=0.5)
# -

# - Data source: https://doi.org/10.17867/10000125
# - Article: https://doi.org/10.1371/journal.pbio.3000388
# - Link: https://idr.openmicroscopy.org/webclient/?show=image-6001240
# - Organism:	Mus musculus
# - Study Title:	NesSys: a new set of tools for the automated detection of nuclei within intact tissues and dense 3D cultures
# - Imaging Method:	confocal microscopy
# - Publication Title:	NesSys: a novel method for accurate nuclear segmentation in 3D
# - Publication Authors:	<NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>
# - Protocol 1:	growth protocol - Mouse blastocysts (E3.5)
# - Protocol 2:	Immunostaining: LaminB1 antibody: ab16048 (dilution 1:1000).
# - Protocol 3:	Imaged with an Sp8 leica confocal microscope and HC PL APO 40x/1.30 Oil CS2 objective. Nuclear features were extracted in PickCells using manually segmented nuclei in Nessys editor.

# + [markdown] slideshow={"slide_type": "slide"}
# ## Can I reduce the noise?

# + slideshow={"slide_type": "fragment"}
import numpy as np

image_float = image.astype(np.float32)

denoised = itk.curvature_flow_image_filter(image_float,
                                           number_of_iterations=10)
denoised = itk.median_image_filter(denoised,
                                   radius=1)
denoised = itk.smoothing_recursive_gaussian_image_filter(denoised,
                                   sigma=0.5)

view(denoised, gradient_opacity=0.5)

# + [markdown] slideshow={"slide_type": "slide"}
# ## History of ITK

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Insight into Images
#
# ![Visible Human Head Rendering](data/VisibleHumanHeadRender.png)
#
# http://itk.org

# + [markdown] slideshow={"slide_type": "subslide"}
# ### History
#
# In 1999, the US National Institute of Health’s (NIH) National Library of Medicine (NLM) started a project to support the Visible Human Project.
#
# ![Visible Human Logo](data/VisibleHumanLogo.png)
#
# ![Visible Human Slice](data/VisibleHumanSlice.png)
#

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Goals
#
# * Collect best-of-the-best image analysis algorithms for reproducible science.
# * Provide a software resource for teaching medical image analysis algorithms.
# * Establish a foundation for future research.
# * Support commercial applications.
# * Create conventions for future work.
# * Grow a self-sustaining community of software users and developers.

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Continued Development
#
# * Development has progressed since 1999
# * Contributions from over 300 developers
# * Over 1.7 million lines of code
#
# ![ITK contributors](data/itk-contributors.png)
#
# ITK contributors locations for the 4.8 and 4.9 releases.

# + [markdown] slideshow={"slide_type": "slide"}
# ## Features

# + [markdown] slideshow={"slide_type": "subslide"}
# ### N-Dimensional Image Filtering
#
# ![Filtering](data/Filtering.png)

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Filtering Algorithms Classes
#
# * Fast marching methods
# * Convolution
# * Image gradient
# * Denoising
# * Thresholding
# * Mathematical morphology
# * Smoothing
# * Image features
# * Image statistics
# * Bias correction
# * Image grid operations
# * ....

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Segmentation
#
# "Image segmentation is the process of partitioning a digital image into multiple segments, i.e. sets of pixels. The goal of segmentation is to simplify and/or change the representation of an image into something that is more meaningful and easier to analyze."
#
# Source: [Wikipedia](https://en.wikipedia.org/wiki/Image_segmentation)

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Segmentation
#
# ![Segmentation](data/SegmentationLevelSet.png)

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Segmentation
#
# ![Segmentation](data/Segmentation2.png)

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Registration
#
# "Image registration is the process of transforming different sets of data into one coordinate system. [...] Registration is necessary in order to be able to compare or integrate the data obtained from these different measurements."
#
# Source: [Wikipedia](https://en.wikipedia.org/wiki/Image_registration)

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Registration
#
# ![Registration](data/Registration.png)

# +
image_da = itk.xarray_from_image(image)

image_da

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Other Data Structures
#
# * Mesh's
# * Transforms's
# * SpatialObject's
# * Path's
# * LabelMap's
#
# ![Mesh](data/Mesh.png)
#
# ![Transform](data/Transformation.png)

# + [markdown] slideshow={"slide_type": "subslide"}
# ### ITK Resources
#
# * [ITK Python Quick Start Guide](https://itkpythonpackage.readthedocs.io/en/master/Quick_start_guide.html)
#
# * [Sphinx Examples](https://www.itk.org/ITKExamples)
#
# * [napari](https://napari.org/) - [conversion](https://pypi.org/project/itk_napari_conversion/), [io](https://pypi.org/project/napari-itk-io/), [registration](https://pypi.org/project/elastix-napari/)
#
# * [ITK Software Guide](https://www.itk.org/ItkSoftwareGuide.pdf)
#
# * [ITK Discourse Discussion](https://discourse.itk.org)
#
# * [Insight Software Consortium - NumFOCUS Sponsored Project](https://www.insightsoftwareconsortium.org/)
#
# * [Kitware - Commercial Support](https://www.kitware.com/)

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Enjoy ITK!

StarcoderdataJupyterScriptsDedupFiltered