Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow full crop #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions Augmentor/Operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,21 +846,22 @@ def perform_operation(self, images):
:return: The transformed image(s) as a list of object(s) of type
PIL.Image.
"""


# The images must be of identical size, which is checked by Pipeline.ground_truth().
w, h = images[0].size

diff_w, diff_h = w - self.width, h - self.height

sign_w, sign_h = np.sign(diff_w), np.sign(diff_h)

left_shift = sign_w * random.randint(0, int(sign_w * diff_w))
down_shift = sign_h * random.randint(0, int(sign_h * diff_h))

def do(image):

w, h = image.size

# TODO: Fix. We may want a full crop.
if self.width > w or self.height > h:
return image

if self.centre:
return image.crop(((w/2)-(self.width/2), (h/2)-(self.height/2), (w/2)+(self.width/2), (h/2)+(self.height/2)))
else:
left_shift = random.randint(0, int((w - self.width)))
down_shift = random.randint(0, int((h - self.height)))
return image.crop((left_shift, down_shift, self.width + left_shift, self.height + down_shift))
top_left_x, top_left_y = min(diff_w, w - diff_w), min(diff_h, h - diff_h)
return image.crop((top_left_x, top_left_y, w - top_left_x, h - top_left_y))
return image.crop((left_shift, down_shift, self.width + left_shift, self.height + down_shift))

augmented_images = []

Expand Down