PET and CT cropping scripts#

cg_set_com(varargin)#

Use center-of-mass (COM) to roughly correct for differences in the position between image and template.

Parameters:

varargin (inputs) – Varargin explanation here.

Returns:

mapping – Mapping of the new corrected image(???).

Return type:

(4,4) array

mask_crop_align(imgfile, output_folder, output_filename, brainmask_idx, reference_image, options)#

Crops nifti image to the given indices and realigns it to SPM template.

Selected indices are expected to contain the brain. This selected subset of the image is realigned to slightly modified SPM template. SPM is used for realigning. Can be used for PET or CT image. Aligning is done using spm_coregister_estimate.

Parameters:
  • imgfile (char array) – Full path to nifti-file, e.g. /my/nifti/file.nii

  • output_folder (char array) – Folder for the cropped image and for temporary files during execution.

  • output_filename (char_array) – Filename for the cropped image.

  • brainmask_idx (Vx1 array) – Linear indices corresponding the brainmask.

  • reference_image (char array) – Image that is used for coregistering.

  • cropping_parameters (6x1 double array or []) – Custom parameters are given in format of [x_min x_max y_min y_max z_min z_max]. The values are min and max indices in each dimension.

  • dilation_nr (int, default : 12) – How many times dilation is run on the original mask. Bigger number means looser crop. If set to 0, crop is constrained to the original mask.

  • compress_output (int, default: 0) – Controls whether the final output image is .nii or .nii.gz.

  • save_sum (char array, default: 0) – Save sum image of the final image.

  • save_mask (int, default: 0) –

    Controls whether the mask is also saved.

    • 0, mask image is not saved.

    • 1, mask image is saved to the output_folder.

  • verbose (int, default: 0) –

    Print and save additional information.

    • 0, no printing.

    • 1, prints additional information about program execution.

Returns:

  • img_output_filedir (char array) – Filepath to the final cropped image.

  • cropping_parameters (1x6 double array) – Cropping bounds used in [x_min, x_max, y_min, y_max, z_min, z_max] format.

  • mapping (4x4 array) – Mapping used to correct origin point to center of mass.

nifti_conversion(dicom_path, output_folder, varargin)#

Matlab wrapper for dcm2niix.

Parameters:
  • dicom_path (char array) – Folder where the dicom files are.

  • output_folder (char array) – Where the nifti and json are created.

  • varargin{1} (char array) – User specified name for the new files, if not given, AC number taken from dicominfo is used.

pet_ct_brainmask_crop(PETfile, pet_output_folder, CTfile, ct_output_folder, brainmask_idx, template_image, options)#

Crops brain from PET and CT image and aligns them.

PET image is aligned to SPM template, and CT is aligned to PET image.

Parameters:
  • PETfile (char array) – Full path to PET file, e.g. /my/nifti/file.nii

  • pet_output_folder (char array) – Folder for the cropped PET image and for temporary files during execution.

  • CTfile (char array) – Full path to CT file, e.g. /my/nifti/file.nii. Must be resliced to PET image dimensions first.

  • ct_output_folder (char array) – Folder for the cropped CT image and for temporary files during execution.

  • brainmask_idx (Vx1 array) – Linear indices corresponding the brainmask.

  • template_image (char array) – Full path to the template image that is used for aligning the PET image.

  • pet_output_filename (char array) – Filename for the cropped image.

  • ct_output_filename (char array) – Filename for the cropped image.

  • dilation_nr (int, default : 12) – How many times dilation is run on the original mask. Bigger number means looser crop. If set to 0, crop is constrained to the original mask.

  • compress_output (int, default: 0) – Controls whether the final output image is .nii or .nii.gz.

  • save_mask (int, default: 0) –

    Controls whether the mask is also saved.

    • 0, mask image is not saved.

    • 1, mask image is saved to the pet_output_folder.

  • verbose (int, default: 0) –

    Print and save additional information.

    • 0, no printing.

    • 1, prints additional information about program execution.