MRISnapshot package

Subpackages

Submodules

MRISnapshot.create_report module

MRISnapshot.create_report.calc_sel_slices(img_ulay, img_mask, img_olay, img_olay2, params, sub_index, sub_id)

Select slices that will be used to create snapshots

Parameters:
  • img_ulay – Underlay image

  • img_mask – Mask image

  • img_olay – Overlay image

  • img_olay2 – Second overlay image

  • params – Input parameters

  • sub_index – Index of the subject

  • sub_id – Id of the subject

Return ind_sel:

A list of indices for selected slices

MRISnapshot.create_report.check_foreground_mask(params, nii_mask, nii_olay, nii_olay2)

Check if mask and overlay images have non-zero foreground voxels for slice selection

Parameters:
  • in_nii – Input nifti image

  • sel_vals – List of selected values

Return out_nii:

Output nifti image

MRISnapshot.create_report.copy_edited_js(path_utils, out_dir, report_hdr_txt)

Copy js scripts to QC report folder, while adding hdr text. This function was required to modify QC form columns in js template file dynamically based on user input.

Parameters:
  • path_utils – Path to js template files

  • out_dir – Output folder

  • report_hdr_txt – Header text to add to the js file

MRISnapshot.create_report.copy_js(path_utils, out_dir)

Copy js scripts to QC report folder

Parameters:
  • path_utils – Path to js template files

  • out_dir – Output folder

MRISnapshot.create_report.create_dir(dir_name)

Create output directories

Parameters:

dir_name – Output folder

MRISnapshot.create_report.create_html_report(params, out_dir, dir_subjects_full, dir_snapshots, dir_snapshots_full, dir_subjects, img_info_all, out_report)

Function to create html report from pre-saved image snapshots and meta-data.

Parameters:
  • params – All parameters

  • out_dir – Output directory

  • dir_subjects_full – Output directory for subjects (full path)

  • dir_snapshots – Output directory for snapshots

  • dir_snapshots_full – Output directory for snapshots (full path)

  • dir_subjects – Output directory for subjects

  • img_info_all – Meta data about snapshots

  • out_report – Output report file name

MRISnapshot.create_report.create_report(list_file, config_file, out_dir)

Function to create the QC report.

Parameters:
  • list_file – Image list file

  • config_file – Configuration file

  • out_dir – Output directory

MRISnapshot.create_report.create_snapshots(params, df_images, dir_snapshots_full, out_dir)

Creates and returns image snapshots and meta-data about snapshots. Also creates a QC dataframe to keep QC PASS/FAIL information for initial scans and saves it in the output directory

Parameters:
  • params – Input parameters

  • df_images – Dataframe with image names

  • dir_snapshots_full – Output directory for snapshots (full path)

Return img_info_all:

A dictionary with meta-data about extracted snapshots

MRISnapshot.create_report.crop_nifti(nii_mask, nii_arr, padding_ratio=0.1)

Crops a set of nifti images to the bounding box of the mask. Images are also padded in each direction by the padding ratio

Parameters:
  • nii_mask – Input nifti mask image

  • nii_arr – An array of input nifti images

  • padding_ratio – Padding ratio

Return out_arr:

An array of output nifti images

MRISnapshot.create_report.digitize_olay(nii, num_classes, perc_low=5, perc_high=95)

Simple quick segmentation of overlay image by quantizing intensities. The purpose is to make sure that edge detection on overlay will be smooth. Bins for digitization will be estimated from robust intensity ranges (using percentile values to exclude outliers)

Parameters:
  • nii – Input nifti image

  • num_classes – Number of classes (digits) in output image

Return nii_out:

Output nifti image

MRISnapshot.create_report.extract_snapshot(img_ulay, img_olay, img_olay2, params, curr_view, curr_slice, slice_index, sub_id, dir_snapshots_full, list_sel_slices)

Extracts an image snapshot based on input parameters, and writes it to output folder. Returns the name and caption of the extracted snapshot.

Parameters:
  • img_ulay – Underlay image

  • img_olay – Overlay image

  • img_olay2 – Second overlay image

  • curr_view – View plane to extract the snapshot

  • curr_slice – Slice number to extract the snapshot

  • slice_index – Index of the extracted slice

  • sub_id – Id of the current subject

  • dir_snapshots_full – Output directory for snapshots (full path)

  • list_sel_slices – List of selected slices

Return snapshot_caption:

Caption of the extracted snapshot

Return snapshot_name:

Name of the extracted snapshot

MRISnapshot.create_report.get_img_mat(nii, orient='LPS')

Reorient nifti and get data matrix

Parameters:
  • nii – Input image

  • orient – Desired image orientation

Return img_mat:

Image voxels in a numpy matrix

MRISnapshot.create_report.main()

Script to generate the QC report for an input image dataset.

Parameters:

outdir – Output report directory (full or relative path)

MRISnapshot.create_report.parse_config(df_conf, list_col_names)

Read config list and check params

Parameters:
  • df_conf – Dataframe with the list of configuration parameters

  • list_col_names – List of column names in image list

Return params:

List of all input parameters

MRISnapshot.create_report.read_and_check_images(df_images, params, sub_index, orient='LPS')

Read underlay, mask and overlay image names for a subject from a dataframe, read images as Nifti, reorient them, and check that dimensions are consistent

Parameters:
  • df_images – Input dataframe with image names

  • sub_index – Index of the current subject

  • orient – Desired image orientation

Return qc_ok_flag:

Binary flag that indicates if images are OK and consistent

Return qc_msg:

Text message to report QC issues

Return nii:

Output nifti images

Return img_mat:

Image file names

MRISnapshot.create_report.resize_nifti(nii_arr, interp_order)

Resize image to 1x1x1 mm with size max_size x max_size x max_size

Parameters:
  • nii_arr – An array of input nifti images

  • interp_order – Order of interpolation

Return out_arr:

An array of output nifti images

MRISnapshot.create_report.scale_img_contrast(nii_img, nii_mask, perc_low, perc_high)

Change contrast of the image using percentile values. Image intensities will be mapped to values calculated from the min and max percentiles.

Parameters:
  • nii_img – Input nifti image

  • nii_mask – Input nifti mask

  • perc_low – Lower percentile value to determine new min intensity value

  • perc_high – Higher percentile value to determine new max intensity value

Return nii_out:

Output nifti image

MRISnapshot.create_report.sel_vals_nifti(in_nii, sel_vals)

Selects a set of values from the input image, and resets all other values to 0

Parameters:
  • in_nii – Input nifti image

  • sel_vals – List of selected values

Return out_nii:

Output nifti image

MRISnapshot.prep_data module

MRISnapshot.prep_data.add_img_names(df, in_dir, suffix, col_name)

Finds in the input directory images with a specific suffix (recursively, including nested folders), and adds them to the input dataframe as a new column.

Parameters:
  • df – Input dataframe that keeps the image names

  • in_dir – Input directory

  • suffix – Image suffix

  • col_name – Column name

Returns:

Output dataframe

MRISnapshot.prep_data.main()

Helper script to prepare input files required for QC report creation.

Parameters:
  • indir – Input image directory (full or relative path) (required)

  • s_ulay – Suffix of underlay images (required)

  • outdir – Input image directory (full or relative path) (required)

  • s_mask – Suffix of mask images (optional)

  • s_olay – Suffix of underlay images (optional)

  • s_olay2 – Suffix of underlay images (optional)

MRISnapshot.prep_data.prep_dataset(params)

Function to prepare input files required for QC report creation. Creates two output files in the output directory:

  • list_images.csv: a list with full names of all input image files,

  • config.csv: a list of all configuration parameters and their default values.

Parameters:

params – Input parameters

Module contents