Removes similar colored background in the given image.

    :param img: Input image
    :param th: Tuple(2)
        Background color threshold (lower-limit, upper-limit)
    :return: Background removed image as result

def remove_bg(img, th=(240, 255)):
    """
    Removes similar colored background in the given image.

    :param img: Input image
    :param th: Tuple(2)
        Background color threshold (lower-limit, upper-limit)
    :return: Background removed image as result
    """
    if img.size == 0:
        return img

    img = gray3(img)

    # delete rows with complete background color
    h, w = img.shape[:2]
    i = 0
    while i < h:
        mask = np.logical_or(img[i, :, :] < th[0], img[i, :, :] > th[1])
        if not mask.any():
            img = np.delete(img, i, axis=0)
            i -= 1
            h -= 1
        i += 1

    # if image is complete background only
    if img.size == 0:
        return img

    # delete columns with complete background color
    h, w = img.shape[:2]
    i = 0
    while i < w:
        mask = np.logical_or(img[:, i, :] < th[0], img[:, i, :] > th[1])
        if not mask.any():
            img = np.delete(img, i, axis=1)
            i -= 1
            w -= 1
        i += 1

    return img