Image Module

This module contains functions for loading, saving, and viewing images in the PNG format.

lib6003.image.png_read(fname, zero_loc='center')

Load the PNG image with the given filename into a numpy array. The resulting array will have values between 1 (brightest white) and 0 (darkest black).

fname: string

The filename to load (including .png)

zero_loc (optional): string

This parameter controls which point in the original image is considered to be (0,0). By default, it is the center of the given image (‘center’). The other option is ‘topleft’.

lib6003.image.png_write(array, fname, zero_loc='center', normalize=False, zoom=1)

Save the given numpy array as an image with the given filename. 1 translates to the brightest white in the output image, and 0 to the darkest black. Values above 1 will be displayed as white, and values below 0 will be displayed as black.

array: numpy.ndarray

An array containing pixel values

fname: string

The name of the file to save (including .png)

zero_loc (optional): string

This parameter controls where the point (0,0) should be rendered in the output image. By default, (0,0) is at the center of the image (‘center’). The other option is ‘topleft’.

normalize (optional): boolean

If True, normalize values so that the largest element maps to 1 (brightest white) and the smallest element maps to 0 (darkest black). Default: False

zoom (optional): int

Factor by which to zoom when saving.

lib6003.image.show_dft(array, color_scale='linear', color_limits=None, color_factor=1, show=True)

Given an image in the spatial domain, plot the magnitude and phase of its DFT coefficients using the show_image function. Magnitude is plotted on a log scale.

array: numpy.ndarray

An array containing a spatial-domain image (NOT an array of DFT coefficients)

color_scale (optional): string

Defaults to ‘linear’. If ‘log’, magnitude colors are on a log scale.

color_limits (optional): tuple of numbers

The values of magnitude that should be displayed as black and white, respectively. Values outside this range will be clipped to white or black.

color_factor (optional): number

A value by which the magnitude should be scaled for display purposes.

show (optional): bool

If set to True (the default), the plot will be immediately displayed. Otherwise, plt.show() will need to be called later to display the plot.

lib6003.image.show_image(array, colorscale='linear', zero_loc='center', cmap='gray', show=True, title='', xlabel='', ylabel='', vmax=None, vmin=None)

Display an image using matplotlib.

array: numpy.ndarray

An array containing the image to be displayed

colorscale(optional): string

If set to ‘log’, the colors are plotted on a log scale. Defaults to ‘linear’.

zero_loc (optional): string

This parameter controls where the point (0,0) should be rendered when plotting the image. By default, (0,0) is at the center of the image (‘center’). The other option is ‘topleft’.

cmap (optional): string

The color map to use when displaying the image. Defaults to ‘gray’. See https://matplotlib.org/examples/color/colormaps_reference.html for options.

show (optional): bool

If set to True (the default), the plot will be immediately displayed. Otherwise, plt.show() will need to be called later to display the plot.

title (optional): string

A title for the plot

xlabel (optional): string

A label for the horizontal axis

ylabel (optional): string

A label ver the vertical axis