forked from brunopdias/semanainvernogeofisica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_deconv_lena.m
74 lines (57 loc) · 1.31 KB
/
ex_deconv_lena.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%
% Lena deconvolution
%
% Load octave packages
pkg load image
% make sure we have a clean environment
clear
% 1) Read image file
img = double(rgb2gray(imread("lena_rgb.png")));
[n1,n2]=size(img);
figure(1)
imagesc(img);
colormap(gray);
title("Original Image","fontsize",18)
% 2) Create PSF
x = linspace(-3,3,n1);
y = linspace(-3,3,n2);
[X Y] = meshgrid(x,y);
sigma=15;
psf = exp(-((X.^2)+(Y.^2))/(2./sigma^2));
figure(2)
imagesc(psf);
colormap(gray);
title("Point Spread Function","fontsize",18)
% 3) Spectrum
imgkk=fft2(img);
psfkk=fft2(psf);
figure(3)
imgspec=abs(fftshift(imgkk));
imagesc(imgspec,[0, quantile(imgspec(:),0.99) ]);
colormap(jet);
title("Original Image Spectrum","fontsize",18)
figure(4)
psfspec=abs(fftshift(psfkk));
imagesc(psfspec);
colormap(jet);
title("Point Spread Function Spectrum","fontsize",18)
% 4) Convolution
convkk=imgkk.*psfkk;
conv=fftshift(real(ifft2(convkk)));
noise = .1;
conv(:,:) += noise*randn(n1,n2);
figure(5)
imagesc(conv);
colormap(gray);
t=sprintf("Convolution + Noise (n=%g)",noise);
title(t,"fontsize",18)
% 5) Deconvolution
convkk=fft2(conv);
eps2=1e-5;
deconvkk=convkk.*conj(psfkk)./(psfkk.*conj(psfkk)+eps2);
deconv=fftshift(real(ifft2(deconvkk)));
figure(6)
imagesc(deconv);
colormap(gray);
t=sprintf("Deconvolution: Deblurred Image (eps2=%g)",eps2);
title(t,"fontsize",18)