def random_track_shift(track, out=None, shift_delta='auto'):
if out is None:
out = np.ndarray(shape=track.shape, dtype=track.dtype)
if shift_delta == 'auto':
track_x, track_y = np.where(track > 0)
x_from, x_to = np.min(track_x), np.max(track_x)
y_from, y_to = np.min(track_y), np.max(track_y)
x_delta = np.random.randint(-x_from, out.shape[0] - x_to)
y_delta = np.random.randint(-y_from, out.shape[1] - y_to)
out = np.roll(track, x_delta, axis=0)
out = np.roll(out, y_delta, axis=1)
return out
else:
delta = np.random.uniform(-1.0, 1.0, size=2) * shift_delta
return shift(track, delta, output=out, order=0, prefilter=False)
评论列表
文章目录