ovl.image_filters.image_filters module

ovl.image_filters.image_filters.adaptive_brightness(image: numpy.ndarray, brightness: Union[float, ovl.helpers.types.RangedNumber.<locals>.Hint] = 50, hsv: bool = False) → numpy.ndarray[source]

Changes the brightness of every pixel so that the average of the image is the target average

Parameters:
  • image – The image to be changed (Numpy array)
  • brightness – the target average for the image
  • hsv – bool noting if the image is in hsv
Returns:

a copy of the image changed

ovl.image_filters.image_filters.change_brightness(image: numpy.ndarray, change: float = 25, hsv_image: bool = False) → numpy.ndarray[source]

Changes the brightness of every pixel of a BGR image by the given amount

Parameters:
  • image – The image to be changed (Numpy array)
  • change – the change (integer) (The min brightness is 0 and max is 100)
  • hsv_image – bool noting if the image is in hsv
Returns:

a copy of the image changed

ovl.image_filters.image_filters.convert_to_hsv(image: numpy.ndarray) → numpy.ndarray[source]

Converts an image to hsv - Mainly for beginner use

Parameters:image – image to be converted
Returns:the converted image
ovl.image_filters.image_filters.crop_image(image, point: Tuple[int, int], dimensions: Tuple[int, int])[source]

Crops a given rectangle from a given image, this can be used to “cut out” a rectangle part of the image.

The rectangle is defined by the origin (point) a tuple of (x, y) denoting the top left corner and by the dimensions of its sides - defined using a tuple of (width, height).

Parameters:
  • image – an image (numpy array)
  • point – (x, y) coordinates that is the top left corner of the rectangle
  • dimensions – (width, height) of the rectangle
Returns:

the region of the image

ovl.image_filters.image_filters.gaussian_blur(image, kernel_size=(3, 3), sigma_x=5, sigma_y=None, border_type=None)[source]

An image filter version of cv2.gaussianBlur.

Gaussian blur is a common filter that is used to remove image noise.

It is considered necessary when preforming edge detection (such as using the CannyThreshold)

Gaussian Blur assumes the noise in the image is random and that the neighbors of each pixel are similar in a normally distributed fashion, meaning the closer the neighbor the more it should be similar to the pixel. The process of applying the kernel to the image is called convolution.

Parameters:
  • image – the image to be blurred (numpy array)
  • kernel_size – the size of the window that moves over the image

this determines what are the pixel’s neighbors. The kernel must be of odd dimensions so that it has a center pixel - which is where the output is placed :param sigma_x: standard distribution of the gaussian function on the x axis, the larger this is the more further neighbors affect the new value of the window’s center :param sigma_y: standard distribution of the gaussian function on the y axis, the larger this is the more further neighbors affect the new value of the window’s center if this is set to 0 or None then it will take the value of sigma_x :param border_type: Specifies image boundaries while kernel is applied on image borders.

More information on these can be found in the opencv’s gaussianBlur function https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_filtering/py_filtering.html#gaussian-filtering :return: the blurred image

ovl.image_filters.image_filters.non_local_mean_denoising(image, h=10, hColor=None, template_window_size=None, search_window_size=None, destination=None)[source]

Non local mean denoising is an image noise removal function. Non local mean denoising removes noise by finding matching patterns in other parts of the image It has different arguments for greyscale images and color images

Parameters:
  • image – the image to be denoised
  • hColor
  • h – parameter deciding filter strength. Higher h value removes noise better, but removes details of image also. (10 is default) h maps to h in the greyscale version of the opencv function and to hColor in the color version
  • template_window_size – size of the template window, should be an odd number
  • search_window_size – size of the search window
  • destination – an image of the same size to place the result
Returns:

the denoised image, a numpy array

For more information about the implementation please refer the the opencv source code and this tutorial: https://docs.opencv.org/3.4/d5/d69/tutorial_py_non_local_means.html

For more information on the algorithim behind the implementation look at this paper: http://www.ipol.im/pub/art/2011/bcm_nlm/

ovl.image_filters.image_filters.rotate_image(image: numpy.ndarray, angle: int = 180) → numpy.ndarray[source]

Rotates an image by a given amount of degrees. Note that the rotated image’s dimensions will most likely change if the angle is not 90, -90, 180, 0 or a multiplication of them)

Parameters:
  • image – the image to be rotated
  • angle – the angle to rotate the image in degrees (positive is to the left, negative to the right)
Returns:

the rotated image

ovl.image_filters.image_filters.sharpen_image(image: numpy.ndarray, size: tuple = (3, 3)) → numpy.ndarray[source]

Sharpens an image by preforming convolution it with a sharpening matrix

Parameters:
  • image – the image (numpy array)
  • size – the size of the sharpening matrix
Returns:

the new sharpened image

ovl.image_filters.image_filters.undistort(image, camera_matrix, distortion_coefficients, destination=None, new_camera_matrix=None)[source]

Using calculated camera matrix and distortion coefficients can be used to remove distortions caused by the camera and manufacturing flaws. Getting the camera matrix and distortion coefficients requires performing camera calibration (usually using a chessboard) For more information on camera calibration: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html

Parameters:
  • image – the ndarray of the image
  • camera_matrix – the camera matrix that was calculated from the camera calibration
  • distortion_coefficients – the distortion coefficients that were calculated from the camera calibration
  • destination – the image the result should be saved in, None if just return
  • new_camera_matrix – the new optimal camera matrix .
Returns:

the undistorted image