-
Notifications
You must be signed in to change notification settings - Fork 0
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
transform / resampling does not work #61
Comments
Why is the transform an optional input for the We also need a unit test, that also tests this resampling. |
Can you check 5a4f5d3? |
Sorry, I cannot follow? |
I meant, can you check out this commit and try again? It should be the latest commit in the branch https://github.com/BrainLesion/eReg/tree/61-transform-resampling-does-not-work |
Now a warp file but no log file is created. Here the code I am using:
I am using this example data for my tests: |
Hmm, here is what I am getting using (very similar) code: import os
from pprint import pprint
from ereg import RegistrationClass
base_output = "C:/Users/sarth/Downloads/ereg_test/"
pprint(f"Current files in {base_output}: {os.listdir(base_output)}")
fla = os.path.join(base_output, "fla.nii.gz")
t1c = os.path.join(base_output, "t1c.nii.gz")
output_image_file_0 = os.path.join(base_output, "fla_registered_0.nii.gz")
output_image_file_1 = os.path.join(base_output, "fla_registered_1.nii.gz")
output_transform_file = os.path.join(base_output, "fla_transform.mat")
log_file = os.path.join(base_output, "fla_registration.log")
registration_obj = RegistrationClass()
registration_obj.register(
target_image=t1c, # the target image, which can be either a file or SimpleITK.Image object
moving_image=fla, # the moving image, which can be either a file or SimpleITK.Image object
output_image=output_image_file_0, # the output image to save the registered image to
transform_file=output_transform_file, # the transform file to save the transform to; if already present, will use this transform instead of computing a new one
log_file=log_file, # the log file to write to
)
registration_obj.resample_image(
target_image=t1c, # the target image, which can be either a file or SimpleITK.Image object
moving_image=fla, # the moving image, which can be either a file or SimpleITK.Image object
output_image=output_image_file_1, # the output image to save the registered image to
transform_file=output_transform_file, # the transform file to save the transform to; if already present, will use this transform instead of computing a new one
log_file=log_file,
)
pprint(f"Current files in {base_output}: {os.listdir(base_output)}") Output: ("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'t1c.nii.gz']")
("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'fla_registered_0.nii.gz', 'fla_registered_1.nii.gz', "
"'fla_registration.log', 'fla_transform.mat', 't1c.nii.gz']") Log file: fla_registration.log |
Can you try submitting another log file for the resampling? |
That seems to have done it! from pprint import pprint
from ereg import RegistrationClass
base_output = "C:/Users/sarth/Downloads/ereg_test/"
pprint(f"Current files in {base_output}: {os.listdir(base_output)}")
fla = os.path.join(base_output, "fla.nii.gz")
t1c = os.path.join(base_output, "t1c.nii.gz")
output_image_file_0 = os.path.join(base_output, "fla_registered_0.nii.gz")
output_image_file_1 = os.path.join(base_output, "fla_registered_1.nii.gz")
output_transform_file = os.path.join(base_output, "fla_transform.mat")
log_file_0 = os.path.join(base_output, "fla_registration_0.log")
log_file_1 = os.path.join(base_output, "fla_registration_1.log")
registration_obj = RegistrationClass()
registration_obj.register(
target_image=t1c, # the target image, which can be either a file or SimpleITK.Image object
moving_image=fla, # the moving image, which can be either a file or SimpleITK.Image object
output_image=output_image_file_0, # the output image to save the registered image to
transform_file=output_transform_file, # the transform file to save the transform to; if already present, will use this transform instead of computing a new one
log_file=log_file_0, # the log file to write to
)
registration_obj.resample_image(
target_image=t1c, # the target image, which can be either a file or SimpleITK.Image object
moving_image=fla, # the moving image, which can be either a file or SimpleITK.Image object
output_image=output_image_file_1, # the output image to save the registered image to
transform_file=output_transform_file, # the transform file to save the transform to; if already present, will use this transform instead of computing a new one
log_file=log_file_1,
)
pprint(f"Current files in {base_output}: {os.listdir(base_output)}") ("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'t1c.nii.gz']")
("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'fla_registered_0.nii.gz', 'fla_registered_1.nii.gz', "
"'fla_registration_0.log', 'fla_transform.mat', 't1c.nii.gz']") |
I can confirm that the logging lines related to resampling [ref] are indeed getting invoked, but no idea why the file itself is not getting created. UPDATE: Using the solution in a comment here worked. Can you please try with 8072831? Here is my output from the previous code block: ("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'fla_registered_0.nii.gz', 'fla_registration_0.log', 'fla_transform.mat', "
"'t1c.nii.gz']")
("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'fla_registered_0.nii.gz', 'fla_registered_1.nii.gz', "
"'fla_registration_0.log', 'fla_registration_1.log', 'fla_transform.mat', "
"'t1c.nii.gz']") |
I tested, and still no log is created. |
Okay, in that case I don't know how else to proceed since I am unable to reproduce the error. Can you or someone else who is able to reproduce the issue try to debug this? |
Do you test on a Windows machine? your paths seem to suggest that. I believe one way would be to construct a unit test testing warp and log file creation, similar to this. Once this test is passed, hopefully it will work. A primitive test could just check for existence of these files: |
Yes.
A few points:
|
With 017cb6c, I am getting this output with the code I sent: ("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'t1c.nii.gz']")
Target image: C:/Users/sarth/Downloads/ereg_test/t1c.nii.gz, Moving image: C:/Users/sarth/Downloads/ereg_test/fla.nii.gz
Starting registration with parameters:: {'bias': False, 'metric_parameters': {'type': 'mean_squares', 'histogram_bins': 50, 'radius': 5, 'intensityDifferenceThreshold': 0.001, 'varianceForJointPDFSmoothing': 1.5}, 'optimizer_parameters': {'type': 'regular_step_gradient_descent', 'min_step': '1e-4', 'max_step': 1.0, 'iterations': 200, 'relaxation': 0.1, 'learningrate': 1.0, 'tolerance': '1e-6', 'convergence_minimum': '1e-6', 'convergence_window_size': 10, 'line_search_lower_limit': 0.0, 'line_search_upper_limit': 5.0, 'line_search_epsilon': 0.01, 'step_length': 0.1, 'simplex_delta': 0.1, 'maximum_number_of_corrections': 5, 'maximum_number_of_function_evaluations': 2000, 'solution_accuracy': '1e-5', 'hessian_approximate_accuracy': '1e-5', 'delta_convergence_distance': '1e-5', 'delta_convergence_tolerance': '1e-5', 'line_search_maximum_evaluations': 50, 'line_search_minimum_step': '1e-20', 'line_search_accuracy': '1e-4', 'epsilon': '1e-8', 'initial_radius': 1.0, 'growth_factor': -1.0, 'shrink_factor': -1.0, 'maximum_line_iterations': 100, 'step_tolerance': '1e-6', 'value_tolerance': '1e-6'}, 'transform': 'versorrigid', 'composite_transform': False, 'previous_transforms': [], 'initialization': 'geometry', 'interpolator': 'linear', 'sampling_strategy': 'random', 'sampling_percentage': 0.01, 'shrink_factors': [4, 2, 1], 'smoothing_sigmas': [2, 1, 0], 'attempts': 5}
Initializing registration.
Starting registration.
Final Optimizer Parameters:: convergence=0.0, iterations=30, metric=28450.710036942543, stop condition=RegularStepGradientDescentOptimizerv4: Step too small after 29 iterations. Current step (3.99601e-05) is less than minimum step (0.0001).
Target image: Image (0000021E33799B80)
RTTI typeinfo: class itk::Image<float,3>
Reference Count: 1
Modified Time: 1872
Debug: Off
Object Name:
Observers:
none
Source: (none)
Source output name: (none)
Release Data: Off
Data Released: False
Global Release Data: Off
PipelineMTime: 1856
UpdateMTime: 1868
RealTimeStamp: 0 seconds
LargestPossibleRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [256, 224, 26]
BufferedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [256, 224, 26]
RequestedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [256, 224, 26]
Spacing: [0.898438, 0.898438, 5.5]
Origin: [-113.656, 74.6162, -46.8588]
Direction:
0.998145 4.82309e-08 0.0608771
-0.00456797 -0.997181 0.0748977
-0.0607054 0.0750368 0.995331
IndexToPointMatrix:
0.896771 4.33325e-08 0.334824
-0.00410404 -0.895905 0.411937
-0.05454 0.0674159 5.47432
PointToIndexMatrix:
1.11098 -0.00508435 -0.0675678
5.37341e-08 -1.10991 0.0835193
0.0110686 0.0136178 0.180969
Inverse Direction:
0.998145 -0.00456797 -0.0607054
4.82768e-08 -0.997181 0.0750368
0.0608771 0.0748977 0.995331
PixelContainer:
ImportImageContainer (0000021E324CD660)
RTTI typeinfo: class itk::ImportImageContainer<unsigned __int64,float>
Reference Count: 1
Modified Time: 1865
Debug: Off
Object Name:
Observers:
none
Pointer: 0000021E72B76040
Container manages memory: true
Size: 1490944
Capacity: 1490944
, Moving image: Image (0000021E337976F0)
RTTI typeinfo: class itk::Image<float,3>
Reference Count: 1
Modified Time: 2126
Debug: Off
Object Name:
Observers:
none
Source: (none)
Source output name: (none)
Release Data: Off
Data Released: False
Global Release Data: Off
PipelineMTime: 2111
UpdateMTime: 2122
RealTimeStamp: 0 seconds
LargestPossibleRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [208, 256, 26]
BufferedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [208, 256, 26]
RequestedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [208, 256, 26]
Spacing: [0.898438, 0.898438, 5.5]
Origin: [-90.7199, 71.3685, -98.396]
Direction:
0.998351 -8.88907e-10 -0.0574024
0.0164015 -0.95831 0.285258
0.0550093 0.285729 0.95673
IndexToPointMatrix:
0.896956 -7.98627e-10 -0.315713
0.0147358 -0.860982 1.56892
0.0494224 0.25671 5.26202
PointToIndexMatrix:
1.11121 0.0182556 0.0612277
-1.38278e-09 -1.06664 0.318029
-0.0104368 0.0518651 0.173951
Inverse Direction:
0.998351 0.0164015 0.0550093
-1.24235e-09 -0.95831 0.285729
-0.0574023 0.285258 0.95673
PixelContainer:
ImportImageContainer (0000021E33D4D760)
RTTI typeinfo: class itk::ImportImageContainer<unsigned __int64,float>
Reference Count: 1
Modified Time: 2120
Debug: Off
Object Name:
Observers:
none
Pointer: 0000021E7313D040
Container manages memory: true
Size: 1384448
Capacity: 1384448
, Transform file: C:/Users/sarth/Downloads/ereg_test/fla_transform.mat
Resampling image.
SSIM score of moving against target image: 0.6702636855503058
Target image: C:/Users/sarth/Downloads/ereg_test/t1c.nii.gz, Moving image: C:/Users/sarth/Downloads/ereg_test/fla.nii.gz, Transform file: C:/Users/sarth/Downloads/ereg_test/fla_transform.mat
Resampling image.
SSIM score of moving against target image: 0.6702636855503058
("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'fla_registered_0.log', 'fla_registered_0.nii.gz', "
"'fla_registered_1.nii.gz', 'fla_registration_0.log', "
"'fla_registration_1.log', 'fla_transform.mat', 't1c.nii.gz']") The log and console both get output. |
I tried with this script:
This now generates three log files: as specified:
Additionally:
Should the |
Nope, all logging related to a task should go to a single file.
This should not get generated if |
indeed weird :) contents of
the other two log files remain empty. Console:
|
Unable to replicate this. Code: from pprint import pprint
from ereg import RegistrationClass
base_output = "C:/Users/sarth/Downloads/ereg_test/"
pprint(f"Current files in {base_output}: {os.listdir(base_output)}")
fla = os.path.join(base_output, "fla.nii.gz")
t1c = os.path.join(base_output, "t1c.nii.gz")
output_image_file_0 = os.path.join(base_output, "fla_registered.nii.gz")
output_image_file_1 = os.path.join(base_output, "fla_resampled.nii.gz")
output_transform_file = os.path.join(base_output, "fla_transform.mat")
log_file_0 = os.path.join(base_output, "registration.log")
log_file_1 = os.path.join(base_output, "resampling.log")
pprint("=== Starting registration ===")
pprint(f"Current files in {base_output}: {os.listdir(base_output)}")
registration_obj = RegistrationClass()
registration_obj.register(
target_image=t1c, # the target image, which can be either a file or SimpleITK.Image object
moving_image=fla, # the moving image, which can be either a file or SimpleITK.Image object
output_image=output_image_file_0, # the output image to save the registered image to
transform_file=output_transform_file, # the transform file to save the transform to; if already present, will use this transform instead of computing a new one
log_file=log_file_0, # the log file to write to
)
pprint("=== Starting resampling ===")
registration_obj.resample_image(
target_image=t1c, # the target image, which can be either a file or SimpleITK.Image object
moving_image=fla, # the moving image, which can be either a file or SimpleITK.Image object
output_image=output_image_file_1, # the output image to save the registered image to
transform_file=output_transform_file, # the transform file to save the transform to; if already present, will use this transform instead of computing a new one
log_file=log_file_1,
)
pprint(f"Current files in {base_output}: {os.listdir(base_output)}") Console output: ("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'t1c.nii.gz']")
'=== Starting registration ==='
("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'t1c.nii.gz']")
Target image: C:/Users/sarth/Downloads/ereg_test/t1c.nii.gz, Moving image: C:/Users/sarth/Downloads/ereg_test/fla.nii.gz
Starting registration with parameters:: {'bias': False, 'metric_parameters': {'type': 'mean_squares', 'histogram_bins': 50, 'radius': 5, 'intensityDifferenceThreshold': 0.001, 'varianceForJointPDFSmoothing': 1.5}, 'optimizer_parameters': {'type': 'regular_step_gradient_descent', 'min_step': '1e-4', 'max_step': 1.0, 'iterations': 200, 'relaxation': 0.1, 'learningrate': 1.0, 'tolerance': '1e-6', 'convergence_minimum': '1e-6', 'convergence_window_size': 10, 'line_search_lower_limit': 0.0, 'line_search_upper_limit': 5.0, 'line_search_epsilon': 0.01, 'step_length': 0.1, 'simplex_delta': 0.1, 'maximum_number_of_corrections': 5, 'maximum_number_of_function_evaluations': 2000, 'solution_accuracy': '1e-5', 'hessian_approximate_accuracy': '1e-5', 'delta_convergence_distance': '1e-5', 'delta_convergence_tolerance': '1e-5', 'line_search_maximum_evaluations': 50, 'line_search_minimum_step': '1e-20', 'line_search_accuracy': '1e-4', 'epsilon': '1e-8', 'initial_radius': 1.0, 'growth_factor': -1.0, 'shrink_factor': -1.0, 'maximum_line_iterations': 100, 'step_tolerance': '1e-6', 'value_tolerance': '1e-6'}, 'transform': 'versorrigid', 'composite_transform': False, 'previous_transforms': [], 'initialization': 'geometry', 'interpolator': 'linear', 'sampling_strategy': 'random', 'sampling_percentage': 0.01, 'shrink_factors': [4, 2, 1], 'smoothing_sigmas': [2, 1, 0], 'attempts': 5}
Initializing registration.
Starting registration.
Final Optimizer Parameters:: convergence=0.0, iterations=141, metric=29311.701283887756, stop condition=RegularStepGradientDescentOptimizerv4: Step too small after 140 iterations. Current step (5.89053e-05) is less than minimum step (0.0001).
Target image: Image (000001E64476B140)
RTTI typeinfo: class itk::Image<float,3>
Reference Count: 1
Modified Time: 1872
Debug: Off
Object Name:
Observers:
none
Source: (none)
Source output name: (none)
Release Data: Off
Data Released: False
Global Release Data: Off
PipelineMTime: 1856
UpdateMTime: 1868
RealTimeStamp: 0 seconds
LargestPossibleRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [256, 224, 26]
BufferedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [256, 224, 26]
RequestedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [256, 224, 26]
Spacing: [0.898438, 0.898438, 5.5]
Origin: [-113.656, 74.6162, -46.8588]
Direction:
0.998145 4.82309e-08 0.0608771
-0.00456797 -0.997181 0.0748977
-0.0607054 0.0750368 0.995331
IndexToPointMatrix:
0.896771 4.33325e-08 0.334824
-0.00410404 -0.895905 0.411937
-0.05454 0.0674159 5.47432
PointToIndexMatrix:
1.11098 -0.00508435 -0.0675678
5.37341e-08 -1.10991 0.0835193
0.0110686 0.0136178 0.180969
Inverse Direction:
0.998145 -0.00456797 -0.0607054
4.82768e-08 -0.997181 0.0750368
0.0608771 0.0748977 0.995331
PixelContainer:
ImportImageContainer (000001E644924DE0)
RTTI typeinfo: class itk::ImportImageContainer<unsigned __int64,float>
Reference Count: 1
Modified Time: 1865
Debug: Off
Object Name:
Observers:
none
Pointer: 000001E6045C6040
Container manages memory: true
Size: 1490944
Capacity: 1490944
, Moving image: Image (000001E64476A060)
RTTI typeinfo: class itk::Image<float,3>
Reference Count: 1
Modified Time: 2126
Debug: Off
Object Name:
Observers:
none
Source: (none)
Source output name: (none)
Release Data: Off
Data Released: False
Global Release Data: Off
PipelineMTime: 2111
UpdateMTime: 2122
RealTimeStamp: 0 seconds
LargestPossibleRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [208, 256, 26]
BufferedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [208, 256, 26]
RequestedRegion:
Dimension: 3
Index: [0, 0, 0]
Size: [208, 256, 26]
Spacing: [0.898438, 0.898438, 5.5]
Origin: [-90.7199, 71.3685, -98.396]
Direction:
0.998351 -8.88907e-10 -0.0574024
0.0164015 -0.95831 0.285258
0.0550093 0.285729 0.95673
IndexToPointMatrix:
0.896956 -7.98627e-10 -0.315713
0.0147358 -0.860982 1.56892
0.0494224 0.25671 5.26202
PointToIndexMatrix:
1.11121 0.0182556 0.0612277
-1.38278e-09 -1.06664 0.318029
-0.0104368 0.0518651 0.173951
Inverse Direction:
0.998351 0.0164015 0.0550093
-1.24235e-09 -0.95831 0.285729
-0.0574023 0.285258 0.95673
PixelContainer:
ImportImageContainer (000001E644923EE0)
RTTI typeinfo: class itk::ImportImageContainer<unsigned __int64,float>
Reference Count: 1
Modified Time: 2120
Debug: Off
Object Name:
Observers:
none
Pointer: 000001E604B82040
Container manages memory: true
Size: 1384448
Capacity: 1384448
, Transform file: C:/Users/sarth/Downloads/ereg_test/fla_transform.mat
Resampling image.
SSIM score of moving against target image: 0.6632827569421897
'=== Starting resampling ==='
Target image: C:/Users/sarth/Downloads/ereg_test/t1c.nii.gz, Moving image: C:/Users/sarth/Downloads/ereg_test/fla.nii.gz, Transform file: C:/Users/sarth/Downloads/ereg_test/fla_transform.mat
Resampling image.
SSIM score of moving against target image: 0.6632827569421897
("Current files in C:/Users/sarth/Downloads/ereg_test/: ['fla.nii.gz', "
"'fla_registered.log', 'fla_registered.nii.gz', 'fla_resampled.nii.gz', "
"'fla_transform.mat', 'registration.log', 'resampling.log', 't1c.nii.gz']") Contents of log files:
Since this is now pretty much a wild goose chase, can we PLEASE get the associated PR for this merged and open up a separate issue for the log files? |
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A log file and a transformation file should be created. An error msg should appear if this fails.
Environment
Python 3.10
operating system and version?
e.g. Ubuntu 23.10 LTS
Ubuntu 20
Python environment and version?
e.g. Conda environment with Python 3.10. Check your Python version with:
The text was updated successfully, but these errors were encountered: