You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Encountering segmentation fault when running elastix_registration_method() on both 2D and 3D images #295
Hi there, I have been introduced to Elastix as a possible solution for some of my image alignment needs, and have been running into the aforementioned segmentation fault issue when I try implementing multi-threading on a 3D job.
Using the example elastix data provided, this is the test code that I've written that runs into that segmentation fault:
importnumpyasnpfromitkimportimreadfromitk.itkElastixRegistrationMethodPythonimportelastix_registration_methodfrompathlibimportPathfromtifffileimportimwrite# Load imagesfile_static=Path("/tutorials/elastix-examples/data/CT_3D_lung_fixed.mha")
img_static=np.asarray(imread(file_static))
dtype=str(img_static.dtype)
print(f"Using {file_static.name!r} as the reference image")
file_moving=Path("/tutorials/elastix-examples/data/CT_3D_lung_moving.mha")
img_moving=np.asarray(imread(file_moving))
# Register image while implementing multithreadingimg_aligned, params=elastix_registration_method(
img_static, img_moving,
number_of_threads=2,
log_to_console=False,
) # <-- CODE FAILS AT THIS STEP
I am running this on a Linux RHEL8 system using python v3.10.14 and itk-elastix v0.20.0
Any insight into what went wrong would be much appreciated!
changed the title [-]`elastix_registration_method` leads to a segmentation fault when run on 3D images with multi-threading enabled[/-][+]Running `elastix_registration_method()` on 3D images with multi-threading enabled leads to a segmentation fault[/+]on Jun 28, 2024
Something happened with our manylinux2014 packages (for older glibc). Are you able to reproduce the issue on a newer Linux that has glibc 2.28 or newer? Perhaps it is easy to do a quick test in a Docker image?
Thanks for getting back to me, @thewtex ! Unfortunately, I do not have the know-how at present to set up and run a Docker image of a different Linux distribution. However, if you could keep in mind this issue as encountered on RHEL8 and inform me of a solution in due time, that would be much appreciated!
Hi @thewtex , just an update to this matter: I have opted to perform the image analysis in two dimensions on a per-slice basis, and I surprisingly still run into this segmentation fault issue. Same Linux OS (RHEL8) and ITK-Elastix version (0.20.0).
This was the relevant bit of code I was running:
importnumpyasnpfromitk.elxParameterObjectPythonimportelastixParameterObjectfromitk.itkElastixRegistrationMethodPythonimportelastix_registration_methodfromtifffileimportTiffFiledefrun():
# Load TIFF filesprint("Loading TIFF files")
ref_tiff=TiffFile("reference_image.tiff")
mov_tiff=TiffFile("moving_image.tiff")
# These are ImageJ-compatible TIFF images of shape (85, 2048, 2048)# Load metadataref_series=ref_tiff.series[0]
mov_series=mov_tiff.series[0]
num_frames=mov_series.shape[0] # slices in stack# Set up parameter objectprint("Setting up initial registration parameters")
params_init: elastixParameterObject=elastixParameterObject.New()
params_map=params_init.GetDefaultParameterMap(
# Uncomment as needed"rigid", # Translation + rotation# "affine", # Translation + rotation + scaling + shearingnumberOfResolutions=1,
)
params_init.AddParameterMap(params_map)
# Align in xy planeforfinrange(num_frames):
ref_img=ref_series.pages[f].asarray()
ifinvert_referenceisTrue:
ref_img= (2**bit_depth-1) -ref_img# Order of subtraction is importantmov_img=mov_series.pages[f].asarray()
print(f"Aligning frame {f}")
reg_img, params_reg=elastix_registration_method(
ref_img, mov_img,
parameter_object=params_init,
log_to_console=False,
number_of_threads=1,
)
# Convert to NumPy arrayreg_img=np.asarray(reg_img)
# Append to image stackiff==0:
reg_stk= [reg_img]
else:
reg_stk=np.append(
reg_stk,
[reg_img],
axis=0,
)
if__name__=="__main__":
run()
The segmentation fault appears to occur randomly at different points when iterating through the stack. It also occurs even when the number_of_threads parameter is set to 1. It looks like this is not just an issue with the dimensionality, but with the program trying to (to the best of my current limited computing knowledge) access forbidden bits of the memory in the process of trying to align the image.
Would appreciate your comments on this matter when you have the time. Thanks!
changed the title [-]Running `elastix_registration_method()` on 3D images with multi-threading enabled leads to a segmentation fault[/-][+]Encountering segmentation fault when running `elastix_registration_method()` on both 2D and 3D images[/+]on Jul 16, 2024
Hi @thewtex , apologies for the delay in responding, and thanks for following up on this issue!
The project I'm working on involving this matter has been parked on the side for a bit while we attend to more pressing matters, but I will follow up on this issue once I resume work on it!
Activity
[-]`elastix_registration_method` leads to a segmentation fault when run on 3D images with multi-threading enabled[/-][+]Running `elastix_registration_method()` on 3D images with multi-threading enabled leads to a segmentation fault[/+]thewtex commentedon Jul 5, 2024
Hi, what version of Linux are you using?
tieneupin commentedon Jul 5, 2024
Hi, I'm running it on RHEL8. Have updated my question to reflect this.
thewtex commentedon Jul 9, 2024
Something happened with our manylinux2014 packages (for older glibc). Are you able to reproduce the issue on a newer Linux that has glibc 2.28 or newer? Perhaps it is easy to do a quick test in a Docker image?
tieneupin commentedon Jul 11, 2024
Thanks for getting back to me, @thewtex ! Unfortunately, I do not have the know-how at present to set up and run a Docker image of a different Linux distribution. However, if you could keep in mind this issue as encountered on RHEL8 and inform me of a solution in due time, that would be much appreciated!
tieneupin commentedon Jul 16, 2024
Hi @thewtex , just an update to this matter: I have opted to perform the image analysis in two dimensions on a per-slice basis, and I surprisingly still run into this segmentation fault issue. Same Linux OS (RHEL8) and ITK-Elastix version (0.20.0).
This was the relevant bit of code I was running:
The segmentation fault appears to occur randomly at different points when iterating through the stack. It also occurs even when the
number_of_threadsparameter is set to 1. It looks like this is not just an issue with the dimensionality, but with the program trying to (to the best of my current limited computing knowledge) access forbidden bits of the memory in the process of trying to align the image.Would appreciate your comments on this matter when you have the time. Thanks!
[-]Running `elastix_registration_method()` on 3D images with multi-threading enabled leads to a segmentation fault[/-][+]Encountering segmentation fault when running `elastix_registration_method()` on both 2D and 3D images[/+]thewtex commentedon Jul 16, 2024
@tieneupin thanks for the report and script.
It may be worth trying itkwasm-elastix.
thewtex commentedon Mar 10, 2025
Hi @tieneupin
Is the issue reproducible with
itk-elastix 0.22.0?tieneupin commentedon Mar 19, 2025
Hi @thewtex , apologies for the delay in responding, and thanks for following up on this issue!
The project I'm working on involving this matter has been parked on the side for a bit while we attend to more pressing matters, but I will follow up on this issue once I resume work on it!