-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added default parameter sets to be used for transforms (from brainregister [IBL] or ARA) * Basic magicgui that can import an atlas, translate the atlas/sample, and perform selected transforms with either elastix defaults or provided ARA defaults * Added a button to reset the image back to origin * Added the ability to rotate the image and reset back to original state * Added start alignment button * Added start alignment button * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Transitioning basic function to qpty directly. Widget in registration_widget.py now uses qtpy directly to replicate the majority of _widget.py functionality. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Napari image layer is now rotated around the center not at origin * Tests for setup_parameter_object done * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Wrote basic tests for registration_widget and register * Re-factored the core registration_widget.py to split off each individual UI component into its own file * Added a run settings widget to allow selection of transform types and default param settings * Added tabs on the left side of the main widget, parameter_list_view represents parameters in a table widget * Can dynamically load default values from the 3 provided sources and load them into the parameter list view * Param dictionaries are updated when fields are altered in the table tab view * Parameter table now expands when new entries are added * Plugin runs successfully after renaming * Param dictionaries passed to the backend directly * First version of transform selection widget allowing arbitrary number of transforms with unique defaults * Each column now dynamically imports the correct default file based on the selection in the second column of the widget * Parameters are now read as lists from files, arbitrary numbers of parameter maps can be run in one go * Moving image adjusts immediately after values are entered, removed adjust image button * When reading parameter files anything after a '\' will now be discarded to allow comments in parameter file * Updated tests for braingblobe_registration/register.py, added tests for brainglobe_registration/widgets/adjust_moving_image.py * Added tests for brainglobe_registration/widgets/select_images_view.py * Started tests for brainglobe_registration/widgets/parameter_list_view.py * Finished tests for brainglobe/registration/widgets/parameter_list_view.py * Started tests for transform_select_view.py * Updating README.md * Update README.md * Updated README.md * Added tests, added dynamic fetching for sample selection * Update README.md * Refactored test_registration_widget.py to account for funcitons moving to utils * Fixed line lengths * WIP transforming annotations after registration * WIP transform annotations after registration * Transformed annotation and boundaries images from atlas to sample space * Registered boundaries are now added as an image layer, boundaries overlaid on sample image after run * Changed the source link in the widget header Co-authored-by: Adam Tyson <[email protected]> * Removed tutorial section of the header --------- Co-authored-by: IgorTatarnikov <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Adam Tyson <[email protected]>
- Loading branch information
1 parent
19ff199
commit 53394b4
Showing
46 changed files
with
2,697 additions
and
112 deletions.
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 |
---|---|---|
|
@@ -82,3 +82,6 @@ venv/ | |
|
||
# written by setuptools_scm | ||
**/_version.py | ||
|
||
# Other test files | ||
Logs/ |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,66 +1,120 @@ | ||
import itk | ||
import numpy as np | ||
from bg_atlasapi import BrainGlobeAtlas | ||
from typing import List | ||
|
||
|
||
def get_atlas_by_name(atlas_name: str) -> BrainGlobeAtlas: | ||
""" | ||
Get a BrainGlobeAtlas object by its name. | ||
Parameters | ||
---------- | ||
atlas_name : str | ||
The name of the atlas. | ||
Returns | ||
------- | ||
BrainGlobeAtlas | ||
The BrainGlobeAtlas object. | ||
""" | ||
atlas = BrainGlobeAtlas(atlas_name) | ||
|
||
return atlas | ||
|
||
|
||
def run_registration( | ||
fixed_image, | ||
atlas_image, | ||
moving_image, | ||
rigid=True, | ||
affine=True, | ||
bspline=True, | ||
affine_iterations="2048", | ||
log=False, | ||
): | ||
annotation_image, | ||
parameter_lists: List[tuple[str, dict]] = None, | ||
) -> tuple[np.ndarray, itk.ParameterObject, np.ndarray]: | ||
""" | ||
Run the registration process on the given images. | ||
Parameters | ||
---------- | ||
atlas_image : np.ndarray | ||
The atlas image. | ||
moving_image : np.ndarray | ||
The moving image. | ||
annotation_image : np.ndarray | ||
The annotation image. | ||
parameter_lists : List[tuple[str, dict]], optional | ||
The list of parameter lists, by default None | ||
Returns | ||
------- | ||
np.ndarray | ||
The result image. | ||
itk.ParameterObject | ||
The result transform parameters. | ||
""" | ||
# convert to ITK, view only | ||
fixed_image = itk.GetImageViewFromArray(fixed_image).astype(itk.F) | ||
atlas_image = itk.GetImageViewFromArray(atlas_image).astype(itk.F) | ||
moving_image = itk.GetImageViewFromArray(moving_image).astype(itk.F) | ||
|
||
# This syntax needed for 3D images | ||
elastix_object = itk.ElastixRegistrationMethod.New( | ||
fixed_image, moving_image | ||
moving_image, atlas_image | ||
) | ||
|
||
parameter_object = setup_parameter_object( | ||
rigid=rigid, | ||
affine=affine, | ||
bspline=bspline, | ||
affine_iterations=affine_iterations, | ||
) | ||
parameter_object = setup_parameter_object(parameter_lists=parameter_lists) | ||
|
||
elastix_object.SetParameterObject(parameter_object) | ||
elastix_object.SetLogToConsole(log) | ||
|
||
# update filter object | ||
elastix_object.UpdateLargestPossibleRegion() | ||
|
||
# get results | ||
result_image = elastix_object.GetOutput() | ||
result_transform_parameters = elastix_object.GetTransformParameterObject() | ||
return np.asarray(result_image), result_transform_parameters | ||
temp_interp_order = result_transform_parameters.GetParameter( | ||
0, "FinalBSplineInterpolationOrder" | ||
) | ||
result_transform_parameters.SetParameter( | ||
"FinalBSplineInterpolationOrder", "0" | ||
) | ||
|
||
annotation_image_transformix = itk.transformix_filter( | ||
annotation_image.astype(np.float32, copy=False), | ||
result_transform_parameters, | ||
) | ||
|
||
result_transform_parameters.SetParameter( | ||
"FinalBSplineInterpolationOrder", temp_interp_order | ||
) | ||
|
||
return ( | ||
np.asarray(result_image), | ||
result_transform_parameters, | ||
np.asarray(annotation_image_transformix), | ||
) | ||
|
||
def setup_parameter_object( | ||
rigid=True, | ||
affine=True, | ||
bspline=True, | ||
affine_iterations="2048", | ||
): | ||
|
||
def setup_parameter_object(parameter_lists: List[tuple[str, dict]] = None): | ||
""" | ||
Set up the parameter object for the registration process. | ||
Parameters | ||
---------- | ||
parameter_lists : List[tuple[str, dict]], optional | ||
The list of parameter lists, by default None | ||
Returns | ||
------- | ||
itk.ParameterObject | ||
The parameter object.# | ||
""" | ||
parameter_object = itk.ParameterObject.New() | ||
|
||
if rigid: | ||
parameter_map_rigid = parameter_object.GetDefaultParameterMap("rigid") | ||
parameter_object.AddParameterMap(parameter_map_rigid) | ||
|
||
if affine: | ||
parameter_map_affine = parameter_object.GetDefaultParameterMap( | ||
"affine" | ||
) | ||
parameter_map_affine["MaximumNumberOfIterations"] = [affine_iterations] | ||
parameter_object.AddParameterMap(parameter_map_affine) | ||
|
||
if bspline: | ||
parameter_map_bspline = parameter_object.GetDefaultParameterMap( | ||
"bspline" | ||
) | ||
parameter_object.AddParameterMap(parameter_map_bspline) | ||
for transform_type, parameter_dict in parameter_lists: | ||
parameter_map = parameter_object.GetDefaultParameterMap(transform_type) | ||
parameter_map.clear() | ||
|
||
for k, v in parameter_dict.items(): | ||
parameter_map[k] = v | ||
|
||
parameter_object.AddParameterMap(parameter_map) | ||
|
||
return parameter_object |
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
name: brainglobe-registration | ||
display_name: BrainGlobe Elastix Registration | ||
display_name: BrainGlobe Registration | ||
contributions: | ||
commands: | ||
- id: brainglobe-registration.register | ||
python_name: brainglobe_registration._widget:register | ||
title: BrainGlobe Elastix Registration | ||
- id: brainglobe-registration.make_registration_widget | ||
python_name: brainglobe_registration.registration_widget:RegistrationWidget | ||
title: BrainGlobe Registration | ||
sample_data: | ||
- key: example | ||
display_name: Sample Brain Slice | ||
uri: src/brainglobe_registration/resources/sample_hipp.tif | ||
widgets: | ||
- command: brainglobe-registration.register | ||
display_name: BrainGlobe Elastix Registration | ||
- command: brainglobe-registration.make_registration_widget | ||
display_name: BrainGlobe Registration |
Oops, something went wrong.