def _rotate_and_rescale(xs, ys):
"""Rotate images and labels and scale image and labels by a certain factor.
Both need to swap axis from [depth, height, width] to [height, width, depth]
required by skimage.transform library.
"""
degree = np.int(np.random.uniform(low=-3, high=5))
factor = np.random.uniform(low=0.9, high=1.1)
# swap axis
HWC_xs, HWC_ys = [np.transpose(item, [1, 2, 0]) for item in [xs, ys]]
# rotate and rescale
HWC_xs, HWC_ys = [rotate(item, degree, mode='symmetric', preserve_range=True) for item in [HWC_xs, HWC_ys]]
HWC_xs, HWC_ys = [rescale(item, factor, mode='symmetric', preserve_range=True) for item in [HWC_xs, HWC_ys]]
# swap back
xs, ys = [np.transpose(item, [2, 0, 1]) for item in [HWC_xs, HWC_ys]]
return xs, ys
评论列表
文章目录