xlearn.utils

Module containing utility routines

Functions:

nor_data(img)

Normalize the image

check_random_state(seed)

Turn seed into a np.random.RandomState instance If seed is None, return the RandomState singleton used by np.random.

extract_patches(image, patch_size, step[, ...])

Reshape a 2D image into a collection of patches The resulting patches are allocated in a dedicated array.

reconstruct_patches(patches, image_size, step)

Reconstruct the image from all of its patches.

img_window(img, window_size)

Function Description

extract_3d(img, patch_size, step)

Function Description

class xlearn.utils.RECONmonitor(recon_target)[source]

Bases: object

initial_plot(img_input)[source]
update_plot(epoch, img_diff, img_rec, plot_x, plot_loss)[source]
xlearn.utils.angles(nang, ang1=0.0, ang2=180.0)[source]
xlearn.utils.center(prj, cen)[source]
xlearn.utils.check_random_state(seed)[source]

Turn seed into a np.random.RandomState instance If seed is None, return the RandomState singleton used by np.random. If seed is an int, return a new RandomState instance seeded with seed. If seed is already a RandomState instance, return it. Otherwise raise ValueError.

Parameters

seed (type) – Description.

xlearn.utils.expimg(img)[source]
xlearn.utils.extract_3d(img, patch_size, step)[source]

Function Description

Parameters
  • img (define img)

  • patch_size (describe patch_size)

  • step (describe step)

Returns

patches (describe patches)

xlearn.utils.extract_patches(image, patch_size, step, max_patches=None, random_state=None)[source]

Reshape a 2D image into a collection of patches The resulting patches are allocated in a dedicated array.

Parameters
  • image (array, shape = (image_height, image_width) or) – (image_height, image_width, n_channels) The original image data. For color images, the last dimension specifies the channel: a RGB image would have n_channels=3.

  • patch_size (tuple of ints (patch_height, patch_width)) – the dimensions of one patch

  • step (number of pixels between two patches)

  • max_patches (integer or float, optional default is None) – The maximum number of patches to extract. If max_patches is a float between 0 and 1, it is taken to be a proportion of the total number of patches.

  • random_state (int or RandomState) – Pseudo number generator state used for random sampling to use if max_patches is not None.

Returns

patches (array, shape = (n_patches, patch_height, patch_width) or) – (n_patches, patch_height, patch_width, n_channels) The collection of patches extracted from the image, where n_patches is either max_patches or the total number of patches that can be extracted.

xlearn.utils.img_window(img, window_size)[source]

Function Description

Parameters
  • img (define img)

  • window_size (describe window_size)

Returns

img_wd (describe img_wd)

xlearn.utils.mlog(img)[source]
xlearn.utils.nor_data(img)[source]

Normalize the image

Parameters

img (array) – The images need to be normalized

Returns

img – Description.

xlearn.utils.nor_prj(img)[source]
xlearn.utils.reconstruct_patches(patches, image_size, step)[source]

Reconstruct the image from all of its patches. Patches are assumed to overlap and the image is constructed by filling in the patches from left to right, top to bottom, averaging the overlapping regions.

Parameters
  • patches (array, shape = (n_patches, patch_height, patch_width) or) – (n_patches, patch_height, patch_width, n_channels) The complete set of patches. If the patches contain colour information, channels are indexed along the last dimension: RGB patches would have n_channels=3.

  • image_size (tuple of ints (image_height, image_width) or) – (image_height, image_width, n_channels) the size of the image that will be reconstructed

  • step (number of pixels between two patches)

Returns

image (array, shape = image_size) – the reconstructed image

xlearn.utils.rescale_intensity(img)[source]