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
N4biasFieldCorrection: Inputs do not occupy the same physical space! #750
Comments
Can you share your images, and code to reproduce the problem? Generally, you can also relax the "GlobalDefaultCoordinateTolerance" but these values seem too significant to be a tolerance issue. |
sorry, I don't have permission to share the image.
I have attempted to set the "GlobalDefaultCoordinateTolerance" , but it is useless. |
Does this occur with the distributed Python binaries too or just you local compilation? |
both error . |
Hello
When I use this code for the brats2015 data set, the following error occurs for the 13th image: |
That looks like an internal problem with the filter. Thank you for reference public data so the error can be reproduced. An issue will need to be create with ITK to correct the underlying issue. The work around here is to save the spacing and the direction matrix in your function. The set the input |
Thank you for your answer |
The above should work, I just typed it and didn't run it. |
Hello ###code##
###########information of mask IndexToPointMatrix: PointToIndexMatrix: Inverse Direction: PixelContainer: IndexToPointMatrix: PointToIndexMatrix: Inverse Direction: PixelContainer: RuntimeError: Exception thrown in SimpleITK N4BiasFieldCorrectionImageFilter_Execute: c:\d\vs14-win64-pkg\simpleitk-build\itk-prefix\include\itk-4.13\itkImageToImageFilter.hxx:241: what this the InputImage_1 Origin?? |
You can review the fundamental concepts of a ITK image here: https://simpleitk.readthedocs.io/en/master/Documentation/docs/source/fundamentalConcepts.html It looks like you need to set the origin to 0, then restore it after the processing. |
@blowekamp series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(str(image_path)) maskImage = sitk.OtsuThreshold(image3D, 0, 1, 200) image3D.SetOrigin([0] * 3) --- N4 bias correct ---corrector = sitk.N4BiasFieldCorrectionImageFilter(); RuntimeError: Exception thrown in SimpleITK N4BiasFieldCorrectionImageFilter_Execute: d:\a\1\sitk-build\itk-prefix\include\itk-4.13\itkImageToImageFilter.hxx:241: |
I have not been able to reproduce this issue locally. Can a minimal reproducible example with data please be provided. Also what OS? and what binary are you using? Thanks |
@ntustison Have you seen this error with N4? |
Hey @blowekamp, currently away from my desk but I’ll look later today. |
Okay @blowekamp , I found this issue which looks similar. Unfortunately, I don't think we ever pinpointed the source of the issue. |
I can confirm same issue on Windows 10. This behaviour seems somewhat random, but I'm sure to see it at some point if I use a loop of repeated calls to N4. |
By running it in a loop, you are calling N4 in the same process over and over again? Can you reproduce the bug with synthetic data? I wonder if this is a windows only bug. |
I think I have a candidate for the cause of the problem:
On windows the MTimes are only 32-bits. I think they are overflowing. This issues was only addressed recently in ITKv5. We can back port the fix for SimpleITK 1.2 and/or you can build SimpleITK against ITKv5 yourself. |
Yep, calling the same process over and over again like this:
Curiously, it only crashes at some seemingly random point in the loop. Here's the error: RuntimeError: Exception thrown in SimpleITK N4BiasFieldCorrection: c:\b\3.7-64\itk-prefix\include\itk-4.13\itkImageToImageFilter.hxx:241: |
Hi! I have the same problem. I run the same code over and over and sometimes it works, sometimes it doesn't. |
To verify the cause on the resulting images run:
You should see the pipeline modified times hit close to 2^32 then reset. |
Confirmed: [' Modified Time: 4292895946', ' PipelineMTime: 4281687443', ' UpdateMTime: 4292895945', ' Modified Time: 4292895939'] |
I created a simple script to test the Modified time:
Running N4 on a zero image, with the default parameters is non-sense but it serves the purpose. The resulting Modified Time: 11,555,091. And if I double the size of the image to 1024x512 it goes up to 23,089,434. Now If I use the current ITKv5 the resulting Modified Time: 1,087,445. And it the image is double it's 2,136,021 That is still doubled! @N-Dekker has done some great work optimized N4 in ITKv5 reducing the modifications by 10x. However it appears to still be linear with the number of pixel! This really creates an excessive number of modifications! @ntustison The solution to this issue is in ITKv5. We will see about getting a fix into SimpleITK, either with a patch to ITK upgrading to ITKv5. In the mean time, SImpleITK can be built against ITKv5 by using the Superbuild and adding "-D ITK_GIT_TAG:STRING=master" to the CMake configuration command. |
Thanks @blowekamp . So does the excessive number of modifications imply that there's something in the code that needs to be fixed? |
@ntustison I think is falls should a little a being a full bug. But it's something that should be addressed.
|
Thanks @blowekamp. Based on your judgment, I'm more than willing to try to resolve this issue although modification times gets into ITK details that are beyond my area of comfort so I'll need your help or somebody else's. I'm not sure as to the source of the issue but my guess would be the underlying B-spline fitting class which is used to generate the estimated bias field. Specifically, the reconstruction function employs an optimization trick specific to B-splines for which I use multiple images as temporary data structures. Would that be a possible culprit? |
I created an ITK issue, we can continue how to address it there. |
Use the VectorContainer's STL interface to avoid causing MTime to be called too many time. This has reported to overflow the global time stamp with it's a 32-bit integer. SimpleITK/SimpleITK#750 closes ITK/ITK#1352
Hi @blowekamp. I noticed it was solved for ITK, is it solved for simpleITK? |
When SimpleITK is built against ITKv5 it is solved. PR #861 is also back porting a couple fixes to the ITKv4 branch for a SimpleITK 1.2.4 distribution. |
Use the VectorContainer's STL interface to avoid causing MTime to be called too many time. This has reported to overflow the global time stamp with it's a 32-bit integer. SimpleITK/SimpleITK#750 closes ITK/ITK#1352
@blowekamp Thanks. Do you know when will that happen? Because I really need to use this tool... I installed ITKv5 and I tried to use N4BiasField in Python but for some reason it does not give the same results. |
Use the VectorContainer's STL interface to avoid causing MTime to be called too many time. This has reported to overflow the global time stamp with it's a 32-bit integer. SimpleITK/SimpleITK#750 closes ITK/ITK#1352
We plan on packaging 1.2.4 this week. |
Use the VectorContainer's STL interface to avoid causing MTime to be called too many time. This has reported to overflow the global time stamp with it's a 32-bit integer. SimpleITK/SimpleITK#750 closes ITK/ITK#1352
An intermediate fix in now available in the just release v1.2.4 binaries before the ITKv5 upgrade. Enjoy! |
Hi @blowekamp, thank you very much for your help and update so quickly. PlatformOS: window 10 codeimport SimpleITK as sitk
import numpy as np
Image = sitk.ReadImage('./F2.nii')
image_orgin = Image.GetOrigin()
image_spacing = Image.GetSpacing()
image_direction = Image.GetDirection()
Image = sitk.Cast(Image, sitk.sitkFloat32)
maskImage = sitk.OtsuThreshold(Image, 0, 1, 200)
Image.SetOrigin([0] * 3)
Image.SetSpacing([1] * 3)
Image.SetDirection([1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0])
maskImage.SetOrigin([0] * 3)
maskImage.SetSpacing([1] * 3)
maskImage.SetDirection([1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0])
corrector = sitk.N4BiasFieldCorrectionImageFilter()
imagePost = corrector.Execute(Image, maskImage) error output:RuntimeError Traceback (most recent call last) d:\workstation\pyenv\sci\lib\site-packages\SimpleITK\SimpleITK.py in Execute(self, *args)
RuntimeError: Exception thrown in SimpleITK N4BiasFieldCorrectionImageFilter_Execute: d:\a\1\sitk-build\itk-prefix\include\itk-4.13\itkImageToImageFilter.hxx:241: I have attached the testing image file, please unzip it to use. I also tried another image, download from http://slicer.kitware.com/midas3/download/item/292312/RegLib_C01_1.nrrd Please check this example, thanks for your help |
Thank you for the test image! Running N4 with the default [50,50,50,50] max iterations resulted in an extremely long running process on OSX. These default parameters are likely now useful and need tweaking. I ran N4 with the provided image with just [2,2,2,2] max iterations. On 1.2.3 the of the output was ~875 million, on 1.2.4 is was 506 million, while when the SimpleITK was compiled against ITKv5 master the MTime of the output was only 34,000. We will be creating a SimpleITK 1.4 alpha binary release compiled against ITKv5 shortly. |
Thanks for your feedback. corrector.SetMaximumNumberOfIterations([2, 2, 2, 2]) most image can work now, but still some occur the same error! |
There are now "latest" SimpleITK binaries available build against ITKv4 available on the Github release tab. It can be downloaded with:
|
Hi
I cannot understand how to solve the issue: inputs do not occupy the same physical space, since I believed I forced them to be in the same physical space with mrtransform command! |
when i use the N4 Correction filter,the error will occur with some image in windows(in linux never show). Before I call the function, I print the origin、spacing of the mask and image,they are totally the same.
Even i do not write the mask image :
output = corrector.Execute(input)
some image will also return the error.
RuntimeError: Exception thrown in SimpleITK N4BiasFieldCorrectionImageFilter_Execute: c:\d\vs14-win64-pkg\simpleitk-build\itk-prefix\include\itk-4.13\itkImageToImageFilter.hxx:241:
itk::ERROR: SubtractImageFilter(00000246299BDE10): Inputs do not occupy the same physical space!
InputImage Origin: [-9.0000000e+01, 1.2600000e+02, -7.2000000e+01], InputImage_1 Origin: [-2.2625000e+01, 2.7125000e+01, -2.2625000e+01]
Tolerance: 1.0000000e-06
InputImage Spacing: [1.0000000e+00, 1.0000000e+00, 1.0000000e+00], InputImage_1 Spacing: [2.2625000e+01, 2.7125000e+01, 2.2625000e+01]
Tolerance: 1.0000000e-06
I use the filter in a loop,when I reduce the MaximumNumberOfIterations ,the error shows will delay(before reduce it occur in the second image, after it occur in the fourth image ) . I think maybe it is a memory access error in windows , my version is 1.2 , my visual studio is visual studio 2015
The text was updated successfully, but these errors were encountered: