A question about sct_maths -dilate

Dear SCT team,

I would like to ask a very simple question- how does sct_maths -dilate work on a binary cord segmentation?
I have binary cord segmentation, I would like to dilate it a certain amount and I leave the default options for sct_maths dilate.
For some of my slices, it works like the following (white is original, blue is dilated by 3):

Apologies in advance if I am missing something very obvious!

Thank you very much!

However, for some other slice, the dilated mask looks like this:

I am wondering why sometimes the dilation sometimes look 'non-'uniform like in the last example?

Hi Merve,

Can you please upload:

  • your input mask
  • the exact command you ran
  • SCT version


Thanks a lot for the quick reply, Julien!

Here are the relevant info

SCT info:

  • version: 6.1
  • path: /usr/local/sct_6.1
    OS: linux (Linux-5.15.0-89-generic-x86_64-with-glibc2.35)

sct_maths -i sub-308_ses-02spinalcord_task-EM_bold_mc2_mean_seg.nii.gz -dilate 3 -o sub-308_ses-02spinalcord_task-EM_bold_mc2_mean_seg_dilated3.nii.gz

sub-308_ses-02spinalcord_task-EM_bold_mc2_mean_seg.nii.gz (669 Bytes)

Thanks for the image–

The command indicates that you asked for a dilation with an isotropic kernel of 3 voxels, which means that the voxels with value 1 will be dilated by 3 voxels along X, Y, and Z.

Look at a sagittal view of your mask:


Given the thick axial slices of your scans and the curvature of the spinal cord, you see how dilation produces the result you observed.

In your case I recommend 2D axial kernel:

sct_maths -i sub-308_ses-02spinalcord_task-EM_bold_mc2_mean_seg.nii.gz -dilate 3 -shape disk -dim 2 -o sub-308_ses-02spinalcord_task-EM_bold_mc2_mean_seg_dilated3.nii.gz

Which outputs something probably closer to what you expected:



Hi Julien,

Thank you very much, super helpful as usual!

Oh, I see! Okay, I will be using a 2D axial kernel as you suggested.

Thanks a lot again!
Kind regards,