예제 #1
0
def process_to_gray_scale(img):
    """
    Purpose:
        Converts read image to gray scale.
    Args:
        img_path - path to the image to process.
    Returns:
        gray scale image read by opencv.
    """
    return convert_bgr_to_gray(img)
def process_to_trunc_image(img_path, threshold=177, max_threshold=255):
    """
    Purpose:
        Process an image to gray scale and apply truncation threshold (values considered to be white will be set to white, the
        rest of the image will remain gray scale).
    Args:
        img_path - path to the image to process
        threshold - threshold value used to classify the pixel values (optional).
        max_threshold - the max value to be given if a pixels value is more than the threshold value (optional).
    Returns:
        Truncated binary/grayscale image.
    """
    img = cv2.imread(img_path)
    gray_img = convert_bgr_to_gray(img)
    trunc_image = threshold_trunc(gray_img, threshold, max_threshold)
    return trunc_image
def process_to_trunc_otsu_image(img_path, max_threshold=255):
    """
    Purpose:
        Process an image to gray scale and apply truncation and otsu threshold (values considered to be white will be set to white, the
        rest of the image will remain gray scale).
    Args:
        img_path - path to the image to process
        max_threshold - the max value to be given if a pixels value is more than the threshold value (optional).
    Returns:
        thrunc_image_tuple[0] - optimal threshold value found by otsu threshold.
        thrunc_image_tuple[1] - trunc binary/grayscale image.
    """
    img = cv2.imread(img_path)
    gray_img = convert_bgr_to_gray(img)
    trunc_image_tuple = threshold_trunc_otsu(gray_img, max_threshold)
    return trunc_image_tuple
def process_to_tozero_otsu_image(img_path, inverse=False, max_threshold=255):
    """
    Purpose:
        Process an image tozero colours using tozero otsu thresholding.
    Args:
        img_path - path to the image to process
        inverse - if true an inverted tozero thresholding will be applied (optional).
        max_threshold - the max value to be given if a pixels value is more than the threshold value (optional).
    Returns:
        tozero_image_tuple[0] - optimal threshold value found by otsu threshold.
        tozero_image_tuple[1] - tozero binary/grayscale image.
    """
    img = cv2.imread(img_path)
    gray_img = convert_bgr_to_gray(img)
    if inverse:
        tozero_image_tuple = threshold_tozero_inv_otsu(gray_img, max_threshold)
    else:
        tozero_image_tuple = threshold_tozero_otsu(gray_img, max_threshold)
    return tozero_image_tuple
def process_to_binary_image(img_path, inverse=False, threshold=127, max_threshold=255):
    """
    Purpose:
         Process an image to binary colours.
    Args:
        img_path - path to the image to process
        inverse - if true an inverted binary thresholding will be applied (optional).
        threshold - threshold value used to classify the pixel values (optional).
        max_threshold - the max value to be given if a pixels value is more than the threshold value (optional).
    Returns:
        A binary image.
    """
    img = cv2.imread(img_path)
    gray_img = convert_bgr_to_gray(img)
    if inverse:
        binary_image = threshold_binary_inv(gray_img, threshold, max_threshold)
    else:
        binary_image = threshold_binary(gray_img, threshold, max_threshold)
    return binary_image
def process_to_tozero_image(img_path, inverse=False, threshold=177, max_threshold=255):
    """
    Purpose:
        Process an image tozero. All values considered black (if no inverse) will be set to black, the rest of
        the image will remain in gray scale. If inverse is true, the values considered to be white will be set to black,
        the rest of the image will remain in gray scale.
    Args:
        img_path - path to the image to process
        inverse - if true an inverted binary thresholding will be applied (optional).
        threshold - threshold value used to classify the pixel values (optional).
        max_threshold - the max value to be given if a pixels value is more than the threshold value (optional).
    Returns:
        Tozero grayscale/binary image.
    """
    img = cv2.imread(img_path)
    gray_img = convert_bgr_to_gray(img)
    if inverse:
        tozero_image = threshold_tozero_inv(gray_img, threshold, max_threshold)
    else:
        tozero_image = threshold_tozero(gray_img, threshold, max_threshold)
    return tozero_image