Sct_get_centerline -fitseg does not extrapolate

Hi all,

I’m trying to get the center line of a t2s image in the lumbar region. With the image not having the best quality the optic method fails quite often. Since I have good manual segmentation’s I tried to switch to -fitseg. This works quite well in the slices were I have the binary mask but I get empty slices for the last 1-2 slices where the cord ended. According to the help message of the function this should not happen:

- fitseg: fit a regularized centerline on an already-existing cord segmentation. It will interpolate if slices are missing and extrapolate beyond the segmentation boundaries (i.e., every axial slice will exhibit a centerline pixel).

So maybe I misunderstand the function or am using the commands wrong?

sct_get_centerline
-i binary_sc_mask.nii
-method fitseg
-o img_centerline.nii

Or there might be an error. There is the -igt (File name of ground-truth centerline or segmentation (binary nifti)) argument which I also tried to use in combination with the segmentation but it produced center lines at the edge of the cord.

It seems like I need to have the center line even in slices where there is no cord anymore since following functions like sct_straighten_spinalcord start to delete slices or shift them. (This also happens when I directly give the segmentation to the straighten function. I assume this function just runs the get center line command at the start if a segmentation is provided.)

On a side note, sct_straighten_spinalcord mv or cp files from the /tmp into the current directory ./. I’m not sure if this is intentional but it is a bit weird, since I usually run the bash scripts from a separate folder, to have these files pop up there or even in the home directory.

[...]
Generate output files...
mv /tmp/sct-20230316152744.662160-straighten_spinalcord-27m1rutb/tmp.curve2straight.nii.gz ./warp_curve2straight.nii.gz
File created: ./warp_curve2straight.nii.gz
mv /tmp/sct-20230316152744.662160-straighten_spinalcord-27m1rutb/tmp.straight2curve.nii.gz ./warp_straight2curve.nii.gz
File created: ./warp_straight2curve.nii.gz
cp /tmp/sct-20230316152744.662160-straighten_spinalcord-27m1rutb/tmp.anat_rigid_warp.nii.gz ./straight_ref.nii.gz
[...]

Hi @kuech, thank you for reaching out!

With the image not having the best quality the optic method fails quite often.

Indeed, optic is not great for lumbar cords, but have you tried the recent addition of a lumbar segmentation model, that you can use with:

sct_deepseg -i IMAGE -task seg_lumbar_sc_t2w

This works quite well in the slices were I have the binary mask but I get empty slices for the last 1-2 slices where the cord ended. According to the help message of the function this should not happen:
- fitseg: fit a regularized centerline on an already-existing cord segmentation. It will interpolate if slices are missing and extrapolate beyond the segmentation boundaries (i.e., every axial slice will exhibit a centerline pixel).

You are absolutely correct, the help mentions extrapolation, but the fitseg algorithm only does interpolation (ie: find points between two points), not extrapolation (ie: find points outside of a range of points). In the past, the extrapolation was possible, but it caused other issues, so we decided to remove it and forgot to update the help message. Given the need for extrapolation, we will probably create a new flag “-extrapolate”, which will do what is explained in the help message (by default it will be turned off to not break retro-compatibility). Thank you for noticing this issue! For now, a quick fix for you is to add the segmentation at the edge slices.

There is the -igt (File name of ground-truth centerline or segmentation (binary nifti)) argument which I also tried to use in combination with the segmentation but it produced center lines at the edge of the cord.

The flag -igt was used for internal purpose and will be removed in the next release. Sorry for the confusion.

On a side note, sct_straighten_spinalcord mv or cp files from the /tmp into the current directory ./. I’m not sure if this is intentional but it is a bit weird, since I usually run the bash scripts from a separate folder, to have these files pop up there or even in the home directory.

This is an excellent comment, which we have been discussing internally for the past few years. Some users prefer to have outputs ‘locally’ (ie: curdir), but some, like yourself, don’t work locally and as a result having files created locally is indeed impractical. We will have another internal discussion, and we might end up opting for outputting every file at the location of the -i file by default.

We will shortly add existing/new GitHub issues in this forum thread.

To follow-up on @jcohenadad’s remark, here are the associated GitHub issues that have been created:

  • #3377: Argument ‘-igt’ is not used and should be removed (in-progress, see #4068)
  • #3531: Wrong behaviour of ‘fitseg’ algorithm: the output centerline is not extrapolated
  • #4070: Reconsider the default location for CLI script output files
1 Like

Thank you very much for the quick response.

Indeed, optic is not great for lumbar cords, but have you tried the recent addition of a lumbar segmentation model , that you can use with:

sct_deepseg -i IMAGE -task seg_lumbar_sc_t2w

Yes, I tried both propseg and deepseg including the new task, but the results were very mixed, ranging from decent to segmenting something in the vertebra. At the moment I’m doing the segmentation completely manually until I find something robust. Specially functional image-series produce bad results even after motion correction and taking the mean.

This is an excellent comment, which we have been discussing internally for the past few years. Some users prefer to have outputs ‘locally’ (ie: curdir), but some, like yourself, don’t work locally and as a result having files created locally is indeed impractical. We will have another internal discussion, and we might end up opting for outputting every file at the location of the -i file by default.

That would be great, or having the option the specify an output directory as for example in sct_fmri_moco. There are 1-2 other functions which generate these files, but on the top of my head I only remember sct_register_to_template creating a straightening.cache file.

Thank you for pointing this out. I agree, some of SCT’s scripts contain an -ofolder option for specifying the output directory, but some scripts lack this option.

Of the scripts that you used, which were missing this option? We can prioritize adding this option to those scripts as a short-term solution, if that would be helpful. :slightly_smiling_face:

Of the scripts that you used, which were missing this option? We can prioritize adding this option to those scripts as a short-term solution, if that would be helpful.

Thank you very much. Since I usually work with scripts and this just requires a line to either move or delete the files, its no pressing issue for me. I just wanted to bring it to your attention, in case this behavior was unintentional. I checked the scripts I’m currently using and sct_straighten_spinalcord and sct_register_to_template are the 2 commands that I saw. (The register creates a straighten.cache)

2 Likes

Just as a follow-up, I’m writing to mention that SCT v6.0 has been released, and that two of the issues described in this thread have been fixed for the v6.0 release. :slight_smile:

  • #3377 : Argument ‘-igt’ is not used and should be removed
  • #3531 : Wrong behaviour of ‘fitseg’ algorithm: the output centerline is not extrapolated