Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from scipy import signal
- from scipy import misc
- from scipy.io import loadmat
- H1D = np.array([[1/16,1/4,3/8,1/4,1/16]])
- H2D = np.dot(H1D.T,H1D)
- imtest = misc.ascent()
- resconv = signal.convolve2d(imtest, H2D, boundary='symm', mode='same')
- resconv1 = signal.convolve2d(imtest, H1D, boundary='symm', mode='same')
- resconv2 = signal.convolve2d(resconv1, H1D.T, boundary='symm', mode='same')
- plt.figure(figsize=(10,10))
- plt.imshow(imtest, cmap="gray")
- plt.figure(figsize=(10,10))
- plt.imshow(resconv, cmap="gray")
- plt.figure(figsize=(10,10))
- plt.imshow(resconv2, cmap="gray")
- plt.figure(figsize=(10,10))
- plt.imshow(resconv-resconv2, cmap="gray")
- def H1D2(i):
- res = np.zeros((1,2**(i+2)+1))
- ind = 0
- for j in range(5):#a généraliser pour d'autres tailles que 5
- res[0,ind] = H1D[0][j]
- ind += 2**i
- return res
- def starlet_transform(im, n):
- c = im
- c_list = [c]
- w_list = []
- for i in range(n):
- c_ = signal.convolve2d(c, H1D2(i), boundary='symm', mode='same')
- c_ = signal.convolve2d(c_, H1D2(i).T, boundary='symm', mode='same')
- w = c - c_
- w_list.append(w)
- c = c_
- c_list.append(c)
- return c_list, w_list
- C, W = starlet_transform(imtest, 3)
- def reconstruct(C,W):
- res = np.zeros(W[0].shape)
- for i in range(len(W)):
- res += W[i]
- return res + C[-1]
- res = reconstruct(C,W)
- ngc_mat = loadmat("ngc2997.mat")["ngc2997"]
- C, W = starlet_transform(ngc_mat, 5)
- res = reconstruct(C, W)
- #%%
- N = 200
- imdirac = np.zeros((N,N))
- imdirac[50,50] = N*N
- C, W = starlet_transform(imdirac, 3)
- res = reconstruct(C, W)
- #%%
- imnoise = np.random.normal(size=(100,100))
- C, W = starlet_transform(imnoise, 3)
- res = reconstruct(C, W)
- '''
- rapport : python notebook
- ou pdf avec des figures commentées,
- code pas important
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement