Esempio n. 1
0
 def get_params(self, sample: Any) -> Dict[str, Any]:
     image_size = SampleQuery(sample).image_size()
     image_height, image_width = image_size
     crop_height, crop_width = self.crop_size
     x = torch.randint(0, image_width - crop_width + 1, size=()) if crop_width < image_width else 0
     y = torch.randint(0, image_height - crop_height + 1, size=()) if crop_height < image_height else 0
     crop_box = BoundingBox.from_parts(x, y, crop_width, crop_height, image_size=image_size, format="xywh")
     return dict(crop_box=crop_box)
Esempio n. 2
0
 def get_params(self, sample: Any) -> Dict[str, Any]:
     image_size = SampleQuery(sample).image_size()
     image_height, image_width = image_size
     cx = image_width // 2
     cy = image_height // 2
     h, w = self.crop_size
     crop_box = BoundingBox.from_parts(cx, cy, w, h, image_size=image_size, format="cxcywh")
     return dict(crop_box=crop_box)
Esempio n. 3
0
    def bounding_box(input: BoundingBox, *, size: Tuple[int, int], **_: Any) -> BoundingBox:
        old_height, old_width = input.image_size
        new_height, new_width = size

        height_scale = new_height / old_height
        width_scale = new_width / old_width

        old_x1, old_y1, old_x2, old_y2 = input.convert("xyxy").to_parts()

        new_x1 = old_x1 * width_scale
        new_y1 = old_y1 * height_scale

        new_x2 = old_x2 * width_scale
        new_y2 = old_y2 * height_scale

        return BoundingBox.from_parts(
            new_x1, new_y1, new_x2, new_y2, like=input, format="xyxy", image_size=size
        ).convert(input.format)
Esempio n. 4
0
 def bounding_box(input: BoundingBox) -> BoundingBox:
     x, y, w, h = input.convert("xywh").to_parts()
     x = input.image_size[1] - (x + w)
     return BoundingBox.from_parts(x, y, w, h, like=input, format="xywh").convert(input.format)