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.signal import convolve2d as conv2
- from scipy import misc
- from tkinter.filedialog import askopenfilename
- from skimage import color, data, restoration
- def RL_deconv(image, PSF, iterations):
- latent_est = image
- PSF_HAT = PSF[::-1,::-1]
- for i in range(1,iterations):
- est_conv = conv2(latent_est,PSF,'same');
- relative_blur = image/est_conv;
- error_est = conv2(relative_blur,PSF_HAT,'same');
- latent_est = latent_est* error_est;
- result = latent_est;
- return result
- #astro = color.rgb2gray( misc.imread(askopenfilename()))
- astro = color.rgb2gray(data.astronaut())
- psf = np.ones((5, 5)) / 25
- astro = conv2(astro, psf, 'same')
- # Add Noise to Image
- astro_noisy = astro.copy()
- astro_noisy += (np.random.poisson(lam=25, size=astro.shape) - 10) / 255.
- # Restore Image using Richardson-Lucy algorithm
- #deconvolved_RL = restoration.richardson_lucy(astro_noisy, psf, iterations=30)
- deconvolved_RL = RL_deconv(astro_noisy, psf, iterations=30)
- fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(8, 5))
- plt.gray()
- for a in (ax[0], ax[1], ax[2]):
- a.axis('off')
- ax[0].imshow(astro)
- ax[0].set_title('Исходное изображение')
- ax[1].imshow(astro_noisy)
- ax[1].set_title('Зашумленное изображение')
- ax[2].imshow(deconvolved_RL, vmin=astro_noisy.min(), vmax=astro_noisy.max())
- ax[2].set_title('Восстановление при помощи\n алгоритма Люси-Ричардсона')
- fig.subplots_adjust(wspace=0.02, hspace=0.2,
- top=0.9, bottom=0.05, left=0, right=1)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement