def _original_format(self, image, chw, normalized, gray3dim):
     """ Return transformed image with original format. """
     if not is_numpy(image):
         image = np.array(image)
     if chw:
         image = hwc_to_chw(image)
     if normalized:
         image = image / 255
     if gray3dim:
         image = np.expand_dims(image, 0)
     return image
def chw_to_hwc(img):
    """
    Transpose the input image; shape (C, H, W) to shape (H, W, C).

    Args:
        img (numpy.ndarray): Image to be converted.

    Returns:
        img (numpy.ndarray), Converted image.
    """
    if is_numpy(img):
        return img.transpose(1, 2, 0).copy()
    raise TypeError('img should be numpy.ndarray. Got {}'.format(type(img)))
def is_chw(img):
    """
    Check if the input image is shape (H, W, C).

    Args:
        img (numpy.ndarray): Image to be checked.

    Returns:
        Bool, True if input is shape (H, W, C).
    """
    if is_numpy(img):
        img_shape = np.shape(img)
        if img_shape[0] == 3 and img_shape[1] > 3 and img_shape[2] > 3:
            return True
        return False
    raise TypeError('img should be numpy.ndarray. Got {}'.format(type(img)))
Beispiel #4
0
def is_rgb(img):
    """
    Check if the input image is RGB.

    Args:
        img (numpy.ndarray): Image to be checked.

    Returns:
        Bool, True if input is RGB.
    """
    if is_numpy(img):
        img_shape = np.shape(img)
        if len(np.shape(img)) == 3 and (img_shape[0] == 3 or img_shape[2] == 3):
            return True
        return False
    raise TypeError('img should be numpy.ndarray. Got {}'.format(type(img)))
def is_normalized(img):
    """
    Check if the input image is normalized between 0 to 1.

    Args:
        img (numpy.ndarray): Image to be checked.

    Returns:
        Bool, True if input is normalized between 0 to 1.
    """
    if is_numpy(img):
        minimal = np.min(img)
        maximun = np.max(img)
        if minimal >= 0 and maximun <= 1:
            return True
        return False
    raise TypeError('img should be Numpy array. Got {}'.format(type(img)))