Accept a template with both positive and negative values and scale the negative part in such a way that the sum is zero.

This is useful to generate masks that return zero when applied to a uniform background or linear gradient.

Calculate a radius around centerX, centerY that covers the whole frame

Make a circular mask as a 2D array

Parameters
• centreX (float) – Centre point of the mask.

• centreY (float) – Centre point of the mask.

• imageSizeX (int) – Size of the image to be masked.

• imageSizeY (int) – Size of the image to be masked.

Returns

Array with the shape (imageSizeX, imageSizeY) with the mask.

Return type

Numpy 2D Array

libertem.masks.polar_map(centerX, centerY, imageSizeX, imageSizeY, stretchY=1.0, angle=0.0)[source]

Return a map of radius and angle.

The optional parameters stretchY and angle allow to stretch and rotate the coordinate system into an elliptical form. This is useful to generate modified input data for functions that generate a template as a function of radius and angle.

Parameters
• centerX (float) – Center of the coordinate system in pixel coordinates

• centerY (float) – Center of the coordinate system in pixel coordinates

• imageSizeX (int) – Size of the map to generate in px

• imageSizeY (int) – Size of the map to generate in px

• stretchY (float, optional) – Stretch the radius elliptically by amount `stretchY` in direction `angle` in radians. `angle = 0` means in Y direction.

• angle (float, optional) – Stretch the radius elliptically by amount `stretchY` in direction `angle` in radians. `angle = 0` means in Y direction.

Returns

Map of radius and angle of shape `(imageSizeY, imageSizeX)`

Return type

Tuple[numpy.ndarray, numpy.ndarray]

Generate antialiased rings

Generate a template with a linear radial gradient from 0 to 1 inside r0, linear transition region for antialiasing between [r0 - delta/2, r0 + delta/2[, and a negative ring with value -1 in [r0 + delta/2, r_outer].

The function accepts the radius for each pixel as a parameter so that a distorted version can be generated with the stretchY and angle parameters of `polar_map()`.

Parameters
• r (numpy.ndarray) – Map of radius for each pixel, typically 2D. This allows to work in distorted coordinate systems by assigning arbitrary radius values to each pixel. `polar_map()` can generate elliptical maps as an example.

• r0 (float) – Inner radius to fill with a linear gradient in units of r

• r_outer (float) – Outer radius of ring from r0 to fill with -1 in units of r

• delta (float, optional) – Width of transition region between inner and outer in units of r with linear gradient for antialiasing or smoothening. Defaults to 1.

Returns

NumPy numpy.ndarray with the same shape and type of r with mask values assigned as described in the description.

Return type

numpy.ndarray

libertem.masks.rectangular(X, Y, Width, Height, imageSizeX, imageSizeY)[source]

Make a rectangular mask as a 2D array of bool. :param X: Centre point of the mask. :type X: Corner coordinates :param Y: Centre point of the mask. :type Y: Corner coordinates :param imageSizeX: Size of the image to be masked. :type imageSizeX: int :param imageSizeY: Size of the image to be masked. :type imageSizeY: int :param Width: :type Width: Width and Height of the rectangle :param Height: :type Height: Width and Height of the rectangle

Returns

Array with the shape (imageSizeX, imageSizeY) with the mask.

Return type

Numpy 2D Array

Make a ring mask as a double array.

Parameters
• centreX (float) – Centre point of the mask.

• centreY (float) – Centre point of the mask.

• imageSizeX (int) – Size of the image to be masked.

• imageSizeY (int) – Size of the image to be masked.