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.
- 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)
- save_image(filename)[source]¶
Save the ROI overlayed over the reference image in .tiff image format.
- Parameters:
filename (
str
orpathlib.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
orpathlib.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 (
str
orpathlib.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
orpathlib.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
orpathlib.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.