(img, v)
| 121 | |
| 122 | |
| 123 | def CutoutAbs(img, v): # [0, 60] => percentage: [0, 0.2] |
| 124 | # assert 0 <= v <= 20 |
| 125 | if v < 0: |
| 126 | return img |
| 127 | w, h = img.size |
| 128 | x0 = np.random.uniform(w) |
| 129 | y0 = np.random.uniform(h) |
| 130 | |
| 131 | x0 = int(max(0, x0 - v / 2.)) |
| 132 | y0 = int(max(0, y0 - v / 2.)) |
| 133 | x1 = min(w, x0 + v) |
| 134 | y1 = min(h, y0 + v) |
| 135 | |
| 136 | xy = (x0, y0, x1, y1) |
| 137 | color = (125, 123, 114) |
| 138 | # color = (0, 0, 0) |
| 139 | img = img.copy() |
| 140 | PIL.ImageDraw.Draw(img).rectangle(xy, color) |
| 141 | return img |
| 142 | |
| 143 | |
| 144 | def augment_list(): |