mri.operators.linear.utils#

Functions used for the dictionary learning Compressed Sensing reconstruction.

timer(start, end)[source]#

Give duration time between 2 times in hh:mm:ss.

Parameters
  • start (float) – the starting time.

  • end (float) – the ending time.

Returns

str

Return type

the duration formated in hh:mm:ss.

min_max_normalize(img)[source]#

Center and normalize the given array.

Parameters

img (numpy.ndarray) –

Returns

ndarray

Return type

the center and normalized array.

extract_patches_from_2d_images(img, patch_shape)[source]#

Return flattened patches from the 2d image.

Parameters

img (numpy.ndarray of floats, the input 2d image) – patch_shape: tuple of int, shape of the patches

Returns

patches – dim nb_patches*(patch.shape[0]*patch_shape[1])

Return type

numpy.ndarray of floats, a 2d matrix with

generate_flat_patches(images, patch_size, option='real')[source]#

Generate flat patches the list of images.

The generated images can be either the real, imaginary, complex or modulus of the images.

Parameters
  • image (list of list of np.ndarray of float or complex) – a sublist containing all the images for one subject

  • patch_size (int,) – width of square patches

  • option ({'real', 'imag', 'abs', 'complex'}) –

Returns

flat_patches – The patches flat and concatained as a list

Return type

list of np.ndarray as a GENERATOR

learn_dictionary(flat_patches_subjects, nb_atoms=100, alpha=1, n_iter=1, fit_algorithm='lars', transform_algorithm='lasso_lars', batch_size=100, n_jobs=1, verbose=1)[source]#

Learn the dictionary from a training set.

Parameters
  • flat_patches (generator of 1d array of flat patches (floats)) – a list per subject

  • nb_atoms (int,) – number of components of the dictionary (default=100)

  • alpha (float,) – regulation term (default=1)

  • n_iter (int) – number of iterations (default=1)

  • fit_algorithm ('lars') – for more details see MiniBatchDictionaryLearning from the sklearn library

  • transform_algorithm ('lasso_lars',) – for more details see MiniBatchDictionaryLearning from the sklearn library

  • batch_size (int (default 100),) – number of patches taken per iteration to fit the model

  • n_jobs (int defaul 6,) – number of cpu to run the learning

  • verbose (int default1,) – The level of verbosity

Returns

dico

Return type

MiniBatchDictionaryLearning object