示例#1
0
def create_wrap_figures():
    ground = snowy.load(qualify('ground.jpg'))
    hground = np.hstack([ground, ground])
    ground2x2 = np.vstack([hground, hground])
    snowy.export(ground2x2, qualify('ground2x2.jpg'))

    ground = snowy.blur(ground, radius=14, filter=snowy.LANCZOS)
    snowy.export(ground, qualify('blurry_ground_bad.jpg'))
    hground = np.hstack([ground, ground])
    ground2x2 = np.vstack([hground, hground])
    snowy.export(ground2x2, qualify('blurry_ground2x2_bad.jpg'))

    ground = snowy.load(qualify('ground.jpg'))

    ground = snowy.blur(ground,
                        radius=14,
                        wrapx=True,
                        wrapy=True,
                        filter=snowy.LANCZOS)
    snowy.export(ground, qualify('blurry_ground_good.jpg'))
    hground = np.hstack([ground, ground])
    ground2x2 = np.vstack([hground, hground])
    snowy.export(ground2x2, qualify('blurry_ground2x2_good.jpg'))

    n = snowy.generate_noise(256, 512, frequency=4, seed=42, wrapx=False)
    n = 0.5 + 0.5 * np.sign(n) - n
    n = np.hstack([n, n])
    n = snowy.add_border(n, width=4)
    snowy.export(n, qualify('tiled_noise_bad.png'))

    n = snowy.generate_noise(256, 512, frequency=4, seed=42, wrapx=True)
    n = 0.5 + 0.5 * np.sign(n) - n
    n = np.hstack([n, n])
    n = snowy.add_border(n, width=4)
    snowy.export(n, qualify('tiled_noise_good.png'))

    c0 = create_circle(400, 200, 0.3)
    c1 = create_circle(400, 200, 0.08, 0.8, 0.8)
    circles = np.clip(c0 + c1, 0, 1)
    mask = circles != 0.0
    sdf = snowy.unitize(snowy.generate_sdf(mask, wrapx=True, wrapy=True))
    sdf = np.hstack([sdf, sdf, sdf, sdf])
    sdf = snowy.resize(np.vstack([sdf, sdf]), width=512)
    sdf = snowy.add_border(sdf)
    snowy.export(sdf, qualify('tiled_sdf_good.png'))

    sdf = snowy.unitize(snowy.generate_sdf(mask, wrapx=False, wrapy=False))
    sdf = np.hstack([sdf, sdf, sdf, sdf])
    sdf = snowy.resize(np.vstack([sdf, sdf]), width=512)
    sdf = snowy.add_border(sdf)
    snowy.export(sdf, qualify('tiled_sdf_bad.png'))
示例#2
0
def test_gdf():
    "This is a (failed) effort to create a smoother distance field."
    c0 = create_circle(200, 200, 0.3)
    c1 = create_circle(200, 200, 0.08, 0.8, 0.8)
    c0 = np.clip(c0 + c1, 0, 1)
    circles = snowy.add_border(c0, value=1)
    circles = np.clip(snowy.blur(circles, radius=2), 0, 1)
    circles = np.clip(snowy.blur(circles, radius=2), 0, 1)
    source = (1.0 - circles) * 2000.0
    gdf = np.sqrt(snowy.generate_gdf(source))
    gdf = snowy.unitize(gdf)
    nx, ny = snowy.gradient(gdf)
    grad = snowy.unitize(nx + ny)
    snowy.show(snowy.hstack([circles, gdf, grad]))
示例#3
0
def test_range():

    source = path('../docs/ground.jpg')
    ground = snowy.load(source)
    assert np.amin(ground) >= 0 and np.amax(ground) <= 1

    with tempfile.NamedTemporaryFile() as fp:
        target = fp.name + '.png'
        snowy.save(ground, target)
        show_filename(target)

    show_filename(source)
    show_array(ground)

    blurred = snowy.blur(ground, radius=10)
    snowy.show(blurred)
示例#4
0
def test_thick():
    source = sn.load('tests/sobel_input.png')[:, :, :3]
    small_source = sn.resize(source, width=256)
    blurred = sn.blur(source, radius=2)
    small_blurred = sn.resize(blurred, width=256)

    L = skimage_sobel(blurred)
    sksobel = np.dstack([L, L, L])
    small_sksobel = sn.resize(sksobel, width=256)

    L = sn.rgb_to_luminance(blurred)
    L = sn.compute_sobel(L)
    snsobel = np.dstack([L, L, L])
    small_snsobel = sn.resize(snsobel, width=256)

    small_sksobel = np.clip(1 - small_sksobel * 40, 0, 1)
    small_snsobel = np.clip(1 - small_snsobel * 40, 0, 1)

    strip = np.hstack([
        small_blurred, small_source * small_sksobel,
        small_source * small_snsobel
    ])
    sn.show(strip)
示例#5
0
# Test noise generation

n = snowy.generate_noise(100, 100, frequency=4, seed=42, wrapx=True)
n = np.hstack([n, n])
n = 0.5 + 0.5 * n
snowy.show(n)
snowy.export(n, qualify('noise.png'))

# First try minifying grayscale

gibbons = snowy.load(qualify('snowy.jpg'))
gibbons = np.swapaxes(gibbons, 0, 2)
gibbons = np.swapaxes(gibbons[0], 0, 1)
gibbons = snowy.reshape(gibbons)
source = snowy.resize(gibbons, height=200)
blurry = snowy.blur(source, radius=4.0)
diptych_filename = qualify('diptych.png')
snowy.export(snowy.hstack([source, blurry]), diptych_filename)
optimize(diptych_filename)
snowy.show(diptych_filename)

# Next try color

gibbons = snowy.load(qualify('snowy.jpg'))
source = snowy.resize(gibbons, height=200)
blurry = snowy.blur(source, radius=4.0)
diptych_filename = qualify('diptych.png')
snowy.export(snowy.hstack([source, blurry]), diptych_filename)
optimize(diptych_filename)
snowy.show(diptych_filename)
示例#6
0
文件: snowy.py 项目: Aurametrix/Alg
import snowy

source = snowy.open('poodle.png')
source = snowy.resize(source, height=200)
blurry = snowy.blur(source, radius=4.0)
snowy.save(snowy.hstack([source, blurry]), 'diptych.png')

# This snippet does a resize, then a blur, then horizontally concatenates the two images

parrot = snowy.load('parrot.png')
height, width = parrot.shape[:2]
nearest = snowy.resize(parrot, width * 6, filter=snowy.NEAREST) 
mitchell = snowy.resize(parrot, width * 6)
snowy.show(snowy.hstack([nearest, mitchell]))

#  This snippet first magnifies an image using a nearest-neighbor filter, then using the default Mitchell filter.

parrot = snowy.load('parrot.png')
height, width = parrot.shape[:2]
nearest = snowy.resize(parrot, width * 6, filter=snowy.NEAREST) 
mitchell = snowy.resize(parrot, width * 6)
snowy.show(snowy.hstack([nearest, mitchell]))