preprocessing module
- edafm.preprocessing.add_cutout(Xs, n_holes=5)[source]
Randomly add cutouts (square patches of zeros) to images. In-place operation.
- Parameters
Xs – list of np.ndarray of shape (batch_size, x_dim, y_dim, z_dim).
n_holes – int. Maximum number of cutouts to add.
- edafm.preprocessing.add_gradient(Xs, c=0.3)[source]
Add a constant gradient plane with random direction to arrays. In-place operation.
- Parameters
Xs – list of np.ndarray of shape (batch_size, x, y, z).
c – float. Maximum range of gradient plane as a fraction of the range of the array values.
- edafm.preprocessing.add_noise(Xs, c=0.1, randomize_amplitude=False, normal_amplitude=False)[source]
Add uniform random noise to arrays. In-place operation.
- Parameters
Xs – list of np.ndarray of shape (batch_size, …).
c – float. Amplitude of noise. Is multiplied by (max-min) of sample.
randomize_amplitude – Boolean. If True, noise amplitude is uniform random in [0,c] for each sample in the batch.
normal_amplitude – Boolean. If True and randomize_amplitude=True, then the noise amplitude is distributed like the absolute value of a normally distributed variable with zero mean and standard deviation equal to c.
- edafm.preprocessing.add_norm(Xs, per_layer=True)[source]
Normalize arrays by subracting the mean and dividing by standard deviation. In-place operation.
- Parameters
Xs – list of np.ndarray of shape (batch_size, …).
per_layer – Boolean. If True, normalized separately for each element in last axis of Xs.
- edafm.preprocessing.add_rotation_reflection(X, Y, reflections=True, multiple=2, crop=None, per_batch_item=False)[source]
Randomly rotate images in a batch to a different random angle (0 - 359 deg) and reflect.
- Parameters
X – list of np.ndarray of shape (batch, x, y, z). AFM images.
Y – list of np.ndarray of shape (batch, x, y). Reference image descriptors.
reflections – bool. Whether to augment with reflections. If set True each rotation is randomly reflected with 50% probability.
multiple – int. Multiplier, how many rotations to generate for every sample
crop – None or tuple (x_size, y_size). If not None, then output batch is cropped to specified size in the middle of the image.
per_batch_item – bool. If True, rotation is randomized per batch item, otherwise same rotation for all.
- Returns: tuple (X, Y)
- X: list of np.ndarray of shape (batch*multiple, x_new, y_new, z). Rotation augmented AFM images.Y: list of np.ndarray of shape (batch*multiple, x_new, y_new). Rotation augmented reference image descriptors.
- edafm.preprocessing.interpolate_and_crop(X, real_dim, target_res=0.125, target_multiple=8)[source]
Interpolate batch of AFM images to target resolution and crop to a target multiple of pixels in xy plane.
- Parameters
X – list of np.ndarray of shape (batch, x, y, z). AFM images.
real_dim – tuple of floats (len_x, len_y): Real-space size of AFM image region in x- and y-directions in angstroms.
target_res – float. Target size for a pixel in angstroms.
target_multiple – int. Target multiple of pixels of output image.
- Returns: list of np.ndarray of shape (batch, x_out, y_out, z)
Interpolated and cropped AFM images.
- edafm.preprocessing.rand_shift_xy_trend(Xs, shift_step_max=0.02, max_shift_total=0.1)[source]
Randomly shift z layers in x and y. Each shift is relative to previous one. In-place operation.
- Parameters
Xs – list of np.ndarray of shape (batch_size, x_dim, y_dim, z_dim).
shift_step_max – float in [0,1]. Maximum fraction of image size by which to shift for each step.
max_shift_total – float in [0,1]. Maximum fraction of image size by which to shift in total.
- edafm.preprocessing.random_crop(X, Y, min_crop=0.5, max_aspect=2.0, multiple=8, distribution='flat')[source]
Randomly crop images in a batch to a different size and aspect ratio.
- Parameters
X – list of np.ndarray of shape (batch, x, y, z). AFM images.
Y – list of np.ndarray of shape (batch, x, y). Reference image descriptors.
min_crop – float in [0,1]. Minimum crop size as percentage of the original size.
max_aspect – float >=1.0. Maximum aspect ratio for crop. Cannot be more than 1/min_crop.
multiple – int. The crop size is rounded down to the specified integer multiple.
distribution – ‘flat’ or ‘exp-log’. How aspect ratios are distributed. If ‘flat’, then distribution is random uniform between (1, max_aspect) and half of time is flipped. If ‘exp-log’, then distribution is exp of log of uniform distribution over (1/max_aspect, max_aspect). ‘exp-log’ is more biased towards square aspect ratios.
- Returns: tuple (X, Y)
- X: list of np.ndarray of shape (batch, x_new, y_new, z). Cropped AFM images.Y: list of np.ndarray of shape (batch, x_new, y_new). Cropped reference image descriptors.