jbohnslav / opencv_transforms

OpenCV implementation of Torchvision's image augmentations
MIT License
377 stars 46 forks source link

Bug in functional.five_crop #17

Closed fjchange closed 4 years ago

fjchange commented 4 years ago

In five_crop()

  1. get h,w from img shape wrongly.
  2. crop the image in a wrong way. It should be as belowed
def five_crop(img, size):
    if isinstance(size, numbers.Number):
        size = (int(size), int(size))
    else:
        assert len(size) == 2, "Please provide only two dimensions (h, w) for size."
    h,w = img.shape[0:2]
    crop_h, crop_w = size
    if crop_w > w or crop_h > h:
        raise ValueError("Requested crop size {} is bigger than input size {}".format(size,
                                                                                      (h, w)))
    tl = crop(img, 0, 0, crop_h, crop_w)
    tr = crop(img, 0, w-crop_w, crop_h, crop_w)
    bl = crop(img, h - crop_h,0, crop_h, crop_w)
    br = crop(img, h - crop_h, w- crop_w, crop_h, crop_w)
    center = center_crop(img, (crop_h, crop_w))
    return [tl, tr, bl, br, center]
jbohnslav commented 4 years ago

You're exactly right, I can't believe I had a height / width mixup. I incorporated your changes in 9419213. Thank you!