dicregionofinterest.py

class RegionOfInterest(ref_image)[source]

Bases: object

A class for interactively selecting and manipulating ROI of an image before passing to the DIC engine.

Users can: - Interactively select rectangular, circular, or polygonal regions on the image. - Add or subtract selected regions from the mask. - Undo and reset the mask changes. - read in previously created ROIs - save created ROI as text or binary file. - Display/save the ROI overlayed over the reference. - Programatically select a rectangular ROI for consistency.

Public attributes:

image (np.ndarray): The image on which regions of interest are selected. mask (np.ndarray): A binary mask representing the selected regions of interest.

__init__(ref_image)[source]
Parameters:

ref_image (str, numpy.ndarray, pathlib.Path) – location of the reference image.

Raises:

ValueError

interactive_selection(subset_size)[source]

Interactive GUI to select a region of interest (ROI) in the image using openCV.

reset_mask()[source]

Completely resets the roi mask to 0s.

rect_boundary(left, right, top, bottom)[source]

Defines a central rectangular region of interest (ROI) excluding surrounding pixels defined by input arguments”

Parameters:
  • (int) (bottom)

  • (int)

  • (int)

  • (int)

rect_region(x, y, size_x, size_y)[source]
save_image(filename)[source]

Save the ROI overlayed over the reference image in .tiff image format.

Parameters:

filename (str or pathlib.Path) – Filename of image

Raises:

ValueError – If no ROI has been selected

save_array(filename, binary=False)[source]

Save the ROI mask as a numpy binary or text file.

Parameters:
  • filename (str or pathlib.Path) – filename given to saved ROI mask

  • binary (bool) – If True, saves from as a .npy binary file. If False, saves to a space delimited text file.

Raises:

ValueError – If no ROI has been selected.

read_array(filename, binary=False)[source]

Load the ROI mask from a binary or text file and store it in self.mask.

Parameters:
  • filename (str or pathlib.Path) – Path to the file to load.

  • binary (bool) – If True, loads from a .npy binary file. If False, loads from a text file.

Raises:
  • FileNotFoundError – If the specified file does not exist.

  • ValueError – If the loaded data is not a valid mask.

save_yaml(filename)[source]

Save the current ROI to a YAML file. This only works with the after having run the interactive GUI.

Parameters:

filename (str or pathlib.Path) – Filename of the YAML file to save the ROI data.

Raises:

ValueError – If no ROI has been selected.

read_yaml(filename)[source]

Load the ROI from a YAML file and restore the state of the GUI. This method will clear existing ROIs and restore the state from the YAML file.

Parameters:

filename (str or pathlib.Path) – Path to the YAML file containing the ROI data.

Raises:
  • FileNotFoundError – If the specified file does not exist.

  • ValueError – If the loaded data is not a valid ROI format.

show_image()[source]

Displays the current mask in grayscale.

Raises:

ValueError

class CustomMainWindow(dic_obj=None, *args, **kwargs)[source]

Bases: QWidget

__init__(dic_obj=None, *args, **kwargs)[source]
closeEvent(self, a0: QCloseEvent | None)[source]