pyvale.dic.dicregionofinterest module

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()[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]

Select a rectangular region of interest (ROI) in the reference image.

The rectangle is defined by its top-left corner and size. The region is automatically clipped to the image bounds. The selected area is marked in the internal mask and flags the ROI as selected.

Parameters:
  • x (int) – X-coordinate (column index) of the top-left corner of the rectangle.

  • y (int) – Y-coordinate (row index) of the top-left corner of the rectangle.

  • size_x (int) – Width of the rectangular region in pixels.

  • size_y (int) – Height of the rectangular region in pixels.

Returns:

None

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:
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 ROI geometry from a YAML file without initialising the GUI.

The YAML format is the same one written by the interactive ROI tool. Rectangular, circular, and polygonal entries are applied directly to self.mask in file order, while SeedROI entries populate self.seed.

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]