Image-processing methods#

These classes and functions all process images in some way, and thus may be helpful for constructing your own models or metrics. As is, they are not compatible with any of the synthesis methods.

Metric components

These functions are used by the Metrics. While they are not compatible with any of our synthesis methods, they may be useful to better understand the behavior of their respective metrics.

ssim_map

Structural similarity index map.

normalized_laplacian_pyramid

Compute the normalized Laplacian Pyramid using pre-optimized parameters.

Image pyramids

Image pyramids decompose images into bands corresponding to different spatial frequencies and orientations. As we often think of neurons in the early visual system as similarly only responding to a range of spatial frequencies and/or orientations, these pyramids can be used to construct a model of those early areas.

See pyrtools for more information, including links to resources for learning more.

LaplacianPyramid

Laplacian Pyramid in Torch.

SteerablePyramidFreq

Steerable frequency pyramid in Torch.

Filter construction functions

These convenience functions make it easier to construct some commonly-used filters.

circular_gaussian2d

Create normalized, centered circular 2D gaussian tensor with which to convolve.

Coordinate transformations

This related set of functions convert between the rectangular and polar representations of a signal (or computing the norm and direction, which are the analogues for real-valued signals).

rectangular_to_polar

Rectangular to polar coordinate transform.

polar_to_rectangular

Polar to rectangular coordinate transform.

local_gain_control

Spatially local gain control.

local_gain_release

Spatially local gain release.

rectangular_to_polar_dict

Return the complex amplitude and the phase of each complex tensor in a dictionary.

polar_to_rectangular_dict

Return the real and imaginary parts of tensor in a dictionary.

local_gain_control_dict

Spatially local gain control, for each element in a dictionary.

local_gain_release_dict

Spatially local gain release, for each element in a dictionary.

The following table summarizes the relationship among these functions (where ➡ denotes from rectangular to polar and ⬅ is the inverse):

function

dtype

input object

direction

rectangular_to_polar

complex*

tensor

polar_to_rectangular

complex*

tensor

local_gain_control

float*

tensor

local_gain_release

float*

tensor

rectangular_to_polar_dict

complex*

dict

polar_to_rectangular_dict

complex*

dict

local_gain_control_dict

float*

dict

local_gain_release_dict

float*

dict

Image resizing

The following functions return a version of their input whose size has increased or decreased without further modifying its contents.

correlate_downsample

Correlate with a filter and downsample by a factor of 2.

blur_downsample

Correlate with a named filter and downsample by 2.

upsample_convolve

Upsample by 2 and convolve with a filter.

upsample_blur

Upsample by 2 and convolve with named filter.

same_padding

Pad a tensor so that 2D convolution will result in output with same dims.

shrink

Shrink a signal by a factor.

expand

Expand a signal by a factor.

Image modification

The following functions return a modified version of their input.

rescale

Linearly rescale the dynamic range of the input to [a, b].

add_noise

Add normally distributed noise to an image.

center_crop

Crop out the center of a signal.

modulate_phase

Modulate the phase of a complex signal.

Image statistics

The following functions compute summary statistics of their inputs.

autocorrelation

Compute the autocorrelation of x.

variance

Calculate sample variance.

skew

Calculate sample estimate of asymmetry about input's mean.

kurtosis

Calculate sample estimate of tailedness (presence of outliers).