opihiexarata.library.image module

Functions to help with image and array manipulations.

opihiexarata.library.image.create_circular_mask(array: ndarray, center_x: int, center_y: int, radius: float) ndarray[source]

Creates an array which is a circular mask of some radius centered at a custom index value location. This process is a little intensive so using smaller subsets of arrays are preferred.

Method inspired by https://stackoverflow.com/a/44874588.

Parameters:
  • array (array-like) – The data array which the mask will base itself off of. The data in the array is not actually modified but it is required for the shape definition.

  • center_x (integer) – The x-axis coordinate where the mask will be centered.

  • center_y (integer) – The y-axis coordinate where the mask will be centered.

  • radius (float) – The radius of the circle of the mask in pixels.

Returns:

circular_mask – The mask; it is the same dimensions of the input data array. If True, the the mask should be applied.

Return type:

array-like

opihiexarata.library.image.determine_translation_image_array(translate_array: ndarray, reference_array: ndarray) tuple[float, float][source]

This function determines the cross-correlated translation required to determine the translation which occurred to the translated array image from the reference array image.

This function deals with only translation, it does not handle scaling or rotation. More sophisticated methods are needed for that. This algorithm finds the mode of all translation vectors between star-points in the images.

Parameters:
  • translate_array (array-like) – The array which was translated from the reference array. We are computing the translation of this array.

  • reference_array (array-like) – The array before the translation. Inverting the translation on the translate_array returns back to this array.

Returns:

  • delta_x (float) – The x-axis length, in pixels, of the translation vector determined which would translate the translation array back onto the reference array.

  • delta_y (float) – The y-axis length, in pixels, of the translation vector determined which would translate the translation array back onto the reference array.

opihiexarata.library.image.save_array_as_png_grayscale(array: ndarray, filename: str, overwrite: bool = False) None[source]

This converts an array to a grayscale PNG file.

The PNG specification requires that the data values be integer. Note that if you are saving an array as a PNG, then data may be lost during the conversion between float to integer.

Parameters:
  • array (array-like) – The array that will be saved as a png.

  • filename (string) – The filename where the png will be saved. If the filename does not have the appropriate filename extension, it will be appended.

  • overwrite (boolean) – If the file already exists, should it be overwritten?

opihiexarata.library.image.scale_image_array(array: ndarray, minimum: float, maximum: float, lower_percent_cut: float = 0, upper_percent_cut: float = 0) ndarray[source]

This function scales the array to the provided minimum and maximum ranges after the percentile masks are taken.

Parameters:
  • array (array-like) – The array to be scaled.

  • minimum (float) – The minimum value of the scaling axis. This will be equal to the minimum value of the scaled array after accounting for the percentile cuts.

  • maximum (float) – The maximum value of the scaling axis. This will be equal to the maximum value of the scaled array after accounting for the percentile cuts.

  • lower_percent_cut (float) – The percent of values that will be masked from the lower end. Must be between 0-100.

  • upper_percent_cut (float) – The percent of values that will be masked from the upper end. Must be between 0-100.

Returns:

scaled_array – The array, after the scaling.

Return type:

array-like

opihiexarata.library.image.slice_array_boundary(array: ndarray, x_min: int, x_max: int, y_min: int, y_max: int) ndarray[source]

Slice an image array such that it stops at the boundaries and does not exceed past it. This function basically handels runtime slicing, but it returns a copy.

This function does not wrap around slices.

Parameters:
  • array (array-like) – The base array which the slice will access.

  • x_min (int) – The lower index bound of the x-axis slice.

  • x_max (int) – The upper index bound of the x-axis slice.

  • y_min (int) – The lower index bound of the y-axis slice.

  • y_max (int) – The upper index bound of the y-axis slice.

Returns:

boundary_sliced_array – The array, sliced while adhering to the boundary of the slices.

Return type:

array-like

opihiexarata.library.image.translate_image_array(array: ndarray, shift_x: float = 0, shift_y: float = 0, pad_value: float = nan) ndarray[source]

This function translates an image or array in some direction. The image is treated as value padded so pixels beyond the scope of the image after translation are given by the value specified.

Parameters:
  • array (array) – The image array which is going to be translated.

  • shift_x (float, default = 0) – The number of pixels the image will be shifted in the x direction.

  • shift_y (float, default = 0) – The number of pixels the image will be shifted in the y direction.

  • pad_value (float, default = np.nan) – The value to pad around the image.

Returns:

shifted_image – The image array after shifting.

Return type:

array