ReubenDo / MRIPreprocessor

Apache License 2.0
15 stars 3 forks source link

Skull stripping file doesn't exist error #3

Open inikishev opened 4 months ago

inikishev commented 4 months ago

Hi! I ran the code

ppr = Preprocessor({'T1':r"/mnt/d/vkr/new/nii/1/z/301_ax_t1w_3d_tfe_.nii.gz",
                    'T2':r"/mnt/d/vkr/new/nii/1/z/401_ax_st2w_tse.nii.gz",
                    'T1c':r"/mnt/d/vkr/new/nii/1/z/701_ax_t1w_3d_tfe_c.nii.gz",
                    'FLAIR':r"/mnt/d/vkr/new/nii/1/z/501_ax_sflair_longtr.nii.gz"},
                    output_folder = r"/mnt/d/vkr/new/nii_preprocessed",
                    reference='T1',
                    label=None,
                    prefix='patient001_',
                    already_coregistered=False,
                    mni=True,
                    crop=True)

ppr.run_pipeline()

this is what it printed (i added some prints to some defs after to try to see where it fails)

[INFO] Registering to 1x1x1mm MNI space using ANTsPy
T1 is used as reference
[INFO] Registration using ANTsPy for T2 with T1 as reference
[INFO] Registration using ANTsPy for T1c with T1 as reference
[INFO] Registration using ANTsPy for FLAIR with T1 as reference
[INFO] Performing Skull Stripping using HD-BET
`run_hd_bet` with `/mnt/d/vkr/new/nii_preprocessed/skullstripping/patient001_T1.nii.gz`
File: /mnt/d/vkr/new/nii_preprocessed/coregistration/patient001_T1.nii.gz
preprocessing...
image shape after preprocessing:  (126, 155, 131)
prediction (CNN id)...
0
exporting segmentation...

I am having the following issue:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_32252/3775332851.py in ?()
     12                     already_coregistered=False,
     13                     mni=True,
     14                     crop=True)
     15 
---> 16 ppr.run_pipeline()

[~/programming/tools/stuff/stuff/found/MRIPreprocessor/mri_preprocessor.py](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kai/programming/experiments/vkr/~/programming/tools/stuff/stuff/found/MRIPreprocessor/mri_preprocessor.py) in ?(self)
    181     def run_pipeline(self):
    182         self._run_coregistration()
    183         if self.skull_stripping:
--> 184             self._run_skullstripping()
    185         if self.crop:
    186             self._run_cropping()

[~/programming/tools/stuff/stuff/found/MRIPreprocessor/mri_preprocessor.py](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kai/programming/experiments/vkr/~/programming/tools/stuff/stuff/found/MRIPreprocessor/mri_preprocessor.py) in ?(self)
    154         modalities_tosk.remove(self.reference)
    155         for mod in modalities_tosk:
    156             registered_mod = os.path.join(self.coregistration_folder, f"{self.prefix}{mod}.nii.gz")
    157             skullstripped_mod = os.path.join(self.skullstrip_folder, f"{self.prefix}{mod}.nii.gz")
--> 158             self._apply_mask(input=registered_mod, output=skullstripped_mod, reference=ref_sk, mask=mask_sk)
    159 
    160         if not self.label is None:
    161             registered_lab = os.path.join(self.coregistration_folder, f"{self.prefix}Label.nii.gz")

[~/programming/tools/stuff/stuff/found/MRIPreprocessor/mri_preprocessor.py](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kai/programming/experiments/vkr/~/programming/tools/stuff/stuff/found/MRIPreprocessor/mri_preprocessor.py) in ?(self, input, output, reference, mask)
     78     def _apply_mask(self, input, output, reference, mask):
     79         # Reorient in case HD-BET changed the orientation of the raw file
     80         input_img = sitk.ReadImage(input)
---> 81         ref_img = sitk.ReadImage(reference)
     82         output_img = sitk.Resample(
     83             input_img,
     84             ref_img,

[~/miniconda3/envs/mriprep/lib/python3.11/site-packages/SimpleITK/extra.py](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kai/programming/experiments/vkr/~/miniconda3/envs/mriprep/lib/python3.11/site-packages/SimpleITK/extra.py) in ?(fileName, outputPixelType, imageIO)
    371         reader.SetFileNames([str(name) for name in fileName])
    372 
    373     reader.SetImageIO(imageIO)
    374     reader.SetOutputPixelType(outputPixelType)
--> 375     return reader.Execute()

[~/miniconda3/envs/mriprep/lib/python3.11/site-packages/SimpleITK/SimpleITK.py](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kai/programming/experiments/vkr/~/miniconda3/envs/mriprep/lib/python3.11/site-packages/SimpleITK/SimpleITK.py) in ?(self)
   8426         type to be same as the file. If the pixel type is specified then the itk::ConvertPixelBuffer will be used to convert the pixels.
   8427 
   8428 
   8429         """
-> 8430         return _SimpleITK.ImageFileReader_Execute(self)

RuntimeError: Exception thrown in SimpleITK ImageFileReader_Execute: /tmp/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:97:
sitk::ERROR: The file "/mnt/d/vkr/new/nii_preprocessed/skullstripping/patient001_T1.nii.gz" does not exist.

this is the coregistration folder, it worked image

and this is the skullstripping folder, which caused the issue. For some reason there is no patient001_T1.nii.gz in it image

inikishev commented 4 months ago

this can be fixed by going into mri_preprocessor.py and changing line 151

run_hd_bet(ref_co, ref_sk, mode="fast", device=self.device, do_tta=False)

into

run_hd_bet(ref_co, ref_sk, mode="fast", device=self.device, do_tta=False, bet=True)