Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import matplotlib.image as mpimg
- import scipy.signal as signal
- import numpy as np
- # Tweakable
- strip_count = 12 # amount of subdivisions on x-axis
- effect_power = 12 # bump effect strength
- hMap = mpimg.imread("h3.png") # heightmap to apply
- cMap = 'viridis' # matplotlib colormap
- imgRes = [int(len(hMap[0])),int(len(hMap))]
- stripSize = [int(imgRes[0]/strip_count),imgRes[1]]
- final = np.zeros((imgRes[1],imgRes[0])) # placeholder for final image, filled with .0
- def draw_strip(id): # -> void
- for y in range(len(noise)):
- for x in range(len(noise[0])):
- # calculate pixel movement based on heightmap
- hv = int(hMap[y][x+stripSize[0]*id][0]*effect_power)
- final[y][x+stripSize[0]*id] = final[y][x-stripSize[0]+stripSize[0]*id+hv]
- def get_smooth_noise(size):
- n = np.random.uniform(1.,.0,size)
- n = signal.convolve2d(n, np.ones((4,4)) / 16,"same")
- for y in range(len(n)):
- for i in range(0,2):
- n[y][i] = (n[y][i+1] + n[y][i+2] + n[y][i+3] + n[y][i+4])/4
- n[y][len(n[0])-1] = (n[y][0] + n[y][1] + n[y][2])/3
- return n
- def create_stereogram():
- # Drawing first reference strip of noise
- for y in range(len(noise)):
- for x in range(len(noise[0])):
- final[y][x] = noise[y][x]
- for i in range(1,strip_count):
- draw_strip(i)
- pltimg = plt.imshow(final,cmap=cMap)
- plt.show()
- noise = get_smooth_noise((stripSize[1],stripSize[0]))
- create_stereogram()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement