pyvale.dic.dicregionofinterest module¶
- class RegionOfInterest(ref_image)[source]¶
Bases:
objectA 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:
- interactive_selection()[source]¶
Interactive GUI to select a region of interest (ROI) in the image using openCV.
- 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.
- save_image(filename)[source]¶
Save the ROI overlayed over the reference image in .tiff image format.
- Parameters:
filename (
strorpathlib.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 (
strorpathlib.Path) – filename given to saved ROI maskbinary (
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 (
strorpathlib.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 (
strorpathlib.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.maskin file order, whileSeedROIentries populateself.seed.