Weird results using propseg

Me again,

Using dev version, after 4.2.1

Trying to obtain the CSF segmentation using sct_propseg, we encounter the following issues.
The code gives an error at some point but is able to extract images [EXPLAINED BELOW]


extop@:TT1$ sct_propseg -i T1.nii -c t1 -CSF

--
Spinal Cord Toolbox (dev)


Create temporary folder (/tmp/sct-20200224122453.203680-label_vertebrae-r4uo4yt7)...
Remove temporary files...
rm -rf /tmp/sct-20200224122453.204806-asblo5d9
/home/extop/sct_dev/bin/isct_propseg -t t1 -o ./ -verbose -CSF -i '/T1.nii' -init-centerline /tmp/sct-20200224122453.203680-label_vertebrae-r4uo4yt7/centerline_optic.nii.gz -centerline-binary 

Check consistency of segmentation...

Create temporary folder (/tmp/sct-20200224122539.013849-propseg-46lybd2z)...
tmp.segmentation.nii.gz
tmp.centerline.nii.gz

Get data dimensions...
usage: sct_image -i <file> [<file> ...] [-h] [-o <file>] [-pad <list>]
                 [-pad-asym <list>] [-split {x,y,z,t}] [-concat {x,y,z,t}]
                 [-remove-vol <list>] [-keep-vol <list>]
                 [-type {uint8,int16,int32,float32,complex64,float64,int8,uint16,uint32,int64,uint64}]
                 [-copy-header <file>] [-getorient]
                 [-setorient {RIP,LIP,RSP,LSP,RIA,LIA,RSA,LSA,IRP,ILP,SRP,SLP,IRA,ILA,SRA,SLA,RPI,LPI,RAI,LAI,RPS,LPS,RAS,LAS,PRI,PLI,ARI,ALI,PRS,PLS,ARS,ALS,IPR,SPR,IAR,SAR,IPL,SPL,IAL,SAL,PIR,PSR,AIR,ASR,PIL,PSL,AIL,ASL}]
                 [-setorient-data {RIP,LIP,RSP,LSP,RIA,LIA,RSA,LSA,IRP,ILP,SRP,SLP,IRA,ILA,SRA,SLA,RPI,LPI,RAI,LAI,RPS,LPS,RAS,LAS,PRI,PLI,ARI,ALI,PRS,PLS,ARS,ALS,IPR,SPR,IAR,SAR,IPL,SPL,IAL,SAL,PIR,PSR,AIR,ASR,PIL,PSL,AIL,ASL}]
                 [-mcs] [-omc] [-display-warp] [-v {0,1,2}]
sct_image: error: unrecognized arguments: EXT/T1.nii

but the CSF_segmentation exists in all slices and is centered wrongly.

I believe to have found the origin of the first error. We are running the analysis in a mounted unit and i think the program loses the correct path.
It should not be EXT but the name of the unit.
EDIT: Probably it origins with the name of the unit, since it is ‘TOSHIBA EXT’ and the part ‘TOSHIBA+space’ gets lost eventually

sct_image: error: unrecognized arguments: EXT/T1.nii

Can you confirm your results of sct_propseg?

When using sct_deepseg_sc, this does not happen. Could be possible to include the -CSF option to that module also?

Thank you very much!

Indeed, space are not well interpreted in UNIX. In fact, space should always be avoided in folder/file names. I’ve added a special page in the London’20 SCT course (page 23)

Hi Julien,

Just wanted to say that we tried it in the local disk and the error disappeared.

Nevertheless, the weird results still appearing. See the screenshoot

Indeed, the CSF output is not cropped the same way the output cord segmentation is. You can just crop it using this command:

# Dilate cord seg by 50 pixel in the axial plane to encompass CSF seg
sct_maths -i CORD_SEG.nii.gz -dilate 50,50,1 -o CORD_SEG_DIL.nii.gz
# Use dilated cord as a mask to crop the CSF seg along the Z-dimension
sct_crop_image -i CSF_SEG.nii.gz -m CORD_SEG_DIL.nii.gz -o CSF_SEG_CROPPED.nii.gz 

Cheers,
Juilien

Hello Julien,

Sorry to insist and i apologize for my delay.

sct_propseg keeps generating the wrong segmentation.

As you can see, the SC segmentation starts ‘mid-air’.
We wanted to use the centerline produced from sct_deepseg_sc in order to obtain the CSF segmentation BUT this command does not produce the centerline file anymore. I think that in older versions this output was created with the command, perhaps I am wrong.

And besides cropping the segmentation above the indicated slice the usage of the -up or -down flags yields no difference.

Different approaches would be to be able to segment CSF with the deepseg_sc(maybe deepseg_csf?) or that deepseg_sc generates a centerline file, in order to propagate from it using propseg with the -CSF flag.

Really looking forward for your answer :wink:
thanks!

aran

Hi @Aran,

first of all i will need you to send me the Terminal output so i can verify (i) what exact syntax you typed and (ii) what SCT version you are running. Also, if you have an example dataset that I could use, that would help me help you.

We wanted to use the centerline produced from sct_deepseg_sc in order to obtain the CSF segmentation BUT this command does not produce the centerline file anymore.

no need to do that-- in SCT 4.2.2 (and few releases before), sct_propseg and sct_deepseg_sc are using the exact same method to obtain the centerline. The method is implemented in sct_get_centerline (which you could run separately if you wish, but again, there is no need because this is what propseg is calling).

Hi Julien,

I have just sent you the files via WeTransfer.

The syntax that we used to obtain the images is very simple


extop@/media/extop/OriginalFiles/20180915$ sct_get_centerline -i mSAG_3D-T1.nii -c t1

--
Spinal Cord Toolbox (dev)

Remove temporary files...
rm -rf /tmp/sct-20200305073918.390637-mntxwjuu

Done! To view results, type:
fsleyes mSAG_3D-T1.nii -cm greyscale /media/extop/20180915/mSAG_3D-T1_centerline.nii.gz -cm red -a 100.0 &

extop@/media/extop/20180915$ sct_deepseg_sc -i mSAG_3D-T1.nii -c t1 

--
Spinal Cord Toolbox (dev)

Config deepseg_sc:
  Centerline algorithm: svm
  Brain in image: True
  Kernel dimension: 2d
  Contrast: t1
  Threshold: 0.15

Create temporary folder (/tmp/sct-20200305074049.808128-19786nwr)...
Reorient the image to RPI, if necessary...
Finding the spinal cord centerline...
Remove temporary files...
rm -rf /tmp/sct-20200305074114.669497-7rz4g0vh
Cropping the image around the spinal cord...
Normalizing the intensity...
Segmenting the spinal cord using deep learning on 2D patches...
Reassembling the image...
Resampling the segmentation to the native image resolution using linear interpolation...
Binarizing the resampled segmentation...
Removing small objects above slice #78
Removing small objects above slice #78
Removing small objects above slice #78
Removing small objects above slice #78
Removing small objects above slice #78
Removing small objects above slice #78
Removing small objects above slice #78
Compute shape analysis: 100%|################| 79/79 [00:00<00:00, 277.63iter/s]
Found isolated voxels on slice 0, Removing them
Remove temporary files...
rm -rf /tmp/sct-20200305074049.808128-19786nwr

Done! To view results, type:
fsleyes /media/extop/20180915/mSAG_3D-T1.nii -cm greyscale /media/extop/20180915/mSAG_3D-T1_seg.nii -cm red -a 70.0 &

extop@/media/extop/20180915$ sct_propseg -i mSAG_3D-T1.nii -c t1

--
Spinal Cord Toolbox (dev)


Create temporary folder (/tmp/sct-20200305074201.603702-label_vertebrae-8gd0q7qo)...
Remove temporary files...
rm -rf /tmp/sct-20200305074201.604404-bczi8f53
/home/extop/sct_dev/bin/isct_propseg -t t1 -o ./ -verbose -i '/media/extop/20180915/mSAG_3D-T1.nii' -init-centerline /tmp/sct-20200305074201.603702-label_vertebrae-8gd0q7qo/centerline_optic.nii.gz -centerline-binary # in /media/extop/20180915
    
Check consistency of segmentation...

Create temporary folder (/tmp/sct-20200305074225.260784-propseg-1ck98h70)...
tmp.segmentation.nii.gz
tmp.centerline.nii.gz

tmp.segmentation_RPI_c.nii.gz
rm -rf /tmp/sct-20200305074906.272133-propseg-ldg7c_fz
Copy header input --> output(s) to make sure qform is the same.
WARNING: File /home/extop/Escritorio/mSAG_3D-T1_seg.nii.gz already exists. Will overwrite it.
WARNING: File /home/extop/Escritorio/mSAG_3D-T1_centerline.nii.gz already exists. Will overwrite it.

Done! To view results, type:
fsleyes /home/extop/20180915/mSAG_3D-T1.nii.gz -cm greyscale /home/extop/20180915/mSAG_3D-T1_seg.nii.gz -cm red -a 100.0 &

We are using a dev version located between the 4.2.1 and 4.2.2. We will download the 4.2.2 right away and try to do the same

Thanks,
aran

Dear @jcohenadad,

We have found a way to bypass the problem.

Since sct_deepseg_sc works really good, we multiplied the deepseg segmentation and the output from sct_get_centerline in order to have a centerline with the right dimensions.
After that, we used this centerline in sct_propseg with the -init-centerline flag.

The results are not bad. Although, we were wondering if there is a way to get a better ones. See screenshot.

thanks!

aran

Hi,

After that, we used this centerline in sct_deepseg_sc with the -init-centerline flag.

Assuming you meant sct_propseg (not sct_deepseg_sc), then yes, this is an option. However, this is not the most optimal option because the output segmentation from deepseg_sc provides a more accurate centerline than sct_get_centerline. If you directly input the segmentation from deepseg_sc as -init-centerline with propseg, it will calculate the center of mass of the input seg and provide a much more accurate centerline. Syntax looks like this:

sct_deepseg_sc -i mSAG_3D-T1.nii.gz -c t1
sct_propseg -i mSAG_3D-T1.nii.gz -c t1 -init-centerline mSAG_3D-T1_seg.nii.gz -CSF

Now, regarding your question if we can get better CSF segmentation: currently you cannot, although we are currently working on a deep learning based tool for CSF segmentation. Stay tuned!

Hi,

Assuming you meant sct_propseg (not sct_deepseg_sc ), then yes, this is an option.

Yes, totally my bad. I have just edited it.

If you directly input the segmentation from deepseg_sc as -init-centerline with propseg,

Thanks for this idea! We will try it right away.

Looking forward for the deep learning tool for CSF segmentation!
thanks,

aran

1 Like