paint.preprocessing.target_cropper
Functions
|
Load and preprocess the image. |
|
Get marker names and their offsets based on the target. |
|
Apply template matching to detect the position of markers. |
|
Load the image, detect marker positions, and return their sub-pixel locations. |
|
Use template matching to crop the images to the targets. |
Module Contents
- paint.preprocessing.target_cropper.load_and_preprocess_image(image_path: pathlib.Path, resize: bool) numpy.ndarray
Load and preprocess the image.
Parameters
- image_pathPath
Path to the image file.
- resizebool
Whether to resize the image.
Returns
- np.ndarray
Preprocessed grayscale image.
- paint.preprocessing.target_cropper.get_marker_data(target: str | int) tuple[list[str], numpy.ndarray]
Get marker names and their offsets based on the target.
Parameters
- targetstr | int
Target ID used to determine which marker should be used.
Returns
- list[str]
Required marker names.
- np.ndarray
Offset values from the center of the template to the desired position in the template.
- paint.preprocessing.target_cropper.apply_template_matching(img_gray: numpy.ndarray, template: numpy.ndarray, search_radius: int) tuple[numpy.ndarray, float]
Apply template matching to detect the position of markers.
Parameters
- img_graynp.ndarray
Grayscale image on which to perform template matching.
- templatenp.ndarray
Template image for marker matching.
- search_radiusint
Radius around detected markers to refine the position.
Returns
- np.ndarray
Sub-pixel adjusted position of the marker.
- float
Maximum match quality value.
- paint.preprocessing.target_cropper.get_marker_positions(image_path: pathlib.Path, target: str | int, search_radius: int = 10, resize: bool = False) tuple[numpy.ndarray, float]
Load the image, detect marker positions, and return their sub-pixel locations.
Parameters
- image_pathPath
Path to the image file.
- targetstr | int
Target type for marker selection.
- search_radiusint
Radius around detected markers to refine the position. Default is 10.
- resizebool
Whether to resize the image for marker detection. Default is
False.
Returns
- np.ndarray
All identified marker positions. The height and width coordinates are provided.
- float
Minimum matching quality value from template matching.
- paint.preprocessing.target_cropper.crop_image_with_template_matching(image_path: pathlib.Path, target: str | int, n_grid: int = 512) numpy.ndarray
Use template matching to crop the images to the targets.
Parameters
- image_pathPath
Path to the image file.
- targetstr | int
Target ID for marker detection.
- n_gridint
Size of the rectified grid. Default is 512.
Returns
- np.ndarray
Cropped image.
Raises
- RuntimeError
If the markers are not detected with sufficient accuracy.