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 bug in createJacobianDeterminantImage after upgrade #383

Closed
muratmaga opened this issue May 5, 2023 · 14 comments
Closed

ITK bug in createJacobianDeterminantImage after upgrade #383

muratmaga opened this issue May 5, 2023 · 14 comments
Labels

Comments

@muratmaga
Copy link

muratmaga commented May 5, 2023

A couple weeks ago I upgraded the ANTsR and ANTsCore to the latest version on GH via R CMD INSTALL method. Now I am getting this ITK error when I try to run createJacobianDeterminantImage at the warp image read step. This reproduces using the example code.

antsImageRead() works perfectly fine on this image, so it is not triggered due to file corruption

> fi<-antsImageRead( getANTsRData("r16") ,2)
> mi<-antsImageRead( getANTsRData("r64") ,2)
> fi<-resampleImage(fi,c(128,128),1,0)
> mi<-resampleImage(mi,c(128,128),1,0)
> mytx<-antsRegistration(fixed=fi , moving=mi, typeofTransform = c("SyN") )
> jac<-createJacobianDeterminantImage(fi,mytx$fwdtransforms[[1]],1)
ITK ExceptionObject caught!
Error in createJacobianDeterminantImage(fi, mytx$fwdtransforms[[1]], 1) : 
  /usr/local/lib/R/site-library/ITKR/libs/include/ITK-5.3/itkImageFileReader.hxx:132:
 Could not create IO object for reading file /tmp/RtmpB9ydC3/file20a543a7faac81Warp.nii.gz
  Tried to create one of the following:
    MGHImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.

Here are the sessionInfo and other relevant things.

  Dependency                                   GitTag
1       ANTs d30526f9cb5159bc0a3e9011f7ae5f409b3634c8
2  ANTsRCore 038b62f258d426e82ec3dd837793a7746b5d83b8
3    ANTsURL        https://github.com/ANTsX/ANTs.git
4        ITK                                 v5.3rc04
> .libPaths()
[1] "/home/maga/R/x86_64-pc-linux-gnu-library/4.1" "/usr/local/lib/R/site-library"               
[3] "/usr/lib/R/site-library"                      "/usr/lib/R/library"                          
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8    LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ANTsR_0.5.7.5   ANTsRCore_0.7.5

loaded via a namespace (and not attached):
[1] compiler_4.1.2      RcppEigen_0.3.3.9.3 magrittr_2.0.3      Matrix_1.4-0        tools_4.1.2         ITKR_0.6.0.0.2     
[7] Rcpp_1.0.9          grid_4.1.2          lattice_0.20-45    
> 
> 
@ntustison
Copy link
Member

I'm not able to reproduce. And that ITK error looks wrong as it's missing several file types. You mention that you ugraded ANTsRCore and ANTsR but I don't see where you completely re-installed ITKR. You might want to try that for a possible fix.

@muratmaga
Copy link
Author

Sorry, yes ITKR also got reinstalled. And I would agree this is an ITK issue, except that antsImageRead seem to work fine with the same input.
As a temporary work around I brought back the older libraries, and everything is back to working.

I will try to rebuild the ITKR cleanly one more and see if it fixes.

@ntustison
Copy link
Member

antsImageRead seem to work fine with the same input.

"input", I assume, refers to the temporary warp file, mytx$fwdtransforms[[1]], correct?

@muratmaga
Copy link
Author

muratmaga commented May 5, 2023

it I used the hard coded path reported in the error, because I suspected the file got corrupted for some reason.
antsImageRead("/tmp/RtmpB9ydC3/file20a543a7faac81Warp.nii.gz")

@ntustison
Copy link
Member

Okay, just wanted to confirm as "input" was ambiguous and the antsImageRead call of the temp warp file is missing. I just tried it and wasn't able to reproduce the error:

> mytx$fwdtransforms[[1]]
[1] "/var/folders/5h/62f7bql14zvgx34nqwd7xvnc0000gn/T//RtmpaA01Qa/file2f11583079921Warp.nii.gz"
> antsImageRead( mytx$fwdtransforms[[1]] )
antsImage
  Pixel Type          : float 
  Components Per Pixel: 2 
  Dimensions          : 128x128 
  Voxel Spacing       : 2x2 
  Origin              : 0 0 
  Direction           : 1 0 0 1 
  Filename           : /var/folders/5h/62f7bql14zvgx34nqwd7xvnc0000gn/T//RtmpaA01Qa/file2f11583079921Warp.nii.gz 

@muratmaga
Copy link
Author

This is what I am getting

>  fi<-antsImageRead( getANTsRData("r16") ,2)
>      mi<-antsImageRead( getANTsRData("r64") ,2)
>      fi<-resampleImage(fi,c(128,128),1,0)
>      mi<-resampleImage(mi,c(128,128),1,0)
>      mytx<-antsRegistration(fixed=fi , moving=mi, typeofTransform = c("SyN") )
>      jac<-createJacobianDeterminantImage(fi,mytx$fwdtransforms[[1]],1)
ITK ExceptionObject caught!
Error in createJacobianDeterminantImage(fi, mytx$fwdtransforms[[1]], 1) : 
  /usr/local/lib/R/site-library/ITKR/libs/include/ITK-5.3/itkImageFileReader.hxx:132:
 Could not create IO object for reading file /tmp/RtmpUA2gDC/file211d1753c51c041Warp.nii.gz
  Tried to create one of the following:
    MGHImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.
> test = antsImageRead(mytx$fwdtransforms[[1]])
> print(test)
antsImage
  Pixel Type          : float 
  Components Per Pixel: 2 
  Dimensions          : 128x128 
  Voxel Spacing       : 2x2 
  Origin              : 0 0 
  Direction           : 1 0 0 1 
  Filename           : /tmp/RtmpUA2gDC/file211d1753c51c041Warp.nii.gz 

Will try to rebuild ITKR from scratch

@muratmaga
Copy link
Author

Himm, this is what I did

root@magalab-ML:~# cd ITKR
root@magalab-ML:~/ITKR# ./cleanup
root@magalab-ML:~/ITKR# git pull origin
Already up to date.
root@magalab-ML:~/ITKR# cd ..
root@magalab-ML:~# R CMD INSTALL ITKR

successful build, but resulted in the same error. any other suggestions

@ntustison
Copy link
Member

Is the error reproducible on a different machine?

@muratmaga
Copy link
Author

Yep, it does on a cloud Ubuntu machine I have. Same error. I can give you access, if it helps:
image

@muratmaga
Copy link
Author

I am still getting the same error after building ITKR, ANTsCore, ANTsR via R CMD INSTALL with fresh clones from the primary repo on a new system. Any help will be greatly appreciated...

@ntustison
Copy link
Member

I don't know. I'd have to explore a bit. If you can provide access, I can try to take a look later this week.

@muratmaga
Copy link
Author

just sent you an email with access information.

@ntustison
Copy link
Member

Okay, I don't know why this is happening on your systems but the CMake magic that is supposed to register the IO factories is just not working when compiling ANTsR but not with ANTsRCore. That's why createJacobianDeterminantImage doesn't work but antsImageRead does. I wish I figured out a fix it but the issue appears to be system-specific and I don't have more time to play around with this at the moment. In fact, if I had more time, I would avoid having it read the file and simply input the actual ANTs image. Perhaps you should add that as a wish-list item.

For now, a workaround is to manually add the required IO factories prior to calling R CMD INSTALL ANTsR. For example, to register the NiftiIO, you would add the line

itk::NiftiImageIOFactory::RegisterOneFactory();

before line 40 of CreateJacobianDeterminantImage. You would also need to include the corresponding header #include "itkNiftiImageIOFactory.h" at the top. Fortunately, it looks like this is the only file affected.

@muratmaga
Copy link
Author

What a bizarre situation. Thank you very much for finding a workaround. Much appreciated

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

No branches or pull requests

3 participants