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 widget + intensity standardization #5

Open
FroylanZR opened this issue Jul 14, 2020 · 9 comments
Open

ITK widget + intensity standardization #5

FroylanZR opened this issue Jul 14, 2020 · 9 comments

Comments

@FroylanZR
Copy link

Hi,

in the step 3D MAP: Interactive rendering of 𝑇2 maps i keep getting the Error displaying widget: model not found. I already installed npm and nodejs and ran the line on the anaconda prompt.

@sbonaretti
Copy link
Owner

Hi! I think you are referring to the ITK widgtes. Have you tried to:

  • install the JupyteLab extension:
    In your terminal type:
    jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib jupyterlab-datawidgets itkwidgets
    
  • restart JupyterLab and rerun the notebook.

You can also have a look at the itkwidget documentation here
Let me know! :)

@FroylanZR
Copy link
Author

Hi,

I had already installed the ITK widgets, i could see them in the extension manager. i uninstalled and am currently trying to reinstall them.

I also had another issue in the code with the instensity standardization step in preprocessing, should i start another issue?

thanks :)

@FroylanZR
Copy link
Author

This is the error i have been getting with the intensity standardization step

RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\Users\Luis\Anaconda3\lib\multiprocessing\pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "C:\Users\Luis\Anaconda3\lib\multiprocessing\pool.py", line 44, in mapstar
return list(map(*args))
File "C:\Users\Luis\Anaconda3\lib\site-packages\pykneer\preprocessing_for_nb.py", line 180, in field_correction_s
img = sitkf.field_correction(img)
File "C:\Users\Luis\Anaconda3\lib\site-packages\pykneer\sitk_functions.py", line 274, in field_correction
img = corrector.Execute(img, mask)
File "C:\Users\Luis\Anaconda3\lib\site-packages\SimpleITK\SimpleITK.py", line 51747, in Execute
return _SimpleITK.N4BiasFieldCorrectionImageFilter_Execute(self, *args)
RuntimeError: Exception thrown in SimpleITK N4BiasFieldCorrectionImageFilter_Execute: d:\a\1\sitk-build\itk-prefix\include\itk-4.13\itkImageToImageFilter.hxx:241:
itk::ERROR: SubtractImageFilter(0000023A21D49730): Inputs do not occupy the same physical space!
InputImage Origin: [0.0000000e+00, 0.0000000e+00, 0.0000000e+00], InputImage_1 Origin: [-1.1850000e+02, -1.5968750e+02, -1.5968750e+02]
Tolerance: 1.5000000e-06
InputImage Spacing: [1.5000000e+00, 3.1250000e-01, 3.1250000e-01], InputImage_1 Spacing: [1.1850000e+02, 1.5968750e+02, 1.5968750e+02]
Tolerance: 1.5000000e-06

"""

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last)
in
1 if intensity_standardization == 1:
----> 2 prep.field_correction(image_data, n_of_cores)

~\Anaconda3\lib\site-packages\pykneer\preprocessing_for_nb.py in field_correction(all_image_data, n_of_processes)
189 start_time = time.time()
190 pool = multiprocessing.Pool(processes=n_of_processes)
--> 191 pool.map(field_correction_s, all_image_data)
192 print ("-> Magnetic field bias corrected")
193 print ("-> The total time was %.2f seconds (about %d min)" % ((time.time() - start_time), (time.time() - start_time)/60))

~\Anaconda3\lib\multiprocessing\pool.py in map(self, func, iterable, chunksize)
266 in a list that is returned.
267 '''
--> 268 return self._map_async(func, iterable, mapstar, chunksize).get()
269
270 def starmap(self, func, iterable, chunksize=None):

~\Anaconda3\lib\multiprocessing\pool.py in get(self, timeout)
655 return self._value
656 else:
--> 657 raise self._value
658
659 def _set(self, i, obj):

RuntimeError: Exception thrown in SimpleITK N4BiasFieldCorrectionImageFilter_Execute: d:\a\1\sitk-build\itk-prefix\include\itk-4.13\itkImageToImageFilter.hxx:241:
itk::ERROR: SubtractImageFilter(0000023A21D49730): Inputs do not occupy the same physical space!
InputImage Origin: [0.0000000e+00, 0.0000000e+00, 0.0000000e+00], InputImage_1 Origin: [-1.1850000e+02, -1.5968750e+02, -1.5968750e+02]
Tolerance: 1.5000000e-06
InputImage Spacing: [1.5000000e+00, 3.1250000e-01, 3.1250000e-01], InputImage_1 Spacing: [1.1850000e+02, 1.5968750e+02, 1.5968750e+02]
Tolerance: 1.5000000e-06

still not sure how to fix it.

Also, i tried running the 3D model after reinstalling the itkwidgets and it still didn't work.

@FroylanZR
Copy link
Author

Just found the issue with the 3D widget. Apparently it was either adblocker or pop up blocker extension on chrome that was blocking the widget from showing up. thanks either way and hope i can get some feedback on the other issue i posted above,

thanks :)

@sbonaretti
Copy link
Owner

Fantastic, happy you solved the widget issue!

For the preprocessing issue. Is it with your images or with demo images?
From the error, I can see that there is an issue with a subtraction in the N4BiasFieldCorrectionImageFilter, the main filter used to correct magnetic field inhomogeneities. It seems like the filter subtract two images that have different origin and spacing:

InputImage Origin: [0.0000000e+00, 0.0000000e+00, 0.0000000e+00]
vs.
InputImage_1 Origin: [-1.1850000e+02, -1.5968750e+02, -1.5968750e+02]

and

InputImage Spacing: [1.5000000e+00, 3.1250000e-01, 3.1250000e-01]
vs.
InputImage_1 Spacing: [1.1850000e+02, 1.5968750e+02, 1.5968750e+02]

Also, I see that in InputImage_1, Origin and Spacing are the same, just one positive and one negative, which is an interesting coincidence.
Not sure how to solve this, since it seems to be happening in N4BiasFieldCorrectionImageFilter. If you are using your own images, as a very first step you could try to set the origin to (0,0,0) and round the spacing to the third decimal, and run the code again.
Let me know how it goes!

@FroylanZR
Copy link
Author

Hi again,

i am getting the issue with the demo images, still haven´t tried to use my own set as i want it to have it running smoothly by then.
Yes, i noticed that small coincidence and am suspecting that the images in the step before standardization are not getting their origins set at (0,0,0), however, in your video the program seems to show more info on the pictures which i have not been able to do manually, for example in step 0 when reading the images it gives information about the origin, for example.

i found it happens with certain images only. The first time i ran the program only file cubeQuant/03 was presenting this issue and once i deleted it from the image_list_preprocessing.txt file, it ran smoothly.

@FroylanZR
Copy link
Author

Hi

I think i found something interesting. The origin of the second image is different because it appears to be the origin of the otsu filter mask used for the field correction step. I just checked the code and maybe it could be solved by adding a line to set the origin to zero for the mask used as well, probably setting the spacing to match the one in the image to filter as well. I am yet to try it but ill let you know what happens.

@sbonaretti
Copy link
Owner

That's indeed interesting, and surprising. Have you also tried to run the image by itself? I mean as the only image in the input .txt file. I am thinking about a possible memory leakage somewhere.
FYI: I will have limited internet access for the next two weeks, but please keep me posted!

@FroylanZR
Copy link
Author

To answer your question, yes, i tried it, the problem was mostly when trying to process more than one at a time.

A small update, I dug into the code in preprocessing_for_nb.py and sitk_functions.py to have a look at the field_correction function. After a lot of trial and error, i ended up using the field correction code in sitk_functions.py directly on jupyter.

`start_time = time.time()

read the image

img = sitk.ReadImage("./preprocessed/01_DESS_01_orig.mha")

correct for the magnetic field

creating Otsu mask

otsu = sitk.OtsuThresholdImageFilter()
otsu.SetInsideValue(0)
otsu.SetOutsideValue(1)
otsu.SetNumberOfHistogramBins(200)
mask = otsu.Execute(img)

correct field

corrector = sitk.N4BiasFieldCorrectionImageFilter()
corrector.SetMaskLabel(1)
corrector.SetNumberOfHistogramBins(600)
corrector.SetWienerFilterNoise(10)
corrector.SetBiasFieldFullWidthAtHalfMaximum(15)
corrector.SetMaximumNumberOfIterations([50])
corrector.SetConvergenceThreshold(0.001)
sitkf.origin_to_zero(mask)
sitkf.origin_to_zero(img)
mask.SetSpacing(img.GetSpacing())
img = corrector.Execute(img, mask)

save image to temp

sitk.WriteImage(img, "./preprocessed/01_DESS_01_temp.mha")

print ("-> The total time for image was %d seconds (about %d min)" % ((time.time() - start_time), (time.time() - start_time)/60))`

I ran this code for each file manually, and i found it interesting that the first time i ran it for each one i ended up having the same issue as before about origin and spacing not being the same. However, right after getting the error message and running the code again, the task was completed succesfully.

@sbonaretti sbonaretti changed the title relaxometry 3D model ITK widget + intensity standardization Aug 17, 2020
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

2 participants