pnp_mace.utils¶
Utility functions.
Functions
|
Add Gaussian white noise to an image. |
|
Display an image in console using |
|
Display an image along with the NRMSE relative to the reference image in the title. |
|
Downscale the image via decimation by the given factor in each direction. |
|
Load an image given a filename or url. |
|
Calculate the NRMSE of an image with respect to a reference. |
|
Create a list from a single image. |
|
Upscale the image via replication by the given factor in each direction. |
- pnp_mace.utils.load_img(path, convert_to_gray=True, convert_to_float=True)[source]¶
Load an image given a filename or url.
- Parameters
path – data path, may be local, or url as a string beginning with http
convert_to_gray – True to convert color images to grayscale
convert_to_float – True to convert to floats and divide by 255
- Returns
Grayscale image (numpy ndarray)
- pnp_mace.utils.display_image_nrmse(input_image, reference_image, title='', cmap='gray', fig=None, ax=None)[source]¶
Display an image along with the NRMSE relative to the reference image in the title.
- Parameters
input_image – image to be displayed
reference_image – reference image for calculating nrmse of input_image
title – title for the plot
cmap – colormap for image display
fig – draw in specified figure instead of creating one
ax – plot in specified axes instead of current axes of figure
- pnp_mace.utils.display_image(input_image, title=None, vmin=0, vmax=1, cmap='gray', fig=None, ax=None)[source]¶
Display an image in console using
matplotlib.pyplot
- Parameters
input_image – image to be displayed
title – title for the plot
cmap – colormap for image display
fig – draw in specified figure instead of creating one
ax – plot in specified axes instead of current axes of figure
- pnp_mace.utils.stack_init_image(init_image, num_images)[source]¶
Create a list from a single image.
- Parameters
init_image – a single image to be copied and stacked
num_images – number of copies to be included
- Returns
A list of copies of the original image (numpy ndarrays)
- pnp_mace.utils.downscale(input_image, scale_factor, resample)[source]¶
Downscale the image via decimation by the given factor in each direction.
- Parameters
input_image – input image as a numpy array
scale_factor – upscale factor
resample – interpolation type as in PIL.Image (NEAREST = NONE = 0, LANCZOS = 1, BILINEAR = 2, BICUBIC = 3, BOX = 4, HAMMING = 5)
- Returns
Downscaled image (numpy ndarray)
- pnp_mace.utils.upscale(input_image, scale_factor, resample)[source]¶
Upscale the image via replication by the given factor in each direction.
- Parameters
input_image – input image
scale_factor – upscale factor
resample – interpolation type as in PIL.Image (NEAREST = NONE = 0, LANCZOS = 1, BILINEAR = 2, BICUBIC = 3, BOX = 4, HAMMING = 5)
- Returns
Upscaled image (numpy ndarray)
- pnp_mace.utils.nrmse(image, reference)[source]¶
Calculate the NRMSE of an image with respect to a reference.
- Parameters
image – input image to be compared with reference
reference – reference image
- Returns
Root mean square error of the difference of image and reference, divided by the root mean square of the reference
- pnp_mace.utils.add_noise(clean_image, noise_std, seed=None)[source]¶
Add Gaussian white noise to an image.
- Parameters
clean_image – input image
noise_std – standard deviation of noise to be added
seed – seed for random number generator
- Returns
image with noise added, clipped to valid range of values (numpy ndarray)