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> [-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>] [-h] [-v <int>] [-profile-time [<file>]]
                      [-trace-memory [<folder>]]

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’

MISC ARGUMENTS

-v

Possible choices: 0, 1, 2

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

Default: 1

-profile-time

Enables time-based profiling of the program, dumping the results to the specified file.

If no file is specified, human-readable results are placed into a ‘time_profiling_results.txt’ document in the current directory (’/home/docs/checkouts/readthedocs.org/user_builds/spinalcordtoolbox/checkouts/stable/documentation/source’). If the specified file is a .prof file, the file will instead be in binary format, ready for use with common post-profiler utilities (such as snakeviz).

-trace-memory

Enables memory tracing of the program.

When active, a measure of the peak memory (in KiB) will be output to the file peak_memory.txt. Optionally, developers can also modify the SCT code to add additional snapshot_memory() calls. These calls will ‘snapshot’ the memory usage at that moment, saving the memory trace at that point into a second file (memory_snapshots.txt).

By default, both outputs will be placed in the current directory (’/home/docs/checkouts/readthedocs.org/user_builds/spinalcordtoolbox/checkouts/stable/documentation/source’). Optionally, you may provide an alternative directory (-trace-memory <dir_name>), in which case all files will be placed in that directory instead. Note that this WILL incur an overhead to runtime, so it is generally advised that you do not run this in conjunction with the time profiler or in time-sensitive contexts.

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 `