def test_io(): # Ensure that to_planar and from_planar do the right thing to shape. a = np.array([[[1, 2, 3, 4], [5, 6, 7, 8]]], dtype='f8') assert a.shape == (1, 2, 4) b = snowy.to_planar(a) assert b.shape == (4, 1, 2) c = snowy.from_planar(b) assert np.array_equal(a, c) # Ensure that to_planar creates a copy, not a view. b[0, 0, 0] = 100 assert np.amax(a) == 8 # Ensure that from_planar creates a copy, not a view. c[0, 0, 0] == 200 assert np.amax(b) == 100 # Ensure that extract_rgb does the right thing with shape and makes # a copy rather than a view. color = snowy.extract_rgb(a) assert color.shape == (1, 2, 3) color[0, 0, 0] = 100 assert np.amax(a) == 8 # Ensure that extract_alpha does the right thing with shape and # makes a copy rather than a view. alpha = snowy.extract_alpha(a) assert alpha.shape == (1, 2, 1) alpha[0, 0, 0] = 100 assert np.amax(a) == 8 # This next snippet doesn't test Snowy but shows how to make a view # of the alpha plane. alpha_view = a[:, :, 3] assert alpha_view[0, 0] == 4 assert alpha_view[0, 1] == 8 alpha_view[0, 0] = 100 assert np.amax(a) == 100
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) # Moving on to magnification... parrot = snowy.load(qualify('parrot.png')) scale = 6 nearest = snowy.resize(parrot, width=32*scale, filter=snowy.NEAREST) mitchell = snowy.resize(parrot, height=26*scale) diptych_filename = qualify('diptych-parrot.png') parrot = snowy.hstack([nearest, mitchell]) parrot = snowy.extract_rgb(parrot) snowy.export(parrot, diptych_filename) optimize(diptych_filename) snowy.show(diptych_filename) # EXR cropping sunset = snowy.load(qualify('small.exr'), False) sunset = sunset[:100,:,:] / 50.0 cropped_filename = qualify('cropped-sunset.png') snowy.export(sunset, cropped_filename) optimize(cropped_filename) snowy.show(cropped_filename) # Alpha composition