-
Notifications
You must be signed in to change notification settings - Fork 23
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
ome zarr notebook #311
Draft
thewtex
wants to merge
2
commits into
main
Choose a base branch
from
ome-zarr-notebook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+311
−3
Draft
ome zarr notebook #311
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,6 @@ numpy | |
torch>=2.0 | ||
monai>=1.2.0 | ||
matplotlib==3.3.1 | ||
PyQt5==5.15.0 | ||
PyQt5-sip==12.8.0 | ||
QtPy==1.9.0 | ||
PySide2 | ||
voila | ||
tqdm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,310 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 23. OME-Zarr image registration" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### OME-Zarr" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"[OME-Zarr](https://ngff.openmicroscopy.org/) is a cloud-optimized file format designed for storing and managing large-scale bioimaging data [1][2]. \n", | ||
"\n", | ||
"## Core Features\n", | ||
"\n", | ||
"**Storage Architecture**\n", | ||
"- Stores N-dimensional typed arrays in individually accessible chunks\n", | ||
"- Uses JSON for metadata storage and binary data in chunk-files\n", | ||
"- Supports up to 5 dimensions in version 0.4 (time, channel, z, y, x)\n", | ||
"\n", | ||
"**Performance Optimization**\n", | ||
"- Implements Google Maps-style multi-resolution pyramids for smooth zooming\n", | ||
"- Offers configurable chunk compression using algorithms like GZIP or Blosc\n", | ||
"- Enables efficient data access through colocated pixel storage\n", | ||
"\n", | ||
"**Data Organization**\n", | ||
"- Uses hierarchical Zarr \"groups\" to organize multiple multi-dimensional pyramids\n", | ||
"- Allows metadata attachment at each hierarchy level using JSON files\n", | ||
"- Supports grouping of related data (raw images, deconvolutions, segmentations)\n", | ||
"\n", | ||
"## Spatial Metadata Support\n", | ||
"\n", | ||
"Version 0.4 introduced significant spatial metadata capabilities:\n", | ||
"- Supports multi-dimensional raster images with associated volumetric data\n", | ||
"- Enables spatial transformations for dataset alignment\n", | ||
"\n", | ||
"[1] https://www.biorxiv.org/content/10.1101/2023.02.17.528834v2.full\n", | ||
"[2] https://pmc.ncbi.nlm.nih.gov/articles/PMC9980008/" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### ngff-zarr" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import itk\n", | ||
"from itkwidgets import compare, checkerboard, view" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The function calls in the 3D case to import and register the images is similar to the 2D case. Masks, usually binary images, are import with the itk library similar to the images. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Import Images\n", | ||
"fixed_image = itk.imread('data/CT_3D_lung_fixed.mha', itk.F)\n", | ||
"moving_image = itk.imread('data/CT_3D_lung_moving.mha', itk.F)\n", | ||
"\n", | ||
"# Import Custom Parameter Map\n", | ||
"parameter_object = itk.ParameterObject.New()\n", | ||
"parameter_object.AddParameterFile('data/parameters.3D.NC.affine.ASGD.001.txt')\n", | ||
"\n", | ||
"# \"WriteResultImage\" needs to be set to \"true\" so that the image is resampled at the end of the registration\n", | ||
"# and the result_image is populated properly\n", | ||
"parameter_object.SetParameter(0, \"WriteResultImage\", \"true\")\n", | ||
"\n", | ||
"# Import Mask Images\n", | ||
"fixed_mask = itk.imread('data/CT_3D_lung_fixed_mask.mha', itk.UC)\n", | ||
"moving_mask = itk.imread('data/CT_3D_lung_moving_mask.mha', itk.UC)\n", | ||
"\n", | ||
"# Or Optionally Create Masks from scratch\n", | ||
"\n", | ||
"# MaskImageType = itk.Image[itk.UC, 2]\n", | ||
"# fixed_mask = itk.binary_threshold_image_filter(fixed,\n", | ||
"# lower_threshold=80.0,\n", | ||
"# inside_value=1,\n", | ||
"# ttype=(type(fixed), MaskImageType))\n", | ||
"# moving_mask = itk.binary_threshold_image_filter(moving,\n", | ||
"# lower_threshold=80.0,\n", | ||
"# inside_value=1,\n", | ||
"# ttype=(type(moving), MaskImageType))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Input Visualization\n", | ||
"The images and their masks can be visualized with the itkwidget's view function. This can be useful to visually inspect the quality of the masks." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "9e0ed89550c043a29bef90625e1cb58e", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"Viewer(geometries=[], gradient_opacity=0.22, interpolation=False, point_sets=[], rendered_image=<itk.itkImageP…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"view(fixed_image, label_image=fixed_mask)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "3e093036b3be428389dcebe081bb587b", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"Viewer(geometries=[], gradient_opacity=0.22, interpolation=False, point_sets=[], rendered_image=<itk.itkImageP…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"view(moving_image, label_image = moving_mask)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Registration" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Registration can either be done in one line with the registration function..." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Call registration function\n", | ||
"result_image, result_transform_parameters = itk.elastix_registration_method(\n", | ||
" fixed_image, moving_image,\n", | ||
" parameter_object=parameter_object,\n", | ||
" fixed_mask=fixed_mask, moving_mask=moving_mask,\n", | ||
" log_to_console=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
".. or by initiating an elastix image filter object." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Load Elastix Image Filter Object\n", | ||
"# Fixed and moving image should be given to the Elastix method to ensure that\n", | ||
"# the correct 3D class is initialized.\n", | ||
"elastix_object = itk.ElastixRegistrationMethod.New(fixed_image, moving_image)\n", | ||
"elastix_object.SetFixedMask(fixed_mask)\n", | ||
"elastix_object.SetMovingMask(moving_mask)\n", | ||
"elastix_object.SetParameterObject(parameter_object)\n", | ||
"\n", | ||
"# Set additional options\n", | ||
"elastix_object.SetLogToConsole(False)\n", | ||
"\n", | ||
"# Update filter object (required)\n", | ||
"elastix_object.UpdateLargestPossibleRegion()\n", | ||
"\n", | ||
"# Results of Registration\n", | ||
"result_image = elastix_object.GetOutput()\n", | ||
"result_transform_parameters = elastix_object.GetTransformParameterObject()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Output Visualization\n", | ||
"The results of the 3D image registration can also be visualized with widgets from the itkwidget library such as the checkerboard and compare widgets." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "94d279f136cc48b3983cc60458776d58", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"VBox(children=(Viewer(annotations=False, interpolation=False, rendered_image=<itk.itkImagePython.itkImageF3; p…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"checkerboard(fixed_image, result_image,pattern=5)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "b68308d4d978479789642fe885a49896", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"AppLayout(children=(HBox(children=(Label(value='Link:'), Checkbox(value=True, description='cmap'), Checkbox(va…" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"compare(fixed_image, result_image, label_image= [fixed_image, result_image],link_cmap=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use MetaImage format, what does this example have to do with Zarr?
Reply via ReviewNB