niftynet.io.misc_io module

infer_ndims_from_file(file_path)[source]
create_affine_pixdim(affine, pixdim)[source]

Given an existing affine transformation and the pixel dimension to apply, create a new affine matrix that satisfies the new pixel dimension.

Parameters:
  • affine – original affine matrix
  • pixdim – pixel dimensions to apply
Returns:

load_image(filename)[source]
correct_image_if_necessary(img)[source]
rectify_header_sform_qform(img_nii)[source]

Look at the sform and qform of the nifti object and correct it if any incompatibilities with pixel dimensions

Parameters:img_nii
Returns:
do_reorientation(data_array, init_axcodes, final_axcodes)[source]

Performs the reorientation (changing order of axes)

Parameters:
  • data_array – Array to reorient
  • init_axcodes – Initial orientation
  • final_axcodes – Target orientation
Return data_reoriented:
 

New data array in its reoriented form

do_resampling(data_array, pixdim_init, pixdim_fin, interp_order)[source]

Performs the resampling

Parameters:
  • data_array – Data array to resample
  • pixdim_init – Initial pixel dimension
  • pixdim_fin – Targeted pixel dimension
  • interp_order – Interpolation order applied
Return data_resampled:
 

Array containing the resampled data

save_data_array(filefolder, filename, array_to_save, image_object=None, interp_order=3, reshape=True)[source]

write image data array to hard drive using image_object properties such as affine, pixdim and axcodes.

expand_to_5d(img_data)[source]

Expands an array up to 5d if it is not the case yet :param img_data: :return:

save_volume_5d(img_data, filename, save_path, affine=array([[ 1., 0., 0., 0.], [ 0., 1., 0., 0.], [ 0., 0., 1., 0.], [ 0., 0., 0., 1.]]))[source]

Save the img_data to nifti image

Parameters:
  • img_data – 5d img to save
  • filename – filename under which to save the img_data
  • save_path
  • affine – an affine matrix.
Returns:

split_filename(file_name)[source]
squeeze_spatial_temporal_dim(tf_tensor)[source]

Given a tensorflow tensor, ndims==6 means:

[batch, x, y, z, time, modality]

this function removes x, y, z, and time dims if the length along the dims is one.

Returns:squeezed tensor
touch_folder(model_dir)[source]

This function returns the absolute path of model_dir if exists otherwise try to create the folder and returns the absolute path.

resolve_module_dir(module_dir_str, create_new=False)[source]
to_absolute_path(input_path, model_root)[source]
resolve_checkpoint(checkpoint_name)[source]
get_latest_subfolder(parent_folder, create_new=False)[source]
image3(name, tensor, max_outputs=3, collections=('summaries', ), animation_axes=(1, ), image_axes=(2, 3), other_indices=None)[source]

Summary for higher dimensional images

Parameters:
  • name – string name for the summary
  • tensor – tensor to summarize. Should be in the range 0..255. By default, assumes tensor is NDHWC, and animates (through D) HxW slices of the 1st channel.
  • collections – list of strings collections to add the summary to
  • animation_axes=[1],image_axes=[2,3]
image3_sagittal(name, tensor, max_outputs=3, collections=('summaries', ))[source]
image3_coronal(name, tensor, max_outputs=3, collections=('summaries', ))[source]
image3_axial(name, tensor, max_outputs=3, collections=('summaries', ))[source]
set_logger(file_name=None)[source]