Advertisement
Guest User

Catmap

a guest
Mar 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. from PIL import Image
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. def mat_modexp(a,b,c):
  6.     if b == 0:
  7.         return np.identity(a.shape[0])
  8.     if b % 2 == 1:
  9.         return np.dot(a,mat_modexp(a,b-1,c)) % c
  10.     d = mat_modexp(a,b/2,c)
  11.     return np.dot(d,d) % c
  12.  
  13. def tN(i,n):
  14.         s = np.shape(i)[0]
  15.         newIm = np.zeros(np.shape(i))
  16.         T = mat_modexp(np.matrix( [[2,1],[1,1]] ) ,n,s)
  17.  
  18.         for x in range( s ):
  19.                 for y in range( s ):
  20.                         tC = np.dot(T, np.matrix([ [x] , [y] ]) )
  21.                         newIm[ int(tC.A1[1]) % s ,  int(tC.A1[0]) % s ] = i[y,x]
  22.         return newIm
  23.  
  24. img = np.asarray(Image.open('cat50.png'))
  25.  
  26. tImg = np.uint8(tN(img,150))
  27.  
  28. plt.imshow(tImg)
  29. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement