Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. import numpy as np
  2.  
  3. import matplotlib.pyplot as plt
  4.  
  5. from scipy import signal
  6. from scipy import misc
  7. from scipy.io import loadmat
  8.  
  9. H1D = np.array([[1/16,1/4,3/8,1/4,1/16]])
  10.  
  11. H2D = np.dot(H1D.T,H1D)
  12.  
  13. imtest = misc.ascent()
  14.  
  15.  
  16. resconv = signal.convolve2d(imtest, H2D, boundary='symm', mode='same')
  17.  
  18. resconv1 = signal.convolve2d(imtest, H1D, boundary='symm', mode='same')
  19.  
  20. resconv2 = signal.convolve2d(resconv1, H1D.T, boundary='symm', mode='same')
  21.  
  22. plt.figure(figsize=(10,10))
  23. plt.imshow(imtest, cmap="gray")
  24.  
  25. plt.figure(figsize=(10,10))
  26. plt.imshow(resconv, cmap="gray")
  27.  
  28. plt.figure(figsize=(10,10))
  29. plt.imshow(resconv2, cmap="gray")
  30.  
  31. plt.figure(figsize=(10,10))
  32. plt.imshow(resconv-resconv2, cmap="gray")
  33.  
  34. def H1D2(i):
  35.     res = np.zeros((1,2**(i+2)+1))
  36.     ind = 0
  37.     for j in range(5):#a généraliser pour d'autres tailles que 5
  38.         res[0,ind] = H1D[0][j]
  39.         ind += 2**i
  40.     return res
  41.  
  42. def starlet_transform(im, n):
  43.     c = im
  44.    
  45.     c_list = [c]
  46.     w_list = []
  47.    
  48.     for i in range(n):
  49.         c_ = signal.convolve2d(c, H1D2(i), boundary='symm', mode='same')
  50.         c_ = signal.convolve2d(c_, H1D2(i).T, boundary='symm', mode='same')
  51.         w = c - c_
  52.         w_list.append(w)
  53.         c = c_
  54.         c_list.append(c)
  55.    
  56.     return c_list, w_list
  57.  
  58. C, W = starlet_transform(imtest, 3)
  59.  
  60. def reconstruct(C,W):
  61.     res = np.zeros(W[0].shape)
  62.     for i in range(len(W)):
  63.         res += W[i]
  64.    
  65.     return res + C[-1]
  66.  
  67. res = reconstruct(C,W)
  68.  
  69. ngc_mat = loadmat("ngc2997.mat")["ngc2997"]
  70.  
  71. C, W = starlet_transform(ngc_mat, 5)
  72.  
  73. res = reconstruct(C, W)
  74.  
  75. #%%
  76.  
  77. N = 200
  78.  
  79. imdirac = np.zeros((N,N))
  80.  
  81. imdirac[50,50] = N*N
  82.  
  83. C, W = starlet_transform(imdirac, 3)
  84.  
  85. res = reconstruct(C, W)
  86.  
  87. #%%
  88.  
  89. imnoise = np.random.normal(size=(100,100))
  90.  
  91. C, W = starlet_transform(imnoise, 3)
  92.  
  93. res = reconstruct(C, W)
  94.  
  95. '''
  96. rapport : python notebook
  97. ou pdf avec des figures commentées,
  98. code pas important
  99. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement