Skip to content

Commit

Permalink
Merge pull request #99 from HiPCTProject/clean-logging
Browse files Browse the repository at this point in the history
Clean up logging
  • Loading branch information
dstansby authored May 1, 2024
2 parents 5fb2816 + f0774ca commit 8d64a6c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
19 changes: 8 additions & 11 deletions src/hipct_reg/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def registration_rot(
logging.info(f"Initial rotation = {zrot} deg")
logging.info(f"Range = {angle_range} deg")
logging.info(f"Step = {angle_step} deg")
logging.info(f"Common point ROI = {reg_input.common_point_roi} pix")
logging.info(f"Common point full = {reg_input.common_point_full} pix")

R.SetOptimizerAsExhaustive(
numberOfSteps=[0, 0, int((angle_range / 2) / angle_step), 0, 0, 0],
Expand Down Expand Up @@ -133,7 +131,7 @@ def command_iteration(
new_zrot = np.rad2deg(transform_rotation.GetAngleZ())
logging.debug(f"Final metric value = {R.GetMetricValue()}")
logging.debug(f"Stopping condition = {R.GetOptimizerStopConditionDescription()}")
logging.info(f"Registered rotation angele = {new_zrot} deg")
logging.info(f"Registered rotation angle = {new_zrot} deg")
logging.info("")

return transform_rotation, data
Expand Down Expand Up @@ -165,8 +163,6 @@ def registration_rigid(
"""
logging.info("Starting full registration...")
logging.info(f"Common point ROI = {reg_input.common_point_roi}")
logging.info(f"Common point full = {reg_input.common_point_full}")
logging.info(f"Initial rotation = {zrot:.02f} deg")
pixel_size_roi: int = reg_input.roi_image.GetSpacing()[0]

Expand Down Expand Up @@ -198,7 +194,6 @@ def registration_rigid(
reg_input.full_image.TransformIndexToPhysicalPoint(reg_input.common_point_full)
)
logging.debug(f"rotation center = {rotation_center}")
logging.debug(f"translation from ROI to full organ = {translation}")

theta_x = 0.0
theta_y = 0.0
Expand All @@ -218,8 +213,8 @@ def registration_rigid(
# - Three translation components
# - Scale factor
w = 10
R.SetOptimizerScalesFromPhysicalShift()
R.SetOptimizerWeights([0, 0, w, w, w, w, w / 1000])
R.SetOptimizerScalesFromPhysicalShift()

metric = []

Expand Down Expand Up @@ -248,6 +243,10 @@ def command_iteration(
lambda: command_iteration(R, initial_transform, pixel_size_roi),
)

translation_pix = reg_input.roi_image.TransformPhysicalPointToContinuousIndex(
initial_transform.GetTranslation()
)
logging.info(f"Initial translation = {translation_pix} pix")
logging.info("Starting registration...")
final_transform: sitk.Similarity3DTransform = R.Execute(
reg_input.roi_image, reg_input.full_image
Expand All @@ -262,8 +261,8 @@ def command_iteration(
final_transform.GetTranslation()
)
rotation = np.rad2deg(np.array(final_transform.GetVersor()))
logging.info(f"translation = {translation_pix} pix")
logging.info(f"rotation = {rotation} deg")
logging.info(f"Final translation = {translation_pix} pix")
logging.info(f"Final rotation = {rotation} deg")

return final_transform, R.GetMetricValue()

Expand Down Expand Up @@ -327,9 +326,7 @@ def run_registration(

logging.info("Results from similarity registration:")
logging.info(f"Translation = {final_transform.GetTranslation()}")
logging.info(f"Center of rot = {final_transform.GetCenter()}")
logging.info(f"Matrix = {final_transform.GetMatrix()}")
logging.info(f"Versor = {final_transform.GetVersor()}")
logging.info(f"Scale = {final_transform.GetScale()}")
logging.info(f"Metric = {final_metric}")
logging.info("")
Expand Down
6 changes: 1 addition & 5 deletions src/hipct_reg/tests/expected_reg_log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ INFO Starting rotational registration
INFO Initial rotation = 0 deg
INFO Range = 360 deg
INFO Step = 2.0 deg
INFO Common point ROI = (32, 32, 32) pix
INFO Common point full = (40, 40, 40) pix
INFO Starting rotational registration...
INFO Registration finished!
INFO Registered rotation angele = 0.0 deg
INFO Registered rotation angle = 0.0 deg
INFO
INFO Starting rotational registration
INFO Initial rotation = 0.0 deg
INFO Range = 5 deg
INFO Step = 0.1 deg
INFO Common point ROI = (32, 32, 32) pix
INFO Common point full = (40, 40, 40) pix
INFO Starting rotational registration...
INFO Registration finished!
INFO Registered rotation angele = -0.1 deg
Expand Down
7 changes: 2 additions & 5 deletions src/hipct_reg/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,9 @@ def test_registration_rot(
INFO Initial rotation = 0 deg
INFO Range = 360 deg
INFO Step = 2 deg
INFO Common point ROI = (32, 32, 32) pix
INFO Common point full = (40, 40, 40) pix
INFO Starting rotational registration...
INFO Registration finished!
INFO Registered rotation angele = 0.0 deg
INFO Registered rotation angle = 0.0 deg
"""
assert caplog.text.replace("INFO \n", "") == expected

Expand Down Expand Up @@ -191,9 +189,8 @@ def test_registration_rigid(
# Don't test output lines, as the final values are subject to floating point
# differences on each run
expected = r"""INFO Starting full registration...
INFO Common point ROI = (32, 32, 32)
INFO Common point full = (40, 40, 40)
INFO Initial rotation = 0.02 deg
INFO Initial translation = (128.0, 128.0, 128.0) pix
INFO Starting registration...
INFO Registration finished!
"""
Expand Down

0 comments on commit 8d64a6c

Please sign in to comment.