pypocquant.lib.processing
¶
Module Contents¶
Functions¶
|
Calculate phase-only correlation of two numpy arrays. |
|
Uses phase-only correlation to find the coordinates in in2 where in1 can be found. |
|
Uses normalized cross-correlation to find the coordinates in in2 where in1 can be found. |
|
Create the normalized correlation coefficient (scalar) of two images. |
|
Crop an image to given size centered at coordinates (y, x). |
|
Merge three single channels into an RGB image. |
|
Find features in of a template inside a larger image. |
|
Find the template in the image using the extracted feature descriptors. |
|
Register 2 images using image features. |
|
Apply a transformation to an image. |
|
Displays the matches on a control image and returns it. |
|
Add a border to each of the images in a list and sets the border values to a given fill value. |
|
Convert a BGR image to gray or lightness. |
-
pypocquant.lib.processing.
phase_only_correlation
(in1: np.ndarray, in2: np.ndarray) → np.ndarray¶ Calculate phase-only correlation of two numpy arrays.
- Parameters
in1 – 2D numpy array.
in2 – 2D numpy array.
- Returns
2D np.float64 numpy array.
-
pypocquant.lib.processing.
find_position_in_image_using_phase_corr
(in1: np.ndarray, in2: np.ndarray) → tuple¶ Uses phase-only correlation to find the coordinates in in2 where in1 can be found.
- Parameters
in1 – 2D numpy array (must be strictly smaller, i.e. completely contained) in in2.
in2 – 2D numpy array.
- Returns
tuple with (y = row, x = column) location of the center of in1 in in2.
- Return type
tuple
-
pypocquant.lib.processing.
find_position_in_image_using_norm_xcorr
(in1: np.ndarray, in2: np.ndarray) → tuple¶ Uses normalized cross-correlation to find the coordinates in in2 where in1 can be found.
- Parameters
in1 – 2D numpy array (must be strictly smaller, i.e. completely contained) in in2.
in2 – 2D numpy array.
- Returns
tuple with (y = row, x = column) location of the center of in1 in in2.
- Return type
tuple
-
pypocquant.lib.processing.
correlation_coefficient
(image_1, image_2)¶ Create the normalized correlation coefficient (scalar) of two images. :param image_1: np image1 :param image_2: np image2
- Returns
product:
-
pypocquant.lib.processing.
crop_image_around_position_to_size
(image, y, x, size)¶ Crop an image to given size centered at coordinates (y, x).
If the original image is too small, a cropped version will be returned.
- Parameters
image – Image to be cropped
y – y center coordinate
x – x center coordinate
size – size of the crop
- Returns
out: Cropped image
-
pypocquant.lib.processing.
create_rgb_image
(red, green, blue=None)¶ Merge three single channels into an RGB image.
- Parameters
red – Red channel
- :param green
Green channel
- :param blue
Blue channel
- Returns
view: RGB image
-
pypocquant.lib.processing.
find_features
(image, detector='surf', num_features=1000, hessian_threshold=10, use_latch_descriptor=False)¶ Find features in of a template inside a larger image.
- Parameters
image –
detector –
num_features –
hessian_threshold –
use_latch_descriptor –
- Returns
kp
- Returns
des
-
pypocquant.lib.processing.
find_position_of_template_in_image_using_descriptors
(template_kps, template_des, image_kps, image_des, template_size)¶ Find the template in the image using the extracted feature descriptors.
- Parameters
template_kps –
template_des –
image_kps –
image_des –
template_size –
- Returns
coordinates
- Return type
tuple
-
pypocquant.lib.processing.
register_images_opencv_features
(source, target, detector='surf', use_latch_descriptor=False, perspective=True, affine=False, rigid=False, num_features=1000, hessian_threshold=10, control_image=False)¶ Register 2 images using image features.
Keyword arguments: :param source: source image to be registered (must be grayscale) :param target: target image (must be grayscale) :param detector: one of “orb”, “kaze”, “akaze”, “brisk”, “surf”, “sift” (default if surf) :param use_latch_descriptor: True to use the new LATCH descriptor (requires openCV 3.1), False to use the
default descriptors provided by the detectors (default is False)
- Parameters
num_features – number of features (used only by the “orb” and “sift” detectors, default is 1000)
hessian_threshold – threshold of the hessian of the images (used only by the “surf” detector, default is 10)
perspective – register the image using a perspective transformation (optional, default=True).
affine – register the image using an affine transformation (optional, default=False).
rigid – register the image using a rigid transformation (optional, default=False).
control_image – set to True to create a quality control image (default is False).
- Returns
results (aligned: aligned image, M : transformation matrix, mask: mask returned by cv2.findHomography()),
- Return type
dict
- Returns
view: quality control image,
- Returns
source_descr: list of source descriptors,
- Returns
target_descr: list of target descriptors).
-
pypocquant.lib.processing.
apply_transformation_to_image
(image, transformation_type, transformation_matrix, target_height=None, target_width=None)¶ Apply a transformation to an image.
- Parameters
image – image to be transformed.
transformation_type –
- type of transformation. One of:
”perspective”: register the image using a perspective transformation. “affine”: register the image using an affine transformation. “rigid”: register the image using a rigid transformation.
transformation_matrix –
- transformation matrix, must be:
”perspective”: (3x3) “affine”: (2x3) “rigid”: (2x3)
target_height – (optional) number of rows of the transformed image. If not set, the transformed image will have the same size as the source image.
target_width – (optional) number of columns of the transformed image. If not set, the transformed image will have the same size as the source image.
- Returns
transformed: transformed image.
-
pypocquant.lib.processing.
display_matches
(img1, img2, sel_matches, k1, k2, max_matches=None)¶ Displays the matches on a control image and returns it.
- Parameters
img1 – First image
img2 – Second image
sel_matches – Selected matches
k1 –
k2 –
max_matches –
- Returns
view
-
pypocquant.lib.processing.
add_border
(images: list, border: int, fill_value: int = - 1) → list¶ Add a border to each of the images in a list and sets the border values to a given fill value.
If the fill_value is omitted, the median of all pixel intensities will taken.
- Parameters
images (list) – List of images
border (int) – Border to be added to image
fill_value – (optional) If omitted the median of all pixel intensities will taken.
- Returns
out: List of images with added border.
- Return type
list
-
pypocquant.lib.processing.
BGR2Gray
(image, to_lightness=False)¶ Convert a BGR image to gray or lightness.
- Parameters
image – Image to be converted
to_lightness – To lightness bool
- Returns
l
- Return type
cv2.Image