def apply(self, img, **params):
        w, h = img.shape[:2]
        crop_w, crop_h = self.width, self.height

        if self.crop_pos == 0:
            return F.crop(img, 0, 0, crop_w, crop_h)
        elif self.crop_pos == 1:
            return F.crop(img, w - crop_w, 0, w, crop_h)
        elif self.crop_pos == 2:
            return F.crop(img, 0, h - crop_h, crop_w, h)
        elif self.crop_pos == 3:
            return F.crop(img, w - crop_w, h - crop_h, w, h)
        else:
            return F.center_crop(img, crop_h, crop_w)
Esempio n. 2
0
    def apply(self, img, offset=(0, 0, 0, 0), **params):
        x_min = offset[0]
        y_min = offset[1]
        x_max = params['cols'] - offset[2]
        y_max = params['rows'] - offset[3]

        return F.crop(img, x_min=x_min, y_min=y_min, x_max=x_max, y_max=y_max)
Esempio n. 3
0
def five_crop(
    img: numpy.ndarray, size: List[int]
) -> Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray,
           numpy.ndarray]:
    """Crop the given image into four corners and the central crop.
    Args:
        img (numpy.ndarray): Image to be cropped.
        size (sequence or int): Desired output size of the crop. If size is an
            int instead of sequence like (h, w), a square crop (size, size) is
            made. If provided a sequence of length 1, it will be interpreted
            as (size[0], size[0]).
    Returns:
       tuple: tuple (tl, tr, bl, br, center)
       Corresponding top left, top right, bottom left, bottom right and center crop.
    """

    image_height, image_width = img.shape[:2]
    crop_height, crop_width = size
    if crop_width > image_width or crop_height > image_height:
        msg = "Requested crop size {} is bigger than input size {}"
        raise ValueError(msg.format(size, (image_height, image_width)))

    tl = F.crop(img, 0, 0, crop_width, crop_height)
    tr = F.crop(img, image_width - crop_width, 0, image_width, crop_height)
    bl = F.crop(img, 0, image_height - crop_height, crop_width, image_height)
    br = F.crop(
        img,
        image_width - crop_width,
        image_height - crop_height,
        image_width,
        image_height,
    )

    center = F.center_crop(img, crop_height, crop_width)

    return tl, tr, bl, br, center
Esempio n. 4
0
 def apply(self, img, x_min=0, x_max=0, y_min=0, y_max=0, **params):
     cropped = crop(img, x_min, y_min, x_max, y_max)
     return cropped
Esempio n. 5
0
def resized_crop(image, height, width, x_min, y_min, x_max, y_max):
    image = F.crop(image, x_min, y_min, x_max, y_max)
    image = cv2.resize(image, (width, height))
    return image
Esempio n. 6
0
 def apply(self, img, **params):
     return [F.crop(img, **crop) for crop in self.get_crops(img.shape)]