Previous topic

util.grandom

Next topic

util.misc

This Page

util.kernel

Functions for dealing with the kernel matrices of linear filters.

glimpse.util.kernel.DrawGaborAsLine(orient, num_orientations=8, kwidth=11, shift_orientations=False, line_width=1)

Draw the line corresponding to a given Gabor.

The generated line is phase independent.

Parameters:
  • norientations (int) – Number of edge orientations.
  • kwidth (int) – Width of kernel in pixels.
  • shift_orientations (bool) – Whether to rotate Gabor through a small angle.
  • line_width (int) – Width of drawn line in pixels.
Return type:

2D ndarray of float

glimpse.util.kernel.MakeGaborKernel(kwidth, theta, gamma=0.59999999999999998, sigma=None, phi=0, lambda_=None, scale_norm=True)

Create a kernel matrix by evaluating the 2-D Gabor function.

Parameters:
  • kwidth (odd int) – Width of the kernel.
  • theta (float) – Orientation of the (normal to the) preferred frequency.
  • gamma (float) – Aspect ratio of Gaussian window (gamma = 1 means a circular window, while 0 < gamma < 1 means the window is elongated).
  • sigma (float) – Standard deviation of Gaussian window (1/4 the wavelength is a good choice, so that the window covers approximately two full wavelengths of the sine function).
  • phi (float) – Phase offset (phi = 0 detects white edge on black background, phi = \(\pi\) detects black edge on white background).
  • lambda (float) – Wavelength of sine function (2/5 * kwidth is a good choice, so that the kernel can fit 2 1/2 wavelengths total).
  • scale_norm (bool) – If true, the kernel vector will be scaled to have unit norm.
Returns:

kernel matrix

Return type:

2D ndarray of float

glimpse.util.kernel.MakeGaborKernels(kwidth, num_orientations, num_phases, shift_orientations, **args)

Create a set of 2-D square kernel arrays, whose components are chosen according to the Gabor function.

Parameters:
  • kwidth (odd int) – Width of kernel.
  • num_orientations (int) – Number of edge orientations (orientations will be spread between 0 and \(\pi\)).
  • num_phases (int) – Number of Gabor phases (a value of 2 matches a white edge on a black background, and vice versa).
  • shift_orientations (bool) – Whether to rotate Gabor through a small angle (a value of True helps compensate for aliasing).
  • scale_norm (bool) – If true, then the kernel vector is scaled to have unit norm.
Returns:

kernel arrays

Return type:

4D ndarray of float

glimpse.util.kernel.MakeLanczosKernel()

Construct a smoothing filter based on the Lanczos window.

See also

For more information image resampling using the Lanczos kernel, see the Wikipedia article or the StackOverflow discussion.

Returns:Fixed-size, square kernel.
Return type:2D ndarray
glimpse.util.kernel.MakeRandomKernels(nkernels, kshape, normalize=True, mean=0, std=0.14999999999999999)

Create a set of N-dimensional kernel arrays whose components are sampled independently from the normal distribution.

Parameters:
  • nkernels (int) – Number of kernels to create.
  • kshape (list of int) – Dimensions of each kernel.
  • normalize (bool) – Whether the resulting kernels should be scaled to have unit norm.
  • mean (float) – Center of the component-wise normal distribution.
  • std (float) – Standard deviation of the component-wise normal distribution.
Returns:

Array of kernel values [with N dimensions, where N = len(kshape)+1].

Return type:

ndarray