Skip to content

Commit

Permalink
Merge pull request #25 from BrainLesion/outsource_functionals
Browse files Browse the repository at this point in the history
new: functional
  • Loading branch information
neuronflow authored Dec 15, 2023
2 parents f1b354d + 1cb10b0 commit f47c318
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 41 deletions.
1 change: 1 addition & 0 deletions ereg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO do we need this?
from .functional import registration_function
from .registration import RegistrationClass
from .utils.io import read_image_and_cast_to_32bit_float
50 changes: 50 additions & 0 deletions ereg/functional.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
from typing import Union

import SimpleITK as sitk

from ereg import RegistrationClass


def registration_function(
target_image: Union[str, sitk.Image],
moving_image: Union[str, sitk.Image],
output_image: str,
config_file: str,
transform_file: str = None,
log_file: str = None,
**kwargs,
) -> float:
"""
This is a functional wrapper for the registration class.
Args:
target_image (Union[str, sitk.Image]): The target image.
moving_image (Union[str, sitk.Image]): The moving image.
output_image (str): The output image.
config_file (str): The config file for the registration.
transform_file (str, optional): The transform file. Defaults to None.
Returns:
float: The structural similarity index.
"""
if isinstance(config_file, str):
assert os.path.isfile(config_file), "Config file does not exist."
elif isinstance(config_file, dict):
pass
else:
raise ValueError("Config file must be a string or dictionary.")

registration_obj = RegistrationClass(config_file)
registration_obj.register(
target_image=target_image,
moving_image=moving_image,
output_image=output_image,
transform_file=transform_file,
log_file=log_file,
**kwargs,
)
return registration_obj.ssim_score


# TODO we also need a transformation/resample function
41 changes: 0 additions & 41 deletions ereg/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,44 +858,3 @@ def _register_image_and_get_transform(
# tmp.SetCenter(output_transform.GetCenter())
# output_transform = tmp
return registration_transform_sitk


def registration_function(
target_image: Union[str, sitk.Image],
moving_image: Union[str, sitk.Image],
output_image: str,
config_file: str,
transform_file: str = None,
log_file: str = None,
**kwargs,
) -> float:
"""
This is a functional wrapper for the registration class.
Args:
target_image (Union[str, sitk.Image]): The target image.
moving_image (Union[str, sitk.Image]): The moving image.
output_image (str): The output image.
config_file (str): The config file for the registration.
transform_file (str, optional): The transform file. Defaults to None.
Returns:
float: The structural similarity index.
"""
if isinstance(config_file, str):
assert os.path.isfile(config_file), "Config file does not exist."
elif isinstance(config_file, dict):
pass
else:
raise ValueError("Config file must be a string or dictionary.")

registration_obj = RegistrationClass(config_file)
registration_obj.register(
target_image=target_image,
moving_image=moving_image,
output_image=output_image,
transform_file=transform_file,
log_file=log_file,
**kwargs,
)
return registration_obj.ssim_score

0 comments on commit f47c318

Please sign in to comment.