|
4 | 4 | from .image import _affine_mult
|
5 | 5 |
|
6 | 6 | __all__ = ['brightness', 'contrast', 'crop', 'crop_pad', 'cutout', 'dihedral', 'dihedral_affine', 'flip_affine', 'flip_lr',
|
7 |
| - 'get_transforms', 'jitter', 'pad', 'perspective_warp', 'rand_pad', 'rand_crop', 'rand_zoom', 'rotate', 'skew', 'squish', |
| 7 | + 'get_transforms', 'jitter', 'pad', 'perspective_warp', 'rand_pad', 'rand_crop', 'rand_zoom', 'rgb_randomize', 'rotate', 'skew', 'squish', |
8 | 8 | 'rand_resize_crop', 'symmetric_warp', 'tilt', 'zoom', 'zoom_crop']
|
9 | 9 |
|
10 | 10 | _pad_mode_convert = {'reflection':'reflect', 'zeros':'constant', 'border':'replicate'}
|
@@ -134,6 +134,14 @@ def _cutout(x, n_holes:uniform_int=1, length:uniform_int=40):
|
134 | 134 |
|
135 | 135 | cutout = TfmPixel(_cutout, order=20)
|
136 | 136 |
|
| 137 | +def _rgb_randomize(x, channel:int=None, thresh:float=0.3): |
| 138 | + "Randomize one of the channels of the input image" |
| 139 | + if channel is None: channel = np.random.randint(0, x.shape[0] - 1) |
| 140 | + x[channel] = torch.rand(x.shape[1:]) * np.random.uniform(0, thresh) |
| 141 | + return x |
| 142 | + |
| 143 | +rgb_randomize = TfmPixel(_rgb_randomize) |
| 144 | + |
137 | 145 | def _minus_epsilon(row_pct:float, col_pct:float, eps:float=1e-7):
|
138 | 146 | if row_pct==1.: row_pct -= 1e-7
|
139 | 147 | if col_pct==1.: col_pct -= 1e-7
|
|
0 commit comments