예제 #1
0
def generator(ctx, width, height, channels, time, speed, seed, filename,
              preset_name):
    if not seed:
        seed = random.randint(1, MAX_SEED_VALUE)

    value.set_seed(seed)
    reload_presets(PRESETS)

    if preset_name == "random":
        preset_name = list(GENERATOR_PRESETS)[random.randint(
            0,
            len(GENERATOR_PRESETS) - 1)]

    print(f"{preset_name} (seed: {seed})")

    preset = GENERATOR_PRESETS[preset_name]

    try:
        preset.render(shape=[height, width, channels],
                      time=time,
                      speed=speed,
                      filename=filename)

    except Exception as e:
        util.logger.error(
            f"preset.render() failed: {e}\nSeed: {seed}\nArgs: {preset.__dict__}"
        )
        raise
예제 #2
0
def effect(ctx, seed, filename, no_resize, time, speed, preset_name, input_filename):
    if not seed:
        seed = random.randint(1, MAX_SEED_VALUE)

    value.set_seed(seed)
    reload_presets(PRESETS)

    input_shape = util.shape_from_file(input_filename)

    input_shape[2] = min(input_shape[2], 3)

    tensor = tf.image.convert_image_dtype(util.load(input_filename, channels=input_shape[2]), dtype=tf.float32)

    if preset_name == "random":
        preset_name = list(EFFECT_PRESETS)[random.randint(0, len(EFFECT_PRESETS) - 1)]

    print(f"{preset_name} (seed: {seed})")

    preset = EFFECT_PRESETS[preset_name]

    if no_resize:
        shape = input_shape

    else:
        shape = [1024, 1024, input_shape[2]]

        tensor = effects.square_crop_and_resize(tensor, input_shape, shape[0])

    try:
        preset.render(tensor=tensor, shape=shape, time=time, speed=speed, filename=filename)

    except Exception as e:
        util.logger.error(f"preset.render() failed: {e}\nSeed: {seed}\nArgs: {preset.__dict__}")
        raise
예제 #3
0
def animation(ctx, width, height, channels, seed, effect_preset, filename, save_frames, frame_count, watermark, preset_name):
    if seed is None:
        seed = random.randint(1, MAX_SEED_VALUE)

    value.set_seed(seed)
    reload_presets(PRESETS)

    if preset_name == 'random':
        preset_name = list(GENERATOR_PRESETS)[random.randint(0, len(GENERATOR_PRESETS) - 1)]

    if effect_preset == 'random':
        effect_preset = list(EFFECT_PRESETS)[random.randint(0, len(EFFECT_PRESETS) - 1)]

    if effect_preset:
        print(f"{preset_name} vs. {effect_preset} (seed: {seed})")
    else:
        print(f"{preset_name} (seed: {seed})")

    preset = GENERATOR_PRESETS[preset_name]

    with tempfile.TemporaryDirectory() as tmp:
        for i in range(frame_count):
            frame_filename = f'{tmp}/{i:04d}.png'

            common_params = ['--seed', str(seed),
                             '--time', f'{i/frame_count:0.4f}',
                             '--filename', frame_filename]

            util.check_call(['noisemaker', 'generator', preset_name,
                             '--speed', str(_use_reasonable_speed(preset, frame_count)),
                             '--height', str(height),
                             '--width', str(width)] + common_params)

            if effect_preset:
                util.check_call(['noisemaker', 'effect', effect_preset, frame_filename,
                                 '--no-resize',
                                 '--speed', str(_use_reasonable_speed(EFFECT_PRESETS[effect_preset], frame_count))] + common_params)

            if save_frames:
                shutil.copy(frame_filename, save_frames)

            if watermark:
                util.watermark(watermark, frame_filename)

        if filename.endswith(".mp4"):
            # when you want something done right
            util.check_call(['ffmpeg',
                             '-y',  # overwrite existing
                             '-framerate', '30',
                             '-i', f'{tmp}/%04d.png',
                             '-c:v', 'libx264',  # because this is what twitter wants
                             '-pix_fmt', 'yuv420p',  # because this is what twitter wants
                             '-b:v', '1700000',  # maximum allowed bitrate for 720x720 (2048k), minus some encoder overhead
                             '-s', '720x720',  # a twitter-recommended size
                             filename])

        else:
            util.magick(f'{tmp}/*png', filename)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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)