Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import numpy as np
- import matplotlib.pyplot as plt
- def mat_modexp(a,b,c):
- if b == 0:
- return np.identity(a.shape[0])
- if b % 2 == 1:
- return np.dot(a,mat_modexp(a,b-1,c)) % c
- d = mat_modexp(a,b/2,c)
- return np.dot(d,d) % c
- def tN(i,n):
- s = np.shape(i)[0]
- newIm = np.zeros(np.shape(i))
- T = mat_modexp(np.matrix( [[2,1],[1,1]] ) ,n,s)
- for x in range( s ):
- for y in range( s ):
- tC = np.dot(T, np.matrix([ [x] , [y] ]) )
- newIm[ int(tC.A1[1]) % s , int(tC.A1[0]) % s ] = i[y,x]
- return newIm
- img = np.asarray(Image.open('cat50.png'))
- tImg = np.uint8(tN(img,150))
- plt.imshow(tImg)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement