예제 #1
0
def setup(grayscale=False, imgfile='~/Desktop/SaltLakes.jpg'):
    print('Loading image...')
    global imgarray
    global pilimage
    imgarray = snowy.load(imgfile)
    if grayscale:
        assert imgarray.shape[2] == 3, "Not an RGB image."
        r, g, b = np.split(imgarray, 3, axis=2)
        imgarray = r
    pilimage = Image.fromarray(np.uint8(snowy.unshape(imgarray)))
예제 #2
0
def applyColorGradient(elevation_image, gradient_image):
    xvals = np.arange(256)
    yvals = gradient_image[0]
    apply_lut = interpolate.interp1d(xvals, yvals, axis=0)
    return apply_lut(snowy.unshape(np.clip(elevation_image, 0, 255)))
예제 #3
0
# 4. Generate normal map.

normals = snowy.resize(snowy.compute_normals(elevation), width, height)
snowy.show(0.5 + 0.5 * normals)

# 5. Apply harsh diffuse lighting.

lightdir = np.float64([0.2, -0.2, 1])
lightdir /= np.linalg.norm(lightdir)
lambert = np.sum(normals * lightdir, 2)
snowy.show(snowy.reshape(lambert) * occlusion)

# 6. Lighten the occlusion, flatten the normals, and re-light.

occlusion = 0.5 + 0.5 * occlusion
normals += np.float64([0, 0, 0.5])
normals /= snowy.reshape(np.sqrt(np.sum(normals * normals, 2)))
lambert = np.sum(normals * lightdir, 2)
lighting = snowy.reshape(lambert) * occlusion
snowy.show(lighting)

# 7. Apply color gradient.

xvals = np.arange(256)
yvals = snowy.load('tests/terrain.png')[0, :, :3]
apply_lut = interpolate.interp1d(xvals, yvals, axis=0)
el = elevation * 0.2 + 0.49
el = np.clip(255 * el, 0, 255)
albedo = apply_lut(snowy.unshape(el))
snowy.show(albedo * lighting)
예제 #4
0
 def applyColorGradient(elevation):
     xvals = np.arange(1024)
     yvals = gradient_image[0]
     apply_lut = interpolate.interp1d(xvals, yvals, axis=0)
     el = np.clip(1023 * elevation, 0, 1023)
     return apply_lut(sn.unshape(el))