def render(ctx, width, height, input_dir, voronoi_func, voronoi_nth, point_freq, point_distrib, point_drift, name): shape = [height, width, 3] x, y = points.point_cloud(point_freq, distrib=point_distrib, shape=shape, drift=point_drift) base = generators.basic(freq=random.randint(2, 4), shape=shape, lattice_drift=random.randint(0, 1), hue_range=random.random()) tensor = effects.voronoi(base, shape, diagram_type=effects.VoronoiDiagramType.collage, xy=(x, y, len(x)), nth=voronoi_nth, input_dir=input_dir, alpha=.333 + random.random() * .333) tensor = effects.bloom(tensor, shape, alpha=.333 + random.random() * .333) with tf.Session().as_default(): save(tensor, name) print('mashup')
def _control(): shape = [SMALL_Y, SMALL_X, 1] control = generators.multires(shape=shape, freq=FREQ, octaves=OCTAVES, refract_range=.5) erode_kwargs = { "alpha": .025, "density": 40, "iterations": 20, "inverse": True, } iterations = 5 for i in range(iterations): control = effects.erode(control, shape, **erode_kwargs) control = effects.convolve(constants.ValueMask.conv2d_blur, control, shape) post_shape = [LARGE_Y, LARGE_X, 1] control = effects.resample(control, post_shape) iterations = 2 for i in range(iterations): control = effects.erode(control, post_shape, **erode_kwargs) control = effects.convolve(constants.ValueMask.conv2d_blur, control, post_shape) control = effects.convolve(constants.ValueMask.conv2d_sharpen, control, post_shape) control = effects.normalize(control) with tf.Session().as_default(): save(control, CONTROL_FILENAME)
def lowland(): shape = [LARGE_Y, LARGE_X, 3] kwargs = { "deriv": 1, "deriv_alpha": .5, "freq": FREQ, "hue_range": .125 + random.random() * .25, "hue_rotation": .875 + random.random() * .125, "lattice_drift": 1, "octaves": OCTAVES, "point_freq": 5, "saturation": SATURATION * 2, "voronoi_alpha": .333, "voronoi_inverse": True, "voronoi_nth": 0, "with_voronoi": 2, } tensor = generators.multires(shape=shape, **kwargs) tensor = tf.image.adjust_brightness(tensor, .1) with tf.Session().as_default(): save(tensor, LOW_FILENAME)
def main(ctx, width, height, channels, seed, name, preset_name): generators.set_seed(seed) kwargs, preset_name = presets.load(preset_name) print(preset_name) kwargs["shape"] = [height, width, channels] # print(kwargs) if "freq" not in kwargs: kwargs["freq"] = 3 if "octaves" not in kwargs: kwargs["octaves"] = 1 if "ridges" not in kwargs: kwargs["ridges"] = False tensor = generators.multires(**kwargs) tensor = recipes.post_process(tensor, **kwargs) with tf.Session().as_default(): save(tensor, name)
def render(self, tensor=None, shape=DEFAULT_SHAPE, time=0.0, speed=1.0, filename="art.png"): """Render the preset to an image file.""" # import json # logger.debug("Rendering noise: " # + json.dumps(self.__dict__, # default=lambda v: dict(v) if isinstance(v, SettingsDict) else str(v), # indent=4)) try: tensor = multires(tensor=tensor, shape=shape, octave_effects=self.octave_effects, post_effects=self.post_effects, time=time, speed=speed, **self.generator_kwargs) with tf.compat.v1.Session().as_default(): save(tensor, filename) except Exception as e: logger.error(f"Error rendering preset named {self.name}: {e}") raise
def main(ctx, name, input_filename): tensor = tf.image.convert_image_dtype(load(input_filename), tf.float32) max_height = 1024 max_width = 1024 with tf.Session().as_default(): height, width, channels = tf.shape(tensor).eval() need_resample = False if height != width: length = min(height, width) height = length width = length tensor = tf.image.resize_image_with_crop_or_pad(tensor, length, length) if height > max_height: need_resample = True width = int(width * (max_height / height)) height = max_height if width > max_width: need_resample = True height = int(height * (max_width / width)) width = max_width shape = [height, width, channels] if need_resample: tensor = effects.resample(tensor, shape) save(tensor, name)
def main(ctx, seed, name, preset_name, input_filename): generators.set_seed(seed) tensor = tf.image.convert_image_dtype(load(input_filename), tf.float32) max_height = 1024 max_width = 1024 with tf.Session().as_default(): height, width, channels = tf.shape(tensor).eval() need_resample = False # Some presets only like square images. Work around for now by cropping. if height != width: length = min(height, width) height = length width = length tensor = tf.image.resize_image_with_crop_or_pad(tensor, length, length) if height > max_height: need_resample = True width = int(width * (max_height / height)) height = max_height if width > max_width: need_resample = True height = int(height * (max_width / width)) width = max_width shape = [height, width, channels] if need_resample: tensor = effects.resample(tensor, shape) kwargs, preset_name = presets.load(preset_name, presets.EFFECTS_PRESETS()) kwargs["shape"] = [height, width, channels] if "freq" not in kwargs: kwargs["freq"] = [3, 3] if "octaves" not in kwargs: kwargs["octaves"] = 1 if "ridges" not in kwargs: kwargs["ridges"] = False tensor = effects.post_process(tensor, **kwargs) tensor = recipes.post_process(tensor, **kwargs) print(preset_name) save(tensor, name)
def blended(): shape = [LARGE_Y, LARGE_X, 3] erode_kwargs = { "alpha": .025, "density": 250, "iterations": 50, "inverse": True, } control = tf.image.convert_image_dtype(load(CONTROL_FILENAME), tf.float32) water = tf.ones(shape) * tf.stack([.05, .2, .333]) water = effects.blend(water, control * 4.0, .125) low = tf.image.convert_image_dtype(load(LOW_FILENAME), tf.float32) mid = tf.image.convert_image_dtype(load(MID_FILENAME), tf.float32) high = tf.image.convert_image_dtype(load(HIGH_FILENAME), tf.float32) blend_control = generators.multires(shape=shape, freq=FREQ * 4, ridges=True, octaves=4) blend_control = 1.0 - effects.value_map( blend_control, shape, keep_dims=True) * .5 combined_land = effects.blend_layers(control, shape, blend_control, control * 2, low, mid, high) combined_land = effects.erode(combined_land, shape, xy_blend=.25, **erode_kwargs) combined_land = effects.erode(combined_land, shape, **erode_kwargs) combined_land_0 = effects.shadow(combined_land, shape, alpha=1.0) combined_land_1 = effects.shadow(combined_land, shape, alpha=1.0, reference=control) combined_land = effects.blend(combined_land_0, combined_land_1, .5) combined = effects.blend_layers(control, shape, .01, water, combined_land, combined_land, combined_land) combined = effects.blend(combined_land, combined, .625) combined = tf.image.adjust_brightness(combined, .1) combined = tf.image.adjust_contrast(combined, .75) combined = tf.image.adjust_saturation(combined, .625) with tf.Session().as_default(): save(combined, BLENDED_FILENAME)
def mashup(ctx, input_dir, filename, control_filename, time, speed, seed): filenames = [] for root, _, files in os.walk(input_dir): for f in files: if f.endswith(('.png', '.jpg')): filenames.append(os.path.join(root, f)) collage_count = min(random.randint(4, 6), len(filenames)) collage_images = [] for i in range(collage_count + 1): index = random.randint(0, len(filenames) - 1) input_filename = os.path.join(input_dir, filenames[index]) collage_input = tf.image.convert_image_dtype(util.load(input_filename, channels=3), dtype=tf.float32) collage_images.append(collage_input) if control_filename: control_shape = util.shape_from_file(control_filename) control = tf.image.convert_image_dtype(util.load(control_filename, channels=control_shape[2]), dtype=tf.float32) else: control = collage_images.pop() shape = tf.shape(control) # All images need to be the same size! control = value.value_map(control, shape, keepdims=True) base = generators.basic(freq=random.randint(2, 5), shape=shape, lattice_drift=random.randint(0, 1), hue_range=random.random(), seed=seed, time=time, speed=speed) value_shape = value.value_shape(shape) control = value.convolve(kernel=effects.ValueMask.conv2d_blur, tensor=control, shape=value_shape) with tf.compat.v1.Session().as_default(): tensor = effects.blend_layers(control, shape, random.random() * .5, *collage_images) tensor = value.blend(tensor, base, .125 + random.random() * .125) tensor = effects.bloom(tensor, shape, alpha=.25 + random.random() * .125) tensor = effects.shadow(tensor, shape, alpha=.25 + random.random() * .125, reference=control) tensor = tf.image.adjust_brightness(tensor, .05) tensor = tf.image.adjust_contrast(tensor, 1.25) util.save(tensor, filename) print('mashup')
def main(ctx, name, retro_upscale, input_filename): shape = shape_from_file(input_filename) tensor = tf.image.convert_image_dtype(load(input_filename, channels=3), tf.float32) if retro_upscale: shape = [shape[0] * 2, shape[1] * 2, shape[2]] tensor = value.resample(tensor, shape, spline_order=0) tensor = effects.square_crop_and_resize(tensor, shape, 1024) with tf.compat.v1.Session().as_default(): save(tensor, name)
def clouds(input_filename): tensor = tf.image.convert_image_dtype(load(input_filename), tf.float32) pre_shape = [SMALL_Y, SMALL_X, 1] post_shape = [LARGE_Y, LARGE_X, 1] control_kwargs = { "freq": FREQ * 2, "lattice_drift": 1, "octaves": OCTAVES, "ridges": True, "shape": pre_shape, "warp_freq": 3, "warp_range": .25, "warp_octaves": 2, } control = generators.multires(**control_kwargs) layer_0 = tf.ones(pre_shape) layer_1 = tf.zeros(pre_shape) combined = effects.blend_layers(control, pre_shape, 1.0, layer_0, layer_1) shadow = effects.offset(combined, pre_shape, random.randint(-15, 15), random.randint(-15, 15)) shadow = tf.minimum(shadow * 2.5, 1.0) shadow = effects.convolve(effects.ConvKernel.blur, shadow, pre_shape) shadow = effects.convolve(effects.ConvKernel.blur, shadow, pre_shape) shadow = effects.convolve(effects.ConvKernel.blur, shadow, pre_shape) shadow = effects.resample(shadow, post_shape) combined = effects.resample(combined, post_shape) tensor = effects.blend(tensor, tf.zeros(post_shape), shadow * .5) tensor = effects.blend(tensor, tf.ones(post_shape), combined) post_shape = [LARGE_Y, LARGE_X, 3] tensor = effects.shadow(tensor, post_shape, alpha=.25) tensor = effects.bloom(tensor, post_shape, .333) tensor = recipes.dither(tensor, post_shape, .075) combined = tf.image.adjust_contrast(combined, 1.125) with tf.Session().as_default(): save(tensor, FINAL_FILENAME)
def frame(ctx, input_dir, frame, seed, filename, width, height): value.set_seed(seed) shape = [height, width, 3] dirnames = [d for d in os.listdir(input_dir) if os.path.isdir(os.path.join(input_dir, d))] if not dirnames: click.echo("Couldn't determine directory names inside of input dir " + input_dir) sys.exit(1) collage_count = min(random.randint(4, 6), len(dirnames)) collage_images = [] for i in range(collage_count + 1): index = random.randint(0, len(dirnames) - 1) dirname = dirnames[index] filenames = [f for f in sorted(os.listdir(os.path.join(input_dir, dirname))) if f.endswith('.png')] if not filenames: continue input_filename = os.path.join(input_dir, dirname, filenames[frame]) collage_images.append(tf.image.convert_image_dtype(util.load(input_filename, channels=3), dtype=tf.float32)) base = generators.basic(freq=random.randint(2, 4), shape=shape, hue_range=random.random(), seed=seed, time=frame/30.0, speed=0.125) control = value.value_map(collage_images.pop(), shape, keepdims=True) control = value.convolve(kernel=effects.ValueMask.conv2d_blur, tensor=control, shape=[shape[0], shape[1], 1]) with tf.compat.v1.Session().as_default(): tensor = effects.blend_layers(control, shape, random.random() * .5, *collage_images) tensor = value.blend(tensor, base, .125 + random.random() * .125) tensor = effects.bloom(tensor, shape, alpha=.25 + random.random() * .125) tensor = effects.shadow(tensor, shape, alpha=.25 + random.random() * .125, reference=control) tensor = tf.image.adjust_brightness(tensor, .05) tensor = tf.image.adjust_contrast(tensor, 1.25) util.save(tensor, filename)
def render(ctx, glitch, vhs, crt, scan_error, snow, dither, aberration, bloom, name, input_filename): tensor = tf.image.convert_image_dtype(load(input_filename), tf.float32) freq = [3, 3] max_height = 1024 max_width = 1024 with tf.compat.v1.Session().as_default(): height, width, channels = tf.shape(tensor).eval() need_resample = False if height > max_height: need_resample = True width = int(width * (max_height / height)) height = max_height if width > max_width: need_resample = True height = int(height * (max_width / width)) width = max_width shape = [height, width, channels] if need_resample: tensor = value.resample(tensor, shape) tensor = effects.post_process(tensor, shape=shape, freq=freq, with_bloom=bloom, with_aberration=aberration, with_glitch=glitch, with_vhs=vhs, with_crt=crt, with_scan_error=scan_error, with_snow=snow, with_dither=dither) save(tensor, name) print(name)
def main(ctx, seed, name, no_resize, overrides, time, preset_name, input_filename): presets.bake_presets(seed) input_shape = effects.shape_from_file(input_filename) input_shape[2] = min(input_shape[2], 3) tensor = tf.image.convert_image_dtype(load(input_filename, channels=input_shape[2]), dtype=tf.float32) if preset_name == 'random': preset_name = 'random-effect' kwargs = presets.preset(preset_name) print(kwargs['name']) kwargs['time'] = time if 'freq' not in kwargs: kwargs['freq'] = [3, 3] if 'octaves' not in kwargs: kwargs['octaves'] = 1 if 'ridges' not in kwargs: kwargs['ridges'] = False if no_resize: kwargs['shape'] = input_shape else: kwargs['shape'] = [1024, 1024, input_shape[2]] tensor = effects.square_crop_and_resize(tensor, input_shape, kwargs['shape'][0]) if overrides: kwargs.update(json.loads(overrides)) tensor = effects.post_process(tensor, **kwargs) tensor = recipes.post_process(tensor, **kwargs) with tf.Session().as_default(): save(tensor, name)
def basic(ctx, width, height, input_dir, name): shape = [height, width, 3] filenames = [ f for f in os.listdir(input_dir) if f.endswith(".png") or f.endswith(".jpg") ] collage_count = min(random.randint(3, 5), len(filenames)) collage_images = [] for i in range(collage_count + 1): index = random.randint(0, len(filenames) - 1) collage_input = tf.image.convert_image_dtype(util.load( os.path.join(input_dir, filenames[index])), dtype=tf.float32) collage_images.append(effects.resample(collage_input, shape)) base = generators.basic(freq=random.randint(2, 5), shape=shape, lattice_drift=random.randint(0, 1), hue_range=random.random()) control = effects.value_map(collage_images.pop(), shape, keep_dims=True) tensor = effects.blend_layers(control, shape, random.random() * .5, *collage_images) tensor = effects.blend(tensor, base, .125 + random.random() * .125) tensor = effects.bloom(tensor, shape, alpha=.25 + random.random() * .125) tensor = effects.shadow(tensor, shape, alpha=.25 + random.random() * .125) tensor = tf.image.adjust_brightness(tensor, .05) tensor = tf.image.adjust_contrast(tensor, 1.25) with tf.Session().as_default(): save(tensor, name) print(name)
def midland(): shape = [LARGE_Y, LARGE_X, 3] kwargs = { "deriv": 1, "deriv_alpha": .25, "freq": FREQ * 2, "hue_range": .25 + random.random() * .125, "hue_rotation": .875 + random.random() * .1, "octaves": OCTAVES, "point_freq": 5, "saturation": SATURATION * 2, "voronoi_refract": .5, "voronoi_alpha": .5, "voronoi_nth": 1, "with_voronoi": 6, } tensor = generators.multires(shape=shape, **kwargs) with tf.Session().as_default(): save(tensor, MID_FILENAME)
def main(ctx, width, height, channels, time, clut, seed, overrides, name, preset_name): presets.bake_presets(seed) if preset_name == 'random': preset_name = 'random-preset' kwargs = presets.preset(preset_name) print(kwargs['name']) kwargs['shape'] = [height, width, channels] kwargs['time'] = time if 'freq' not in kwargs: kwargs['freq'] = 3 if 'octaves' not in kwargs: kwargs['octaves'] = 1 if 'ridges' not in kwargs: kwargs['ridges'] = False if clut: kwargs['clut'] = clut kwargs['clut_horizontal'] = True if overrides: kwargs.update(json.loads(overrides)) # print(json.dumps(kwargs, sort_keys=True, indent=4, default=str)) tensor = generators.multires(**kwargs) tensor = recipes.post_process(tensor, **kwargs) with tf.Session().as_default(): save(tensor, name)
def run_preset(preset_name, shape, filename, tensor=None): kwargs = presets.preset(preset_name) kwargs['shape'] = shape if 'freq' not in kwargs: kwargs['freq'] = 3 if 'octaves' not in kwargs: kwargs['octaves'] = 1 if 'ridges' not in kwargs: kwargs['ridges'] = False kwargs['post_brightness'] = .125 if tensor is None: tensor = generators.multires(**kwargs) tensor = recipes.post_process(tensor, **kwargs) with tf.Session().as_default(): save(tensor, filename)
def highland(): shape = [LARGE_Y, LARGE_X, 3] kwargs = { "deriv": 1, "deriv_alpha": 0.25 + random.random() * .125, "freq": FREQ * 4, "hue_range": .125 + random.random() * .125, "hue_rotation": .925 + random.random() * .05, "octaves": OCTAVES, "point_freq": 8, "ridges": True, "saturation": SATURATION, "voronoi_alpha": .5, "voronoi_nth": 3, "with_voronoi": 2, } tensor = generators.multires(shape=shape, **kwargs) tensor = tf.image.adjust_brightness(tensor, .1) with tf.Session().as_default(): save(tensor, HIGH_FILENAME)
def main(ctx, freq, width, height, channels, time, octaves, octave_blending, ridges, post_ridges, sin, wavelet, lattice_drift, vortex, warp, warp_octaves, warp_interp, warp_freq, warp_map, reflect, refract, refract_y_from_offset, reindex, reverb, reverb_iterations, post_reindex, post_reflect, post_refract, post_refract_y_from_offset, clut, clut_horizontal, clut_range, ripple, ripple_freq, ripple_kink, worms, worms_density, worms_drunkenness, worms_duration, worms_stride, worms_stride_deviation, worms_alpha, worms_kink, wormhole, wormhole_kink, wormhole_stride, sobel, outline, normals, post_deriv, deriv, deriv_alpha, interp, distrib, corners, mask, mask_inverse, glyph_map, glyph_map_colorize, glyph_map_zoom, glyph_map_alpha, composite, composite_zoom, posterize, erosion_worms, voronoi, voronoi_metric, voronoi_nth, voronoi_alpha, voronoi_refract, voronoi_refract_y_from_offset, voronoi_inverse, glitch, vhs, crt, scan_error, snow, dither, aberration, light_leak, vignette, vignette_brightness, pop, convolve, shadow, bloom, color_space, hue_range, hue_rotation, saturation, hue_distrib, saturation_distrib, post_hue_rotation, post_saturation, brightness_distrib, input_dir, dla, dla_padding, point_freq, point_distrib, point_corners, point_generations, point_drift, density, palette, seed, name): value.set_seed(seed) if color_space == "grayscale": if channels > 2: channels = 1 else: if channels < 3: channels = 3 shape = [height, width, channels] tensor = generators.multires_old( freq=freq, shape=shape, time=time, octaves=octaves, octave_blending=octave_blending, ridges=ridges, post_ridges=post_ridges, sin=sin, wavelet=wavelet, lattice_drift=lattice_drift, reflect_range=reflect, refract_range=refract, reindex_range=reindex, refract_y_from_offset=refract_y_from_offset, with_reverb=reverb, reverb_iterations=reverb_iterations, post_reindex_range=post_reindex, post_reflect_range=post_reflect, post_refract_range=post_refract, post_refract_y_from_offset=post_refract_y_from_offset, ripple_range=ripple, ripple_freq=ripple_freq, ripple_kink=ripple_kink, clut=clut, clut_horizontal=clut_horizontal, clut_range=clut_range, with_worms=worms, worms_density=worms_density, worms_drunkenness=worms_drunkenness, worms_duration=worms_duration, worms_stride=worms_stride, worms_stride_deviation=worms_stride_deviation, worms_alpha=worms_alpha, worms_kink=worms_kink, with_wormhole=wormhole, wormhole_kink=wormhole_kink, wormhole_stride=wormhole_stride, with_erosion_worms=erosion_worms, with_voronoi=voronoi, voronoi_metric=voronoi_metric, voronoi_nth=voronoi_nth, voronoi_alpha=voronoi_alpha, voronoi_refract=voronoi_refract, voronoi_inverse=voronoi_inverse, voronoi_refract_y_from_offset=voronoi_refract_y_from_offset, with_dla=dla, dla_padding=dla_padding, point_freq=point_freq, point_distrib=point_distrib, point_corners=point_corners, point_generations=point_generations, point_drift=point_drift, with_outline=outline, with_sobel=sobel, with_normal_map=normals, post_deriv=post_deriv, deriv=deriv, deriv_alpha=deriv_alpha, spline_order=interp, distrib=distrib, corners=corners, mask=mask, mask_inverse=mask_inverse, with_glyph_map=glyph_map, glyph_map_colorize=glyph_map_colorize, glyph_map_zoom=glyph_map_zoom, glyph_map_alpha=glyph_map_alpha, with_composite=composite, composite_zoom=composite_zoom, warp_range=warp, warp_octaves=warp_octaves, warp_interp=warp_interp, warp_freq=warp_freq, warp_map=warp_map, posterize_levels=posterize, vortex_range=vortex, color_space=color_space, hue_range=hue_range, hue_rotation=hue_rotation, saturation=saturation, post_hue_rotation=post_hue_rotation, post_saturation=post_saturation, hue_distrib=hue_distrib, brightness_distrib=brightness_distrib, saturation_distrib=saturation_distrib, input_dir=input_dir, with_aberration=aberration, with_bloom=bloom, with_pop=pop, with_light_leak=light_leak, with_vignette=vignette, vignette_brightness=vignette_brightness, with_density_map=density, with_convolve=convolve, with_shadow=shadow, with_palette=palette, with_glitch=glitch, with_vhs=vhs, with_crt=crt, with_scan_error=scan_error, with_snow=snow, with_dither=dither) with tf.compat.v1.Session().as_default(): save(tensor, name) print(name)
def main(ctx, width, height, channels, time, clut, seed, overrides, settings, name, preset_name): value.set_seed(seed) presets.bake_presets() if preset_name == 'random': preset_name = 'random-preset' kwargs = presets.preset(preset_name) kwargs['shape'] = [height, width, channels] kwargs['time'] = time if 'freq' not in kwargs: kwargs['freq'] = 3 if 'octaves' not in kwargs: kwargs['octaves'] = 1 if 'ridges' not in kwargs: kwargs['ridges'] = False if clut: kwargs['clut'] = clut kwargs['clut_horizontal'] = True if overrides: kwargs.update(json.loads(overrides)) if settings: for k, v in sorted(kwargs.items()): if k in {'name', 'shape', 'time'}: continue if k in {'ridges', 'with_convolve'} and not v: continue if k == 'octaves' and v == 1: continue if isinstance(v, float): v = f'{v:.02f}' if isinstance(v, Enum): v = v.name print(f'{k}: {v}') import sys sys.exit() else: print(kwargs['name']) try: tensor = generators.multires_old(**kwargs) except Exception as e: logger.error( f"generators.multires_old() failed: {e}\nSeed: {seed}\nArgs: {dumps(kwargs)}" ) raise with tf.compat.v1.Session().as_default(): save(tensor, name)
def main(ctx, freq, width, height, channels, octaves, ridges, post_ridges, sin, wavelet, lattice_drift, vortex, warp, warp_octaves, warp_interp, warp_freq, reflect, refract, reindex, reverb, reverb_iterations, post_reindex, post_reflect, post_refract, clut, clut_horizontal, clut_range, ripple, ripple_freq, ripple_kink, worms, worms_density, worms_duration, worms_stride, worms_stride_deviation, worms_alpha, worms_kink, wormhole, wormhole_kink, wormhole_stride, sobel, outline, normals, post_deriv, deriv, deriv_alpha, interp, distrib, corners, mask, mask_inverse, posterize, erosion_worms, voronoi, voronoi_func, voronoi_nth, voronoi_alpha, voronoi_refract, voronoi_inverse, glitch, vhs, crt, scan_error, snow, dither, aberration, light_leak, vignette, vignette_brightness, pop, bloom, rgb, hue_range, hue_rotation, saturation, saturation_distrib, post_hue_rotation, post_saturation, brightness_distrib, input_dir, dla, dla_padding, point_freq, point_distrib, point_corners, point_generations, point_drift, shadow, density, seed, name, **convolve_kwargs): generators.set_seed(seed) shape = [height, width, channels] tensor = generators.multires(freq=freq, shape=shape, octaves=octaves, ridges=ridges, post_ridges=post_ridges, sin=sin, wavelet=wavelet, lattice_drift=lattice_drift, reflect_range=reflect, refract_range=refract, reindex_range=reindex, with_reverb=reverb, reverb_iterations=reverb_iterations, post_reindex_range=post_reindex, post_reflect_range=post_reflect, post_refract_range=post_refract, ripple_range=ripple, ripple_freq=ripple_freq, ripple_kink=ripple_kink, clut=clut, clut_horizontal=clut_horizontal, clut_range=clut_range, with_worms=worms, worms_density=worms_density, worms_duration=worms_duration, worms_stride=worms_stride, worms_stride_deviation=worms_stride_deviation, worms_alpha=worms_alpha, worms_kink=worms_kink, with_wormhole=wormhole, wormhole_kink=wormhole_kink, wormhole_stride=wormhole_stride, with_erosion_worms=erosion_worms, with_voronoi=voronoi, voronoi_func=voronoi_func, voronoi_nth=voronoi_nth, voronoi_alpha=voronoi_alpha, voronoi_refract=voronoi_refract, voronoi_inverse=voronoi_inverse, with_dla=dla, dla_padding=dla_padding, point_freq=point_freq, point_distrib=point_distrib, point_corners=point_corners, point_generations=point_generations, point_drift=point_drift, with_outline=outline, with_sobel=sobel, with_normal_map=normals, post_deriv=post_deriv, deriv=deriv, deriv_alpha=deriv_alpha, spline_order=interp, distrib=distrib, corners=corners, mask=mask, mask_inverse=mask_inverse, warp_range=warp, warp_octaves=warp_octaves, warp_interp=warp_interp, warp_freq=warp_freq, posterize_levels=posterize, vortex_range=vortex, rgb=rgb, hue_range=hue_range, hue_rotation=hue_rotation, saturation=saturation, post_hue_rotation=post_hue_rotation, post_saturation=post_saturation, brightness_distrib=brightness_distrib, saturation_distrib=saturation_distrib, input_dir=input_dir, with_aberration=aberration, with_bloom=bloom, with_pop=pop, with_light_leak=light_leak, with_vignette=vignette, vignette_brightness=vignette_brightness, with_shadow=shadow, with_density_map=density, **convolve_kwargs) tensor = recipes.post_process(tensor, shape=shape, freq=freq, with_glitch=glitch, with_vhs=vhs, with_crt=crt, with_scan_error=scan_error, with_snow=snow, with_dither=dither) with tf.Session().as_default(): save(tensor, name) print(name)
def basic(ctx, width, height, input_dir, name, control_filename, retro_upscale): shape = [height, width, 3] # Any shape you want, as long as it's [1024, 1024, 3] filenames = [] for root, _, files in os.walk(input_dir): for filename in files: if filename.endswith(('.png', '.jpg')): filenames.append(os.path.join(root, filename)) collage_count = min(random.randint(4, 6), len(filenames)) collage_images = [] for i in range(collage_count + 1): index = random.randint(0, len(filenames) - 1) input_filename = os.path.join(input_dir, filenames[index]) collage_input = tf.image.convert_image_dtype(util.load(input_filename, channels=3), dtype=tf.float32) input_shape = effects.shape_from_file(input_filename) if retro_upscale: input_shape = [ input_shape[0] * 2, input_shape[1] * 2, input_shape[2] ] collage_input = effects.resample(collage_input, input_shape, spline_order=0) collage_input = effects.square_crop_and_resize(collage_input, input_shape, 1024) collage_images.append(collage_input) base = generators.basic(freq=random.randint(2, 5), shape=shape, lattice_drift=random.randint(0, 1), hue_range=random.random()) if control_filename: control = tf.image.convert_image_dtype(util.load(control_filename, channels=1), dtype=tf.float32) control = effects.square_crop_and_resize( control, effects.shape_from_file(control_filename), 1024) control = effects.value_map(control, shape, keep_dims=True) else: control = effects.value_map(collage_images.pop(), shape, keep_dims=True) control = effects.convolve(effects.ValueMask.conv2d_blur, control, [height, width, 1]) with tf.Session().as_default(): # sort collage images by brightness collage_images = [ j[1] for j in sorted([(tf.reduce_sum(i).eval(), i) for i in collage_images]) ] tensor = effects.blend_layers(control, shape, random.random() * .5, *collage_images) tensor = effects.blend(tensor, base, .125 + random.random() * .125) tensor = effects.bloom(tensor, shape, alpha=.25 + random.random() * .125) tensor = effects.shadow(tensor, shape, alpha=.25 + random.random() * .125, reference=control) tensor = tf.image.adjust_brightness(tensor, .05) tensor = tf.image.adjust_contrast(tensor, 1.25) save(tensor, name) print('mashup')