Skip to content
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

ITK ERROR: CenteredTransformInitializer: Fixed Image has not been set #437

Closed
amirreza1998 opened this issue Mar 12, 2023 · 27 comments
Closed

Comments

@amirreza1998
Copy link

amirreza1998 commented Mar 12, 2023

hi

i have problem with registration with ants. i install ants with pip in windows os but when I try this code below for registration I get error that is mentioned:
my code:

  registration_path = r"E:\python_venv/medvispy/mri_skull_plugin/savepath"
  input_sample_path = "E:\python_venv\input_sample2/MR_N1.nii"
  database_path = r"E:\python_venv/medvispy/mri_skull_plugin/plugin"

  fname1 = ants.image_read(str(input_sample_path))
   for i in range(1, 8):
       print(f"image {i} out of 8")
       fname2 = ants.image_read(str(database_path / "MR_N{}.nii".format(i)))
       print("error here")
       mytx4 = ants.registration(fixed=fname1, moving=fname2,
                                 type_of_transform="SyN",
                                 outprefix=str(registration_path / "diffToMR_N{}_".format(i)),
                                 reg_iterations=[100, 70, 50, 10],  # -m 100x70x50x10 \
                                 )
       print(mytx4)
       result1 = mytx4["warpedmovout"].to_nibabel()
       result2 = mytx4["warpedfixout"].to_nibabel()
       nib.save(result2, str(registration_path / "N{}_invToMRN1.nii".format(i)))
       nib.save(result1, str(registration_path / "N{}_diffToMRN1.nii".format(i)))

but the result is for each one of registration some thing like below:

 file 0000018600E3C1C0 does not exist . 
Exception Object caught: 

itk::ExceptionObject (0000000A275EBBC0)
Location: "unknown" 
File: D:\a\ANTsPy\ANTsPy\itksource\Modules\Registration\Common\include\itkCenteredTransformInitializer.hxx
Line: 31
Description: ITK ERROR: CenteredTransformInitializer(000001867F47D310): Fixed Image has not been set

{'warpedmovout': ANTsImage (LPI)
	 Pixel Type : float (float32)
	 Components : 1
	 Dimensions : (116, 142, 102)
	 Spacing    : (0.94, 0.94, 0.94)
	 Origin     : (54.05, 66.27, -47.47)
	 Direction  : [-1.  0.  0.  0. -1.  0.  0.  0.  1.]
, 'warpedfixout': ANTsImage (LPI)
	 Pixel Type : float (float32)
	 Components : 1
	 Dimensions : (116, 142, 102)
	 Spacing    : (0.94, 0.94, 0.94)
	 Origin     : (54.05, 66.27, -47.47)
	 Direction  : [-1.  0.  0.  0. -1.  0.  0.  0.  1.]
, 'fwdtransforms': [], 'invtransforms': []}

and in no one of them save fwdtransforms and invtransforms
I use same code ,library and python distribution in linux and every thing was alright but I need it in windows actually

@cookpa
Copy link
Member

cookpa commented Mar 16, 2023

Unfortunately, the pointer representation of the image doesn't work on Windows (see #345).

Looking at this it occurs to me, is the whole problem that the pointer address is incorrectly formatted on Windows? If "0000018600E3C1C0" was "0x000018600E3C1C0", would it work?

@cookpa
Copy link
Member

cookpa commented Mar 16, 2023

I see this has already been considered

std::string ptrstr(py::capsule c)
{
char buffer[50];
int n = sprintf(buffer, "0x%p", (void const *)c);
std::string s(buffer, n);
return s;
}

EDIT: this looks like it should work, because %p should format the pointer with the correct number of leading zeros.

@cookpa
Copy link
Member

cookpa commented Mar 16, 2023

Related, #28

Perhaps #435 could be changed to edit string pointer representations?

@cookpa
Copy link
Member

cookpa commented Mar 21, 2023

@amirreza1998 can you try installing a wheel from here?

https://github.com/ANTsX/ANTsPy/actions/runs/4478997465

@cookpa
Copy link
Member

cookpa commented Mar 21, 2023

Actually I made a mistake, hold on

@cookpa
Copy link
Member

cookpa commented Mar 21, 2023

OK fixed, this will hopefully read the pointer on Windows

https://github.com/ANTsX/ANTsPy/actions/runs/4481220355

@stnava
Copy link
Member

stnava commented Mar 21, 2023 via email

@cookpa
Copy link
Member

cookpa commented Mar 21, 2023

Yes, I'm trying to run run_tests.sh and run_tests.bat now. But I don't know if run_tests.bat itself has been tested.

I'll make the tests part of the automated builds going forward.

@cookpa
Copy link
Member

cookpa commented Mar 21, 2023

@stnava I think I'm making progress on my fork - readimage looks fixed, now working on writeimage. Will update later

@cookpa
Copy link
Member

cookpa commented Mar 22, 2023

I think #442 has done it - tests run on all platforms

@amirreza1998
Copy link
Author

hi
thanks for your responses

I actually created python 3.7 venv and tried this version: pip install https://github.com/SGotla/ANTsPy/releases/download/0.1.7Win64/antspy-0.1.7-cp37-cp37m-win_amd64.whl that has been mentioned in #435 and every think become alright I enthusiasm to use https://github.com/ANTsX/ANTsPy/actions/runs/4478997465 and try it in windows

thanks a lot

@amirreza1998
Copy link
Author

I try this version [antspyx-0.3.8-cp39-win_amd64] and everything is smoothly and alright

@cookpa
Copy link
Member

cookpa commented Mar 23, 2023

Thanks for the update!

@cookpa cookpa closed this as completed Mar 23, 2023
@amirreza1998
Copy link
Author

amirreza1998 commented Mar 26, 2023

i want to try to create template by ants.build_template and get this error :

Exception Object caught: 

itk::ImageFileWriterException (000000E7179EB068)
Location: "unknown" 
File: D:\a\ANTsPy\ANTsPy\itksource\Modules\IO\ImageBase\include\itkImageFileWriter.hxx
Line: 117
Description:  Could not create IO object for writing file 000002462225CAD0
  Tried to create one of the following:
    BMPImageIO
    BioRadImageIO
    Bruker2dseqImageIO
    GDCMImageIO
    GE4ImageIO
    GE5ImageIO
    GiplImageIO
    HDF5ImageIO
    JPEGImageIO
    JPEG2000ImageIO
    LSMImageIO
    MGHImageIO
    MINCImageIO
    MRCImageIO
    MetaImageIO
    NiftiImageIO
    NrrdImageIO
    PNGImageIO
    StimulateImageIO
    TIFFImageIO
    VTKImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.

@ntustison
Copy link
Member

This appears to be unrelated to the original posting. Please open a separate issue.

@amirreza1998
Copy link
Author

I think it's related. still have a problem with the pointer because I inspected the source code of create a template and it has registration on it but the issue of saving the warp file of transition has been solved
and also in registration show this message but doesn't cause any error and stops in the code

@ntustison
Copy link
Member

Are you able to run the code that you originally posted?

@amirreza1998
Copy link
Author

amirreza1998 commented Mar 26, 2023

this is the result of original code above:

Exception Object caught: 

itk::ImageFileWriterException (0000007E8ABEBD08)
Location: unknown
File: D:\a\ANTsPy\ANTsPy\itksource\Modules\IO\ImageBase\include\itkImageFileWriter.hxx
Line: 117
Description:  Could not create IO object for writing file 000001CF1AE8FE30
  Tried to create one of the following:
    BMPImageIO
    BioRadImageIO
    Bruker2dseqImageIO
    GDCMImageIO
    GE4ImageIO
    GE5ImageIO
    GiplImageIO
    HDF5ImageIO
    JPEGImageIO
    JPEG2000ImageIO
    LSMImageIO
    MGHImageIO
    MINCImageIO
    MRCImageIO
    MetaImageIO
    NiftiImageIO
    NrrdImageIO
    PNGImageIO
    StimulateImageIO
    TIFFImageIO
    VTKImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.


{"warpedmovout": ANTsImage (LPI)
         Pixel Type : float (float32)
         Components : 1
         Dimensions : (116, 142, 102)
         Spacing    : (0.94, 0.94, 0.94)
         Origin     : (54.05, 66.27, -47.47)
         Direction  : [-1.  0.  0.  0. -1.  0.  0.  0.  1.]
, "warpedfixout": ANTsImage (LPI)
         Pixel Type : float (float32)
         Components : 1
         Dimensions : (116, 142, 102)
         Spacing    : (0.94, 0.94, 0.94)
         Origin     : (54.05, 66.27, -47.47)
         Direction  : [-1.  0.  0.  0. -1.  0.  0.  0.  1.]
, 'fwdtransforms': ['C:\\Users\\amirreza\\Desktop\\result_reg\\diffToMR_N2_1Warp.nii.gz', 'C:\\Users\\amirreza\\Desktop\\result_reg\\diffToMR_N2_0GenericAffine.mat'], 'invtransforms': 
['C:\\Users\\amirreza\\Desktop\\result_reg\\diffToMR_N2_0GenericAffine.mat', 'C:\\Users\\amirreza\\Desktop\\result_reg\\diffToMR_N2_1InverseWarp.nii.gz']}

it's working ok but still, give exceptions at the beginning
but when I run to create a temple, it gets stuck after the first iteration and doesn't start the second iteration.
my code:

xavg,return_list = ants.build_template(
                iterations=2	#  -i 4 \
                ,gradient_step = 0.25	#  -g 0.25 \
                ,initial_template=fname1	#  -z GRAMFC_Template39404142_N7.nii\
                ,image_list = list_of_fnames	#	${inputPath}/N*_NLAff_diff.nii
                ,warp_path = warp_path
                ,**kwargs
                )

@ntustison
Copy link
Member

This is the result when you run the original code? Ie

  registration_path = r"E:\python_venv/medvispy/mri_skull_plugin/savepath"
  input_sample_path = "E:\python_venv\input_sample2/MR_N1.nii"
  database_path = r"E:\python_venv/medvispy/mri_skull_plugin/plugin"

  fname1 = ants.image_read(str(input_sample_path))
   for i in range(1, 8):
       print(f"image {i} out of 8")
       fname2 = ants.image_read(str(database_path / "MR_N{}.nii".format(i)))
       print("error here")
       mytx4 = ants.registration(fixed=fname1, moving=fname2,
                                 type_of_transform="SyN",
                                 outprefix=str(registration_path / "diffToMR_N{}_".format(i)),
                                 reg_iterations=[100, 70, 50, 10],  # -m 100x70x50x10 \
                                 )
       print(mytx4)
       result1 = mytx4["warpedmovout"].to_nibabel()
       result2 = mytx4["warpedfixout"].to_nibabel()
       nib.save(result2, str(registration_path / "N{}_invToMRN1.nii".format(i)))
       nib.save(result1, str(registration_path / "N{}_diffToMRN1.nii".format(i)))

@ntustison ntustison reopened this Mar 26, 2023
@amirreza1998
Copy link
Author

yes

@ntustison
Copy link
Member

Okay, heavily simplify the code to a single ants.registration call and repost.

@amirreza1998
Copy link
Author

for more information the error that happend in create template is :


  File "E:\python_venv\medvispy\mri_skull_plugin\ants_override\build_template.py", line 161, in build_template
    xavg = xavg * blending_weight + utils.iMath(xavg, "Sharpen") * (
  File "E:\python_venv\medvispy\venv\lib\site-packages\ants\utils\iMath.py", line 106, in iMath
    libfn(processed_args)
untimeError: D:\a\ANTsPy\ANTsPy\itksource\Modules\IO\ImageBase\include\itkImageFileWriter.hxx:117:
 Could not create IO object for writing file 0000020D4F604CD0
    MRCImageIO
    VTKImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.


@ntustison
Copy link
Member

Again, I think there's a misunderstanding because you keep referring to "template building" but there was no template building in your original post. Rather, you just iterated a bunch of ants.registration calls

Tell me, does the following work:

import ants

r16 = ants.image_read(ants.get_ants_data("r16"))
r64 = ants.image_read(ants.get_ants_data("r64"))
reg = ants.registration(r16, r64, type_of_transform="SyN", verbose=True)

@amirreza1998
Copy link
Author

amirreza1998 commented Mar 26, 2023

this is the result and it doesn't work :

itk::ImageFileWriterException (000000F10CBEBBA0)
Location: "unknown"
File: D:\a\ANTsPy\ANTsPy\itksource\Modules\IO\ImageBase\include\itkImageFileWriter.hxx
Line: 117
Description:  Could not create IO object for writing file 0000022DF5626DC0
  Tried to create one of the following:
    BMPImageIO
    BioRadImageIO
    Bruker2dseqImageIO
    GDCMImageIO
    GE4ImageIO
    GE5ImageIO
    GiplImageIO
    HDF5ImageIO
    JPEGImageIO
    JPEG2000ImageIO
    LSMImageIO
    MGHImageIO
    MINCImageIO
    MRCImageIO
    MetaImageIO
    NiftiImageIO
    NrrdImageIO
    PNGImageIO
    StimulateImageIO
    TIFFImageIO
    VTKImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.



Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\python_venv\medvispy\venv\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

@stnava
Copy link
Member

stnava commented Mar 26, 2023 via email

@cookpa
Copy link
Member

cookpa commented Mar 27, 2023

Windows tests all look good here

https://github.com/ANTsX/ANTsPy/actions/runs/4524955037

@amirreza1998
Copy link
Author

yes it solved thanks alot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants