def random_contrast(weight=lambda: np.random.rand() * 0.3 + 0.7): def call(x): w = weight() return x * w + (1 - w) * exposure.rescale_intensity(x) return call