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

Add cmd unigradicon-jacobian #30

Open
wants to merge 6 commits into
base: main
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
4 changes: 2 additions & 2 deletions .github/workflows/gpu-test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.8
- name: Install dependencies
run: |
pip install -r requirements.txt
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test_readme_works.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
max-parallel: 5
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand All @@ -35,4 +35,5 @@ jobs:
--transform=trans.hdf5 --warped_moving_out=warped_2_C01_1.nrrd --nearest_neighbor
unigradicon-warp --fixed=RegLib_C01_2.nrrd --moving=RegLib_C01_1_foreground_mask.nii.gz \
--transform=trans.hdf5 --warped_moving_out=warped_2_C01_1.nrrd --nearest_neighbor
unigradicon-jacobian --fixed=RegLib_C01_2.nrrd --transform=trans.hdf5 --jacob=jacobian.nii.gz

3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classifiers =
package_dir =
= src
packages = find:
python_requires = >=3.7
python_requires = >=3.8

install_requires =
icon_registration>=1.1.5
Expand All @@ -30,3 +30,4 @@ where = src
console_scripts =
unigradicon-register = unigradicon:main
unigradicon-warp = unigradicon:warp_command
unigradicon-jacobian = unigradicon:compute_jacobian_map_command
34 changes: 31 additions & 3 deletions src/unigradicon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,6 @@ def warp_command():
use_reference_image=True,
reference_image=fixed
)

warped_moving_image = maybe_cast_back(warped_moving_image)

itk.imwrite(warped_moving_image, args.warped_moving_out)

def maybe_cast(img: itk.Image):
Expand All @@ -409,3 +406,34 @@ def maybe_cast(img: itk.Image):

return img, maybe_cast_back

def compute_jacobian_map_command():
import itk
import argparse
parser = argparse.ArgumentParser(description="Compute the Jacobian map of a given transform.")
parser.add_argument("--transform", required=True, type=str,
help="The path to the transform file.")
parser.add_argument("--fixed", required=True, type=str,
help="The path to the fixed image that has been used in the registration.")
parser.add_argument("--jacob", required=True, default=None, help="The path to the output Jacobian map, \
e.g. /path/to/output_jacobian.nii.gz")
parser.add_argument("--log_jacob", required=False, default=None, help="The path to the output log Jacobian map. \
If not specified, the log Jacobian map will not be saved.")
args = parser.parse_args()

transform_file = args.transform
fixed_img_file = args.fixed
transform = itk.transformread(transform_file)[0]
jacob = itk.displacement_field_jacobian_determinant_filter(
itk.transform_to_displacement_field_filter(
transform,
reference_image=itk.imread(fixed_img_file),
use_reference_image=True
)
)
itk.imwrite(jacob, args.jacob)

if args.log_jacob is not None:
log_jacob = itk.LogImageFilter.New(jacob)
log_jacob.Update()
log_jacob = log_jacob.GetOutput()
itk.imwrite(jacob, args.log_jacob)
Loading