ptyrad.utils.image_proc#

Image processing tools for fitting, cropping, normalization, etc.

Functions

center_crop(image, crop_height, crop_width)

Center crops a 2D or 3D array (e.g., an image).

create_one_hot_mask(image, percentile)

exponential_decay(r, a, b)

fit_background(image, mask[, fit_type])

fit_cbed_pattern(image[, initial_guess])

Estimate the center, radius, and std of a CBED pattern by minimizing the difference between the observed image and a synthetic model.

get_blob_size(dx, blob[, output, plot_profile])

guess_radius_of_bright_field_disk(image[, ...])

Utility function that returns an estimate of the radius of rbf from CBED

make_gaussian_mask(Npix, radius, std[, center])

Create a 2D Gaussian-blurred circular mask.

mfft2(im)

normalize_by_bit_depth(arr, bit_depth)

normalize_from_zero_to_one(arr)

power_law(r, a, b)

ptyrad.utils.image_proc.get_blob_size(dx, blob, output='d90', plot_profile=False)[source]#
ptyrad.utils.image_proc.guess_radius_of_bright_field_disk(image, thresh=0.5)[source]#

Utility function that returns an estimate of the radius of rbf from CBED

Parameters:
  • image (ndarray)

  • thresh (float)

ptyrad.utils.image_proc.fit_cbed_pattern(image, initial_guess=None)[source]#

Estimate the center, radius, and std of a CBED pattern by minimizing the difference between the observed image and a synthetic model.

Parameters:
  • image (np.ndarray) – The input image to fit.

  • initial_guess (dict, optional) – Dictionary with initial guess parameters.

Returns:

Dictionary containing the fitted parameters as dict[‘center’, ‘radius’, ‘std’].

Return type:

dict

ptyrad.utils.image_proc.make_gaussian_mask(Npix, radius, std, center=None)[source]#

Create a 2D Gaussian-blurred circular mask.

Parameters:
  • Npix (int) – Size of the square mask (Npix x Npix).

  • radius (float) – Radius of the circular mask.

  • std (float) – Standard deviation of the Gaussian blur.

  • center (tuple) – (y, x) coordinates of the center of the circle.

Returns:

A 2D Gaussian-blurred circular mask.

Return type:

np.ndarray

ptyrad.utils.image_proc.center_crop(image, crop_height, crop_width, offset=(0, 0))[source]#

Center crops a 2D or 3D array (e.g., an image).

Parameters:
  • image (numpy.ndarray) – The input array to crop. Can be 2D (H, W) or 3D (H, W, C).

  • crop_height (int) – The desired height of the crop.

  • crop_width (int) – The desired width of the crop.

Returns:

The cropped image.

Return type:

numpy.ndarray

ptyrad.utils.image_proc.mfft2(im)[source]#
ptyrad.utils.image_proc.normalize_from_zero_to_one(arr)[source]#
ptyrad.utils.image_proc.normalize_by_bit_depth(arr, bit_depth)[source]#
ptyrad.utils.image_proc.create_one_hot_mask(image, percentile)[source]#
ptyrad.utils.image_proc.fit_background(image, mask, fit_type='exp')[source]#
ptyrad.utils.image_proc.exponential_decay(r, a, b)[source]#
ptyrad.utils.image_proc.power_law(r, a, b)[source]#