ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
629 stars 161 forks source link

can use ant to register two dicom files #600

Open tanjia123456 opened 6 months ago

tanjia123456 commented 6 months ago

Hi, thanks for your contribution, Can this library implement rigid registration of two dicom files? like the follwing code

`import SimpleITK as sitk import os import ants

file_path1 = 'process1/CHEN_MING_LAN_8004816942/SE1/60.IMA' file_path2 = 'process1/CHEN_MING_LAN_8004816942/SE0/60.IMA'

fixed = ants.image_read(file_path1) moving = ants.image_read(file_path2) print("\nfixed=", fixed, "moving=", moving)

SyN = ants.registration(fixed = fixed, moving = moving, typr_of_transform = 'Rigid') result = ants.apply_transforms(fixed = fixed, moving = moving, transformlist = SyN['fwdtransforms'])`

but the error occurs: fixed= ANTsImage (RAI) Pixel Type : float (float32) Components : 1 Dimensions : (256, 256, 1) Spacing : (0.4891, 0.4891, 1.0) Origin : (-74.7078, -100.8887, -8.1527) Direction : [ 0.9947 -0.0393 0.0945 0.0276 0.9922 0.1215 -0.0986 -0.1183 0.9881] moving= ANTsImage (RAI) Pixel Type : float (float32) Components : 1 Dimensions : (256, 256, 1) Spacing : (0.4891, 0.4891, 1.0) Origin : (-74.7078, -100.8887, -8.1527) Direction : [ 0.9947 -0.0393 0.0945 0.0276 0.9922 0.1215 -0.0986 -0.1183 0.9881]

Traceback (most recent call last): File "F:\zzmdata\regis_dicom.py", line 14, in SyN = ants.registration(fixed = fixed, moving = moving, typr_of_transform = 'Rigid') File "D:\software\anaconda\envs\pytorch310\lib\site-packages\ants\registration\interface.py", line 1390, in registration raise RuntimeError(f"Registration failed with error code {reg_exit}") RuntimeError: Registration failed with error code 1

ncullen93 commented 6 months ago

You have a typo in your call: typr_of_transform instead of type_of_transform. Try to fix that first. Otherwise, it's also a potential issue that you have an extra dimension in your images (256, 256, 1) - so you should remove that as well.