height, width, nb_channels = image.shape
downscale_factor = np.clip(1.0 - flake_size_sample, 0.001, 1.0)
height_down = int(height*downscale_factor)
width_down = int(width*downscale_factor)
noise = self._generate_noise(
height_down,
width_down,
self.density,
rss[0]
)
// gate the sampled noise via noise in range [0.0, 1.0]
// this leads to less flakes in some areas of the image and more in
// other areas
gate_noise = iap.Beta(1.0, 1.0 - self.density_uniformity)
noise = self._gate(noise, gate_noise, self.gate_noise_size, rss[1])
noise = ia.imresize_single_image(noise, (height, width),
interpolation="cubic")
// apply a bit of gaussian blur and then motion blur according to
// angle and speed
sigma = max(height, width) * blur_sigma_fraction_sample
sigma = np.clip(sigma,
self.blur_sigma_limits[0], self.blur_sigma_limits[1])
noise_small_blur = self._blur(noise, sigma)
noise_small_blur = self._motion_blur(noise_small_blur,
angle=angle_sample,
speed=speed_sample,
random_state=random_state)
// use contrast adjustment of noise to make the flake size a bit less
// uniform then readjust the noise values to make them more visible
// again
gain = 1.0 + 2*(1 - flake_size_uniformity_sample)
gain_adj = 1.0 + 5*(1 - flake_size_uniformity_sample)
noise_small_blur = contrast.GammaContrast(gain).augment_image(
noise_small_blur)
noise_small_blur = noise_small_blur.astype(np.float32) * gain_adj
noise_small_blur_rgb = np.tile(
noise_small_blur[..., np.newaxis], (1, 1, nb_channels))
// blend:
// sum for a bit of glowy, hardly visible flakes
// max for the main flakes
image_f32 = image.astype(np.float32)
image_f32 = self._blend_by_sum(
image_f32, (0.1 + 20*speed_sample) * noise_small_blur_rgb)
image_f32 = self._blend_by_max(
image_f32, (1.0 + 20*speed_sample) * noise_small_blur_rgb)
return image_f32
After Change
height, width, nb_channels = image.shape
downscale_factor = np.clip(1.0 - flake_size_sample, 0.001, 1.0)
height_down = max(1, int(height*downscale_factor))
width_down = max(1, int(width*downscale_factor))
noise = self._generate_noise(
height_down,
width_down,
self.density,
rss[0]
)
// gate the sampled noise via noise in range [0.0, 1.0]
// this leads to less flakes in some areas of the image and more in
// other areas
gate_noise = iap.Beta(1.0, 1.0 - self.density_uniformity)
noise = self._gate(noise, gate_noise, self.gate_noise_size, rss[1])
noise = ia.imresize_single_image(noise, (height, width),
interpolation="cubic")
// apply a bit of gaussian blur and then motion blur according to
// angle and speed
sigma = max(height, width) * blur_sigma_fraction_sample
sigma = np.clip(sigma,
self.blur_sigma_limits[0], self.blur_sigma_limits[1])
noise_small_blur = self._blur(noise, sigma)
noise_small_blur = self._motion_blur(noise_small_blur,
angle=angle_sample,
speed=speed_sample,
random_state=random_state)
// use contrast adjustment of noise to make the flake size a bit less
// uniform then readjust the noise values to make them more visible
// again
gain = 1.0 + 2*(1 - flake_size_uniformity_sample)
gain_adj = 1.0 + 5*(1 - flake_size_uniformity_sample)
noise_small_blur = contrast.GammaContrast(gain).augment_image(
noise_small_blur)
noise_small_blur = noise_small_blur.astype(np.float32) * gain_adj
noise_small_blur_rgb = np.tile(
noise_small_blur[..., np.newaxis], (1, 1, nb_channels))
// blend:
// sum for a bit of glowy, hardly visible flakes
// max for the main flakes
image_f32 = image.astype(np.float32)
image_f32 = self._blend_by_sum(
image_f32, (0.1 + 20*speed_sample) * noise_small_blur_rgb)
image_f32 = self._blend_by_max(
image_f32, (1.0 + 20*speed_sample) * noise_small_blur_rgb)
return image_f32