sct_crop_image

Tools to crop an image. Either via command line or via a Graphical User Interface (GUI). See example usage at the end.

usage: sct_crop_image -i <file> [-h] [-o <str>] [-dilate <list>] [-g {0,1}]
                      [-m <file>] [-ref <file>] [-xmin <int>] [-xmax <int>]
                      [-ymin <int>] [-ymax <int>] [-zmin <int>] [-zmax <int>]
                      [-b <int>] [-v <int>]

MANDATORY ARGUMENTS

-i

Input image. Example: t2.nii.gz

OPTIONAL ARGUMENTS

-o

Output image. By default, the suffix ‘_crop’ will be added to the input image.

-dilate

Number of extra voxels to keep around the bounding box on each side. Can be specified as a single number, or a list of 3 numbers separated by x. For example:

  • -dilate 5 will add a margin of 5 voxels in each direction

  • -dilate 2x3x0 will add margin of 2 voxels on each side in the x-axis, 3 voxels on each side in the y-axis, and no extra margin in the z-axis.

-g

Possible choices: 0, 1

0: Cropping via command line | 1: Cropping via GUI. Has priority over -m.

Default: 0

-m

Binary mask that will be used to extract bounding box for cropping the image. Has priority over -ref.

-ref

Image which dimensions (in the physical coordinate system) will be used as a reference to crop the input image. Only works for 3D images. Has priority over min/max method.

-xmin

Lower bound for cropping along X.

Default: 0

-xmax

Higher bound for cropping along X. Setting -1 will crop to the maximum dimension (i.e. no change), -2 will crop to the maximum dimension minus 1 slice, etc.

Default: -1

-ymin

Lower bound for cropping along Y.

Default: 0

-ymax

Higher bound for cropping along Y. Follows the same rules as xmax.

Default: -1

-zmin

Lower bound for cropping along Z.

Default: 0

-zmax

Higher bound for cropping along Z. Follows the same rules as xmax.

Default: -1

-b

If this flag is declared, the image will not be cropped (i.e. the dimension will not change). Instead, voxels outside the bounding box will be set to the value specified by this flag. For example, to have zeros outside the bounding box, use: ‘-b 0’

-v

Possible choices: 0, 1, 2

Verbosity. 0: Display only errors/warnings, 1: Errors/warnings + info messages, 2: Debug mode

Default: 1

EXAMPLES:

  • To crop an image using the GUI (this does not allow to crop along the right-left dimension): ` sct_crop_image -i t2.nii.gz -g 1 `

  • To crop an image using a binary mask: ` sct_crop_image -i t2.nii.gz -m mask.nii.gz `

  • To crop an image using a reference image: ` sct_crop_image -i t2.nii.gz -ref mt1.nii.gz `

  • To crop an image by specifying min/max (you don’t need to specify all dimensions). In the example below, cropping will occur between x=5 and x=60, and between z=5 and z=zmax-1 ` sct_crop_image -i t2.nii.gz -xmin 5 -xmax 60 -zmin 5 -zmax -2 `

  • To crop an image using a binary mask, and keep a margin of 5 voxels on each side in the x and y directions only: ` sct_crop_image -i t2.nii.gz -m mask.nii.gz -dilate 5x5x0 `