예제 #1
0
    def __call__(self, image, target):
        # Pad if needed
        ih, iw = get_tensor_image_size(image)
        if ih < self.size[0] or iw < self.size[1]:
            print(image.size())
            print(self.size)
            image, target = ZeroPad.zero_pad(image, target,
                                             max(self.size[0], ih),
                                             max(self.size[1], iw))
        i, j, h, w = self.get_params(image, self.size)
        image = F.crop(image, i, j, h, w)
        target = target if type(target) == str else F.crop(target, i, j, h, w)

        return image, target
예제 #2
0
    def __call__(self, img, target):
        """
        Args:
            img (PIL Image): Image to be cropped.

        Returns:
            PIL Image: Cropped image.
        """
        if self.padding > 0:
            img = F.pad(img, self.padding)
            target = F.pad(target, self.padding)

        i, j, h, w = self.get_params(img, self.size)

        return F.crop(img, i, j, h, w), F.crop(target, i, j, h, w),
예제 #3
0
    def __call__(self, img):
        width, height = self.crop_size

        left = random.randint(0, int(img.shape[1] - width))
        top = random.randint(0, int(img.shape[0] - height))

        if (width > img.shape[1] or height > img.shape[0]):
            raise ValueError(
                "the output imgage size should be small than input image!!!")

        return F.crop(img, top, left, width, height)
    def __call__(self, img, label):
        """
        Args:
            img (PIL Image): Image to be cropped.

        Returns:
            PIL Image: Cropped image.
        """
        if self.padding > 0:
            img = F.pad(img, self.padding)

        # pad the width if needed
        if self.pad_if_needed and img.size[0] < self.size[1]:
            img = F.pad(img, (int((1 + self.size[1] - img.size[0]) / 2), 0))
        # pad the height if needed
        if self.pad_if_needed and img.size[1] < self.size[0]:
            img = F.pad(img, (0, int((1 + self.size[0] - img.size[1]) / 2)))

        i, j, h, w = self.get_params(img, self.size)

        return F.to_tensor(F.crop(img, i, j, h,
                                  w)), F.to_tensor(F.crop(label, i, j, h, w))
예제 #5
0
    def __call__(self, sample):
        """
        Args:
            img (PIL Image): Image to be cropped.

        Returns:
            PIL Image: Cropped image.
        """

        if self.padding > 0:
            sample = F.pad(sample, self.padding)

        (img, target) = sample
        i, j, h, w = self.get_params(img, self.size)

        return F.crop(sample, i, j, h, w)
예제 #6
0
    def __call__(self, img):
        """
        Args:
            img (numpy ndarray): Image to be cropped.
        Returns:
            numpy ndarray: Cropped image.
        """
        if self.padding is not None:
            img = F.pad(img, self.padding, self.fill, self.padding_mode)

        # pad the width if needed
        if self.pad_if_needed and img.shape[1] < self.size[1]:
            img = F.pad(img, (self.size[1] - img.shape[1], 0), self.fill,
                        self.padding_mode)
        # pad the height if needed
        if self.pad_if_needed and img.shape[0] < self.size[0]:
            img = F.pad(img, (0, self.size[0] - img.shape[0]), self.fill,
                        self.padding_mode)

        i, j, h, w = self.get_params(img, self.size)

        return F.crop(img, i, j, h, w)