Exemplo n.º 1
0
def _extract_spatial_features(image: Image) -> np.ndarray:
    shape = Shape.from_image(image)
    features: List[np.ndarray] = []

    while shape.height >= 2 and shape.width >= 2:
        shape = Shape(shape.height / 2, shape.width / 2)
        shape_int = (int(shape.height), int(shape.width))
        features += [cv2.resize(image, shape_int).ravel()]

    return np.concatenate(features)
Exemplo n.º 2
0
def resize_image_to_size(image: ImageT,
                         target_size: Shape,
                         interpolation_method: int = cv2.INTER_AREA) -> ImageT:
    image_size = Shape.from_image(image)
    if image_size.width <= 0 or image_size.height <= 0:
        raise ImageResizingException('image shape is invalid')
    if target_size.width <= 0 or target_size.height <= 0:
        raise ImageResizingException('target_size is invalid')

    return cv2.resize(image, (target_size.width, target_size.height),
                      interpolation_method)