From e089bcc7c4b3ff54cf5adb98231ddb82f857d0ed Mon Sep 17 00:00:00 2001 From: Laurent Fainsin Date: Wed, 29 Jun 2022 10:16:26 +0200 Subject: [PATCH] feat: check for overlapping when pasting Former-commit-id: 920a2df1e54e3dfc22cf62fe9c892bf945af9b63 [formerly f0c2daaa4d0094fafeddce9c07c6ce020c1704d6] Former-commit-id: 7e74f04ed0cd0d31612f23a44b9832b659bf5408 --- src/utils/paste.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/paste.py b/src/utils/paste.py index 5ad8961..6dbaa6b 100644 --- a/src/utils/paste.py +++ b/src/utils/paste.py @@ -107,9 +107,15 @@ class RandomPaste(A.DualTransform): # generate some positions positions = [] - for _ in range(rd.randint(1, self.nb)): + while len(positions) <= rd.randint(1, self.nb): x = rd.randint(0, target_shape[0] - paste_shape[0]) y = rd.randint(0, target_shape[1] - paste_shape[1]) + + # check for overlapping + for xo, yo in positions: + if (x <= xo + paste_shape[0]) and (y <= yo + paste_shape[1]): + continue + positions.append((x, y)) params.update(