NoiseGenerator#
- class augraphy.utilities.noisegenerator.NoiseGenerator(noise_type=1, noise_side=None, numba_jit=1)[source]#
Bases:
object
Core object to generate mask of noise.
- Parameters:
noise_type (int, optional) – Types of generated noise. 1 = default, sklearn.datasets’ make_blobs noise 2 = gaussian noise 3 = perlin noise 4 = worley noise 5 = rectangular pattern noise
noise_side (string, optional) – Location of generated noise. Choose from: “none”, “all”, “left”, “right”, “top”, “bottom”,”top_left”, “top_right”, “bottom_left”, “bottom_right”.
numba_jit (int, optional) – The flag to enable numba jit to speed up the processing in the augmentation.
- static compute_fade(f)[source]#
Computes fade values for interpolation purpose.
- Parameters:
f (numpy array) – Input fractional value for interpolation purpose.
- static compute_gradient(c, x, y)[source]#
Computes the gradient vector calculates the dot product.
- Parameters:
c (numpy array) – Input array that determines the selection of the gradient vector.
x (numpy array) – The x coordinates of the points on the 2D array.
y (numpy array) – The y coordinates of the points on the 2D array.
- static compute_lerp(a, b, x)[source]#
Performs linear interpolation between two values based on a interpolation parameter.
- Parameters:
a (numpy array) – Starting value of the linear interpolation process.
b (numpy array) – End value of the linear interpolation process.
x (numpy array) – The weight of the interpolation process.
- compute_perlin(x, y, permutation_table)[source]#
Calculates Perlin noise values for each point on the 2D array using linear interpolation and gradient selection.
- Parameters:
x (numpy array) – Grid x coordinates of the Perlin noise values.
y (numpy array) – Grid y coordinates of the Perlin noise values.
permutation_table (numpy array) – Permutation table to shuffe and select the gradient vectors during the Perlin noise generation process.
- generate_mask(noise_background, noise_value, generated_points_x, generated_points_y, xsize, ysize)[source]#
Generate mask of noise.
- Parameters:
noise_background (tuple) – Tuple of ints to determine background value of mask.
noise_value (tuple) – Tuple of ints to determine value of noise.
generated_points_x (numpy array) – x point value of noise.
generated_points_y (numpy array) – y point value of noise.
xsize (int) – Width of image.
ysize (int) – Height of image.
- generate_mask_main(noise_type, noise_side, noise_value, noise_background, noise_sparsity, noise_concentration, xsize, ysize)[source]#
Main function to generate mask of noise in each iteration.
- Parameters:
noise_type (int) – Types of generated noise.
noise_side (string) – Location of generated noise.
noise_value (tuple) – Tuple of ints to determine value of noise.
noise_background (tuple) – Tuple of ints to determine background value of mask.
noise_sparsity (tuple, optional) – Pair of floats determining sparseness of noise.
noise_concentration (tuple, optional) – Pair of floats determining concentration of noise.
xsize (int) – Width of image.
ysize (int) – Height of image.
- generate_noise(noise_iteration=(1, 1), noise_size=(1, 1), noise_value=(0, 128), noise_background=(255, 255), noise_sparsity=(0.4, 0.6), noise_concentration=(0.4, 0.6), xsize=1500, ysize=1500)[source]#
Main function to generate noise.
- Parameters:
noise_iteration – Pair of ints to determine number of iterations to apply noise in the mask.
noise_size (tuple, optional) – Pair of ints to determine scale of noise in the mask.
noise_value (tuple, optional) – Pair of ints determining value of noise.
noise_background (tuple, optional) – Pair of ints determining value of noise background.
noise_sparsity (tuple, optional) – Pair of floats determining sparseness of noise.
noise_concentration (tuple, optional) – Pair of floats determining concentration of noise.
xsize (int, optional) – Number of columns in generated mask of noise.
ysize (int, optional) – Number of rows in generated mask of noise.
- generate_perlin_noise(width, height, points=(5, 20))[source]#
Generates Perlin noise for a 2D array of specified width and height.
- Parameters:
width (int) – Width of the generated 2d perlin noise array.
height (int) – Height of the generated 2d perlin noise array.
points (tuple) – Tuple of ints determining number of points in each x and y direction within the array.
- generate_points(n_samples_array, std, center_x, center_y, xsize, ysize)[source]#
Generate x&y coordinates of noise.
- Parameters:
n_samples_array (list) – List contains number of points sample for each cluster.
std (int) – Standard deviation to determine sparseness of generated points.
center_x (int) – Center x of the generated noises.
center_y (int) – Center y of the generated noises.
xsize (int) – Width of image.
ysize (int) – Height of image.
- static generate_worley_noise(width, height, npoints, option, noise_background)[source]#
- Generates Worley noise, also known as cellular noise or Voronoi noise.
Worley noise creates a pattern of irregularly shaped cells, where each cell is centered around a randomly placed point.
- Parameters:
width (int) – Width of the generated 2d worley noise array.
height (int) – Height of the generated 2d worley noise array.
npoints – Number of randomly placed points that will define the Voronoi cells.
npoints – int
option – An option to choose which distance value to calculate within each cell. 0 is the closest point, 1 is the second closest point and so on.
option – int
noise_background (int) – Background value of mask.
Overview#
NoiseGenerator is the base class to generate mask of noise. There are 4 variants of supported noise effect and it supports noise generation in 8 directions of image edges.