pyrtools.pyramids.c package

Submodules

pyrtools.pyramids.c.wrapper module

functions that interact with the C code, for handling convolutions mostly.

pyrtools.pyramids.c.wrapper.corrDn(image, filt, edge_type='reflect1', step=(1, 1), start=(0, 0), stop=None)[source]

Compute correlation of image with filt, followed by downsampling.

These arguments should be 1D or 2D arrays, and image must be larger (in both dimensions) than filt. The origin of filt is assumed to be floor(size(filt)/2)+1.

Downsampling factors are determined by step (optional, default=(1, 1)), which should be a 2-tuple (y, x).

The window over which the convolution occurs is specfied by start (optional, default=(0,0), and stop (optional, default=size(image)).

NOTE: this operation corresponds to multiplication of a signal vector by a matrix whose rows contain copies of the filt shifted by multiples of step. See upConv for the operation corresponding to the transpose of this matrix.

WARNING: if both the image and filter are 1d, they must be 1d in the same dimension. E.g., if image.shape is (1, 36), then filt.shape must be (1, 5) and NOT (5, 1). If they’re both 1d and 1d in different dimensions, then this may encounter a segfault. I’ve not been able to find a way to avoid that within this function (simply reshaping it does not work).

Parameters:
  • image (array_like) – 1d or 2d array containing the image to correlate and downsample.

  • filt (array_like) – 1d or 2d array containing the filter to use for correlation and downsampling.

  • edge_type ({'circular', 'reflect1', 'reflect2', 'repeat', 'zero', 'extend', 'dont-compute'}) –

    Specifies how to handle edges. Options are:

    • ’circular’ - circular convolution

    • ’reflect1’ - reflect about the edge pixels

    • ’reflect2’ - reflect, doubling the edge pixels

    • ’repeat’ - repeat the edge pixels

    • ’zero’ - assume values of zero outside image boundary

    • ’extend’ - reflect and invert

    • ’dont-compute’ - zero output when filter overhangs imput boundaries.

  • step (tuple) – 2-tuple (y, x) which determines the downsampling factor

  • start (tuple or None) – 2-tuple which specifies the start of the window over which we perform the convolution

  • start – 2-tuple which specifies the end of the window over which we perform the convolution. If None, perform convolution over the whole image

Returns:

result – the correlated and downsampled array

Return type:

np.array

pyrtools.pyramids.c.wrapper.pointOp(image, lut, origin, increment, warnings=False)[source]

Apply a point operation, specified by lookup table lut, to image

This function is very fast and allows extrapolation beyond the lookup table domain. The drawbacks are that the lookup table must be equi-spaced, and the interpolation is linear.

Parameters:
  • image (array_like) – 1d or 2d array

  • lut (array_like) – a row or column vector, assumed to contain (equi-spaced) samples of the function.

  • origin (float) – specifies the abscissa associated with the first sample

  • increment (float) – specifies the spacing between samples.

  • warnings (bool) – whether to print a warning whenever the lookup table is extrapolated

pyrtools.pyramids.c.wrapper.upConv(image, filt, edge_type='reflect1', step=(1, 1), start=(0, 0), stop=None)[source]

Upsample matrix image, followed by convolution with matrix filt.

These arguments should be 1D or 2D matrices, and image must be larger (in both dimensions) than filt. The origin of filt is assumed to be floor(size(filt)/2)+1.

Upsampling factors are determined by step (optional, default=(1, 1)), a 2-tuple (y, x).

The window over which the convolution occurs is specfied by start (optional, default=(0, 0), and stop (optional, default = step .* (size(IM) + floor((start-1)./step))).

NOTE: this operation corresponds to multiplication of a signal vector by a matrix whose columns contain copies of the time-reversed (or space-reversed) FILT shifted by multiples of STEP. See corrDn.m for the operation corresponding to the transpose of this matrix.

WARNING: if both the image and filter are 1d, they must be 1d in the same dimension. E.g., if image.shape is (1, 36), then filt.shape must be (1, 5) and NOT (5, 1). If they’re both 1d and 1d in different dimensions, then this may encounter a segfault. I’ve not been able to find a way to avoid that within this function (simply reshaping it does not work).

Parameters:
  • image (array_like) – 1d or 2d array containing the image to upsample and convolve.

  • filt (array_like) – 1d or 2d array containing the filter to use for upsampling and convolution.

  • edge_type ({'circular', 'reflect1', 'reflect2', 'repeat', 'zero', 'extend', 'dont-compute'}) –

    Specifies how to handle edges. Options are:

    • ’circular’ - circular convolution

    • ’reflect1’ - reflect about the edge pixels

    • ’reflect2’ - reflect, doubling the edge pixels

    • ’repeat’ - repeat the edge pixels

    • ’zero’ - assume values of zero outside image boundary

    • ’extend’ - reflect and invert

    • ’dont-compute’ - zero output when filter overhangs imput boundaries.

  • step (tuple) – 2-tuple (y, x) which determines the upsampling factor

  • start (tuple or None) – 2-tuple which specifies the start of the window over which we perform the convolution.

  • start – 2-tuple which specifies the end of the window over which we perform the convolution. If None, perform convolution over the whole image

Returns:

result – the correlated and downsampled array

Return type:

np.array

Module contents