Skip to content

Commit

Permalink
Merge pull request #189 from Visual-Behavior/args-resize-crop
Browse files Browse the repository at this point in the history
Pass arguments to RandomScale and RandomCrop in ResizeCropTransform
  • Loading branch information
thibo73800 authored Jul 5, 2022
2 parents a8e3871 + 7a8c45e commit 4876b3a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions alodataset/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def sample_params(self):
def apply(self, frame: Frame):
assert frame.normalization == "01", "frame should be normalized between 0 and 1 before color modification"

frame = frame**self.gamma
frame = frame ** self.gamma
frame = frame * self.brightness
# change color by applying different coefficients to R, G, and B channels
C = frame.shape[frame.names.index("C")]
Expand Down Expand Up @@ -718,7 +718,7 @@ def __init__(
contrast: tuple = 0.2,
saturation: tuple = 0.2,
hue: tuple = 0.2,
**kwargs
**kwargs,
):
"""Reszie the given frame to the target frame size.
Expand Down Expand Up @@ -856,13 +856,13 @@ class RandomDownScaleCrop(Compose):
"""

def __init__(self, size, preserve_ratio=False, *args, **kwargs):
transforms = [RandomDownScale(size, preserve_ratio), RandomCrop(size)]
transforms = [RandomDownScale(size, preserve_ratio, *args, **kwargs), RandomCrop(size, *args, **kwargs)]
super().__init__(transforms, *args, **kwargs)


class DynamicCropTransform(AloTransform):
""" Crop image to target crop size at chosen position.
"""
"""Crop image to target crop size at chosen position."""

def __init__(self, crop_size, *args, **kwargs):
assert all([isinstance(s, int) for s in crop_size])
self.crop_size = crop_size
Expand Down Expand Up @@ -894,7 +894,9 @@ def apply(self, frame: Frame, center: Union[Tuple[int, int], Tuple[float, float]
bot = top + crop_h - 1

if left < 0 or top < 0 or right > (frame.W - 1) or bot > (frame.H - 1):
raise ValueError(f"Crop coordinates out of image border.\
Image size: {frame.HW}, Crop coordinate (top, left, bot, right): ({top}, {left}, {bot}, {right})")
raise ValueError(
f"Crop coordinates out of image border.\
Image size: {frame.HW}, Crop coordinate (top, left, bot, right): ({top}, {left}, {bot}, {right})"
)

return F.crop(frame, top, left, crop_h, crop_w)

0 comments on commit 4876b3a

Please sign in to comment.