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

[WIP] Add reorient functionality to main() function. #13

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
19 changes: 17 additions & 2 deletions src/unigradicon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ def preprocess(image, modality="ct", segmentation=None):
image = apply_mask(image, segmentation)
return image

def reorient(moving, fixed):
from itk.ITKCommonBasePython import itkSpatialOrientationAdapter

return itk.orient_image_filter(
moving,
desired_coordinate_orientation=itkSpatialOrientationAdapter().FromDirectionCosines(fixed.GetDirection()),
use_image_direction=True)

def main():
import itk
import argparse
Expand All @@ -241,6 +249,7 @@ def main():
default=None, type=str, help="The path to save the warped image.")
parser.add_argument("--io_iterations", required=False,
default="50", help="The number of IO iterations. Default is 50. Set to 'None' to disable IO.")
parser.add_argument("--reorient", action="store_true", help="Reorient the source image to the orientation of the target image.")

args = parser.parse_args()

Expand All @@ -264,10 +273,16 @@ def main():
else:
io_iterations = int(args.io_iterations)

moving_processed = preprocess(moving, args.moving_modality, moving_segmentation)
fixed_processed = preprocess(fixed, args.fixed_modality, fixed_segmentation)

if args.reorient:
moving_processed = reorient(moving_processed, fixed_processed)

phi_AB, phi_BA = icon_registration.itk_wrapper.register_pair(
net,
preprocess(moving, args.moving_modality, moving_segmentation),
preprocess(fixed, args.fixed_modality, fixed_segmentation),
moving_processed,
fixed_processed,
finetune_steps=io_iterations)

itk.transformwrite([phi_AB], args.transform_out)
Expand Down
Loading