| 196 | |
| 197 | |
| 198 | def CutoutAbs(img, v): # [0, 60] => percentage: [0, 0.2] |
| 199 | # assert 0 <= v <= 20 |
| 200 | if v < 0: |
| 201 | return img |
| 202 | w, h = img.size |
| 203 | x0 = np.random.uniform(w) |
| 204 | y0 = np.random.uniform(h) |
| 205 | |
| 206 | x0 = int(max(0, x0 - v / 2.)) |
| 207 | y0 = int(max(0, y0 - v / 2.)) |
| 208 | x1 = min(w, x0 + v) |
| 209 | y1 = min(h, y0 + v) |
| 210 | |
| 211 | xy = (x0, y0, x1, y1) |
| 212 | color = (125, 123, 114) |
| 213 | # color = (0, 0, 0) |
| 214 | img = img.copy() |
| 215 | PIL.ImageDraw.Draw(img).rectangle(xy, color) |
| 216 | return img |
| 217 | |
| 218 | |
| 219 | def SamplePairing(imgs): # [0, 0.4] |