BBillot / SynthSeg

Contrast-agnostic segmentation of MRI scans
Apache License 2.0
372 stars 94 forks source link

Resampled image is not saved #74

Closed Ede1994 closed 11 months ago

Ede1994 commented 12 months ago

I've tried to use your tool and to save the resampled image. My code:

def synthSeg(src_path, dst_path, resample_path):
    command = ["mri_synthseg", '--i', src_path, '--o', dst_path, '--robust', '--resample', resample_path]

    with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as proc:
        for line in proc.stdout:
            print('%s: %s', command[0], line.strip())

        for line in proc.stderr:
            print('%s (stderr): %s', command[0], line.strip())
    return

synthSeg(src_path=seg_p,
         dst_path='/tmp/restmp/results/99_test.nii.gz',
         resample_path='/tmp/restmp/results/98_resample.nii.gz')

The output was the following:

%s: %s mri_synthseg SynthSeg-robust 2.0
%s: %s mri_synthseg using 1 thread
%s: %s mri_synthseg predicting 1/1
%s: %s mri_synthseg 
%s: %s mri_synthseg 1/1 [==============================] - ETA: 
%s: %s mri_synthseg 1/1 [==============================] - 91s 91s/step
%s: %s mri_synthseg 
%s: %s mri_synthseg segmentation  saved in:    [/tmp/restmp/results/99_test.nii.gz]
%s: %s mri_synthseg resampled image saved in:  [/tmp/restmp/results/98_resample.nii.gz]
%s: %s mri_synthseg 
%s: %s mri_synthseg If you use this tool in a publication, please cite:
%s: %s mri_synthseg SynthSeg: Segmentation of brain MRI scans of any contrast and resolution without retraining
%s: %s mri_synthseg B. Billot, D.N. Greve, O. Puonti, A. Thielscher, K. Van Leemput, B. Fischl, A.V. Dalca, J.E. Iglesias
%s: %s mri_synthseg Medical Image Analysis, accepted for publication.
%s: %s mri_synthseg 
%s: %s mri_synthseg Robust machine learning segmentation for large-scale analysis of heterogeneous clinical brain MRI datasets
%s: %s mri_synthseg B. Billot, C. Magdamo, Y. Cheng, S.E. Arnold, S. Das, J.E. Iglesias
%s: %s mri_synthseg PNAS, accepted for publication.

But the resampled image is not saved, only the regular output (99_test.nii.gz).

BBillot commented 11 months ago

Are you sure that you want to save the results under different numbers: 99 for the segmentation and 98 for the resampled image ? Is it possible that you're not looking for the right file ?

Anyway, it seems like you've coded a wrapper around the FreeSurfer command (as opposed to the GitHub command). Have you tried calling mri_synthseg directly from the terminal ? This should work, and if it does, it means there's something wrong with your wrapper, although it looks correct to me.

Ede1994 commented 11 months ago

You're right. It works fine in the terminal. I don't know exactly why the wrapper is causing a problem, because otherwise it works.