Image

class src.processing_cores.image.Image(*args)

Image class for Smart Control

cv_type()

Returns the opencv-type of the array or of the GpuMat.

Returns:

type: Opencv-type of the array or of the GpuMat

ROI(x0, y0, width, height)

Returns an rectangle Image defined by x0, y0, width and height.

Arguments:

x0 (int): x coordinate of the top-left corner of the ROI y0 (int): y coordinate of the top-left corner of the ROI width (int): width of the ROI height (int): height of the ROI

Returns:

Image: Rectangle Image defined by x0, y0, width and height

add_alpha_channel(alpha)

Adds alpha channel to an RGB image.

Arguments:

alpha (numpy.ndarray): Fourth channel to add

Returns:

Image: Converted Image into RGBA

apply_affine_transform(*args)

Applies an affine transformation on the image array.

Arguments:
2 arguments:

Image: Reference image for the rigid transformation, it must have the same size as the current image. Metrology: Instance metrology

3 arguments:

numpy.ndarray: Displacement matrix int: width of the total image int: height of the total image

Returns:

Image: Transformed image

apply_image(*args)

Given an image, if there are 3 arguments, applies a translation on the image array with args[1] and args[2] as respectively x offset and y offset. Then in every cases, binarizes and erodes the image, and applies a mask on it and adds it to the current image.

Arguments:
1 argument:

Image: Image to apply to the current one, it must have the same size as the current image.

3 arguments:

Image: Image to shift and to apply to the current one, it must have the same size as the current image. int: x offset int: y offset

Returns:

Image: Reconstructed image

apply_perspective_transform(*args)

Applies an perspective transformation on the image array.

Arguments:
2 arguments:

Image: Reference image for the rigid transformation, it must have the same size as the current image. Metrology: Instance metrology

3 arguments:

numpy.ndarray: Displacement matrix int: width of the total image int: height of the total image

Returns:

Image: Transformed image

binarize()

Applies a very low threshold to binarize the image.

Returns:

Image: Binarized Image

blur(size)

Applies a gaussian blur to the image. Size must be an odd and inferior or equal to 31.

Arguments:

size (int): Width of the squared kernel

Returns:

Image: Image blurred

brightnessAndContrastAuto(clipLimit=2.0, size=8)

Applies CLAHE algorithm on the image to get an image equalized in terms of histogram.

Arguments:

clipLimit (float, optional): Threshold for contrast limiting. Defaults to 2.0. size (int, optional): Size of grid for the equalization. Defaults to 8.

Returns:

Image: Image equalized in terms of histogram.

canny(low=- 1, high=- 1, apperture=3)

Applies a Canny filter to the image.

Arguments:

low (int, optional): Lower threshold. Defaults to -1. high (int, optional): Higher threshold. Defaults to -1. apperture (int, optional): Aperture size for the Sobel operator. Defaults to 3.

Returns:

Image: Edges image

canvas_size(*args)

Applies a rectangular mask on the image.

Arguments:
1 argument:

tuple: (cols, rows), size of the canvas mask

2 arguments:

int: cols of the canvas mask int: rows of the canvas mask

Returns:

Image: Image masked

close(size)

Applies the morphological operation “close”, it applies an erosion after a dilatation operation.

Arguments:

size (int): width of the squared kernel

Returns:

Image: Image “closed”

convert(*args)

Converts martix into a predetermined type.

Arguments:
1 argument:

int: Integer corresponding to an opencv-type to which the array will be converted to

3 arguments:

bool: True: Convert to a 3 or 4 channels image, False: Convert to a grayscale image bool: True: Convert to a 4 channels image, False: Convert to a 3 channels image bool: True: Convert array value to float without changing the number of channels. First argument checked.

Returns:

Image: Image converted

differential_score(im1, x_offset, y_offset)

Translate im1 with x_offset and y_offset and subtract it to the current image.

Arguments:

im1 (Image): Image to subtract x_offset (int): Offset along horizontal axis y_offset (int): Offset along vertical axis

Returns:

Image: Output image

dx_dy_drz(M)

Extract from the displacement array the position vector

Arguments:

numpy.ndarray: Displacement array (2x3 or 3x3)

Returns:

numpy.ndarray: Position of the top-left corner (x, y, rz)

empty()

Checks if the array or the GpuMat is empty

Returns:

bool: True if mat or gpu_mat is empty

erode(size)

Applies an erosion operation on the image.

Arguments:

size (int): width of the squared kernel

Returns:

Image: Image eroded

generate_keypoints_orb()

Generates the keypoints and descriptors from the current image with ORB.

Returns:

numpy.ndarray: Array of keypoints (5 x number of keypoints) numpy.ndarray: Array of descriptors (number of descriptors)

generate_keypoints_surf(hessian_threshold)

Generates the keypoints and descriptors from the current image with the SURF algorithm.

Arguments:

hessian_threshold (int): Threshold value used by SURF to determinate which keypoints to keep.

Returns:

numpy.ndarray: Array of keypoints (6 x number of keypoints) numpy.ndarray: Array of descriptors (number of descriptors)

get_GpuMat()

Returns the image GpuMat.

Returns:

cv.cuda.GpuMat: Image GpuMat

get_Mat()

Returns the image array.

Returns:

numpy.ndarray: Image array

get_channel(idx)

Returns the channel required as a new Image.

Arguments:

idx (int): Channel index

Returns:

Image: Image with only one channel

get_cols()

Returns the number of columns of the array.

Returns:

int: Number of columns

get_displacement_matrix()

Returns the displacement array of the image.

Returns:

numpy.ndarray: Displacement array

get_id()

Returns the image id.

Returns:

int: Id corresponding to the image

get_position()

Returns the position of the top-left corner (x, y, rz).

Returns:

numpy.ndarray: Position of the top-left corner (x, y, rz)

get_rotation()

Returns the rotation array.

Returns:

numpy.ndarray: Rotation array

get_rows()

Returns the number of rows of the array.

Returns:

int: Number of rows

get_x()

Returns the x coordinate of the top-left corner.

Returns:

int: x coordinate of the top-left corner

get_y()

Returns the y coordinate of the top-left corner.

Returns:

int: y coordinate of the top-left corner

get_z()

Returns the rz coordinate of the top-left corner.

Returns:

int: rz coordinate of the top-left corner

histogram()

Computes and returns the histogram of the current Image array.

Returns:

GpuMat: Histogram

laplacian()

Applies a laplacian filter to the image.

Returns:

Image: Filtered image

mask(mask)

Applies mask on the image.

Arguments:

mask (Image): Mask to apply, that specifies elements to change, it must have the same size as the current image.

Returns:

Image: Image with specified elements changed

mat_type()

Returns a normalized type of the array for the convertion module.

Raises:

Exception: GpuMat type unrecognised Exception: mat type unrecagnised

Returns:

int: Normalized type for the convertion module

max()

Computes and returns the maximum of the Image array.

Returns:

float: Maximum of the Image array

mean()

Computes and returns the mean of the Image array.

Returns:

float: Mean of the Image array

mean_stdev()

Computes and returns the mean and the standard deviation of the Image array.

Returns:

numpy.ndarray: [mean, standard deviation]

min()

Computes and returns the minimum of the Image array.

Returns:

float: Minimum of the Image array

min_max()

Computes and returns the minimum and the maximum of the Image array.

Returns:

numpy.ndarray: [minimum, maximum]

normalize()

Normalizes the Image array values between 0 and 255.

Returns:

Image: Image with its array values normalized.

open(size)

Applies the morphological operation “open”, it applies a dilatation after an erosion operation.

Arguments:

size (int): width of the squared kernel

Returns:

Image: Image “opened”

plt_show()

Display the image in a matplotlib window.

positive_else_zero(nb)

Checks if a number is positive and if not return 0.

Arguments:

nb (int, float): Number to check

Returns:

int or float: Number with the same type as the source.

resize(*args)

Returns the array resized

Arguments:
1 argument:

tuple: (cols, rows)

2 arguments:

cols: Number of columns of the new array rows: Number of rows of the new array

Returns:

Image: Image with its array resized

resize_by_factor(fx, fy)

Resizes the image array by factor. New_width = width*fx and New_height = height*fy.

Arguments:

fx (float): Scale factor along horizontal axis fy (float): Scale factor along vertical axis

Returns:

Image: New image resized

rigid_transform(transformed_image, metro)

Extracts from the current image and from transformed_image the keypoints with the SURF algorithm. The function filters the matches found between the two keypoints datasets using the RANSAC regression. With the matches, it computes a displacement matrix.

Arguments:

transformed_image (Image): Reference image used to compute the displacement matrix, it must have the same size as the current image. metro (Metrology): Instance metrology

Returns:

numpy.ndarray: Displacement matrix (2x3)

rotate(rz, size=(- 1, - 1), canvas_resize=True)

Applies a rotation to the image array.

Arguments:

rz (float): Angle in degrees size (tuple, optional): Size of the output array. Defaults to (-1, -1). canvas_resize (bool, optional): Whether to resize the output array or not. Defaults to True.

Returns:

Image: Rotated image

save(path, filename)

Saves the image array into the given path and filename if on debug mode.

Arguments:

path (str): Path to the folder filename (str): Name of the file

save_always(path, filename)

Saves the image array into the given path and filename.

Arguments:

path (str): Path to the folder filename (str): Name of the file

set_displacement_matrix(matrix_displacement)

Sets the displacement array.

Arguments:

matrix_displacement (numpy.ndarray): New displacement array (2x3 or 3x3)

set_id()

Sets the image id based on the last one.

set_position(tab_postion)

Sets the top-left corner position.

Arguments:

tab_postion (numpy.ndarray): Top-left corner position (x, y, rz)

set_rotation(tab_rotation)

Sets the rotation array.

Arguments:

tab_rotation (numpy.ndarray): New rotation array

set_x(new_x)

Sets the x coordinate of the top-left corner.

Arguments:

new_x (int): x coordinate of the top-left corner

set_y(new_y)

Sets the y coordinate of the top-left corner.

Arguments:

new_y (int): y coordinate of the top-left corner

set_z(new_z)

Sets the rz coordinate of the top-left corner.

Arguments:

new_z (int): rz coordinate of the top-left corner

show()

Resizes and display the image in an opencv window.

size()

Returns the size of the array.

Returns:

tuple: Shape of the array (cols, rows)

sobel_x()

Applies a Sobel filter on x on the image.

Returns:

Image: Image filtered

sobel_y()

Applies a Sobel filter on y on the image.

Returns:

Image: Image filtered

stdev()

Computes and return the standard deviation of the Image array.

Returns:

float: Standard deviation

threashold(th)

Applies a threshold to each array value. Value = 0 if value < th else image maximum.

Arguments:

th (int): Threshold value

Returns:

Image: Thresholded image

threshold_at_mean()

Applies a threshold to each array value. Value = 0 if value < th else image mean.

Returns:

Image: Thresholded image

threshold_at_mean_plus_std(std_coef)

Applies a threshold to each array value. Value = 0 if value < th else image mean + image standard deviation.

Returns:

Image: Thresholded image

threshold_otsu()

Applies a threshold to each array value. Uses Otsu algorithm to choose the optimal value for the thresholding.

Returns:

Image: Thresholded image

threshold_to_zero(th)

Applies a threshold to each array value. Value = 0 if value < th else value.

Arguments:

th (int): Threshold value

Returns:

Image: Thresholded image

threshold_to_zero_inv(th)

Applies a threshold to each array value. Value = 0 if value > th else value.

Arguments:

th (int): Threshold value

Returns:

Image: Thresholded image

translate(*args)

Applies a translation transformation to the image array.

Arguments:
1 argument:

numpy.ndarray: [x, y], offset values

4 arguments:

int: x offset

int: y offset

tuple: size of the output image, (-1, -1) by default

bool: whether to add a mask as fourth channel

Returns:

Image: Shifted image