%%Initialisation
clear all;
close all;
clc;
T=1;
a=0.01;
b=0.01;
f=imread('lena.bmp');
[row_num col_num] = size(f)
[U,V]=meshgrid(1:row_num, 1:col_num);
U = U - floor(row_num/2);
V = V - floor(col_num/2);
K=0.0025;
p_matrix = [0 -1 0; -1 4 -1; 0 -1 0];
gamma = 1e-4;
pause
%%
%Generating Motion Blur Filter in Freq Domain
%H_degrade=(T./(pi*(U*a + V*b+eps))) .* sin((pi*(U*a + V*b+eps))) .* exp(-1i*pi*(U*a + V*b+eps));
H_degrade = psf2otf(fspecial('motion',30,135), size(f));
imwrite(H_degrade,'Degrade_Filter.bmp');
figure;
imshow(fftshift(H_degrade),[ ]);
title('Motion Blur Filter');
hold on;
pause
H_wiener = (1./H_degrade) .* (abs(H_degrade).^2) ./ ((abs(H_degrade).^2) + K);
imwrite(H_wiener,'Wiener_Filter.bmp');
figure;
imshow(fftshift(H_wiener),[ ]);
title('Wiener Filter');
hold on;
P = fft2(p_matrix, row_num, col_num);
H_cls = conj(H_degrade) ./ ((abs(H_degrade).^2) + (gamma* abs(P).^2));
imwrite(H_cls,'CLS_Filter.bmp');
figure;
imshow(fftshift(H_cls),[ ]);
title('CLS Filter');
hold on;
%%
%%
%Processing Image for getting blurry image
F=fft2(double(f));
G=H_degrade.*F;%G is the fft of blurred image
g = real(ifft2(G));
% Crop to original size.
%g =g(1:size(f, 1), 1:size(f, 2));
%Normalize the image
%g=g/255;
%g=im2uint8(g);
imwrite(g,'Blurred.bmp');
figure;
imshow(g,[]);
title('Blurred Picture');
hold on;
%%
%Restoring image without noise
g_new=g;
G_new=fft2(g_new);
F_restored=G_new./H_degrade;
f_restored=real(ifft2(F_restored));
f_restored=f_restored(1:size(f, 1), 1:size(f, 2));
imwrite(f_restored,'Restored.bmp');
figure;
imshow(f_restored,[]);
title('Restored Picture');
hold on;
%%
%Adding image to noise
g_normalized=g/max(max(g));
n_zeros = zeros(size(g));
n_high = imnoise(n_zeros,'gaussian',0,650/255^2);
n_mid = imnoise(n_zeros,'gaussian',0,6.5/255^2);
n_low = imnoise(n_zeros,'gaussian',0,0.0065/255^2);
g_high=im2double(g_normalized)+n_high;
g_mid=im2double(g_normalized)+n_mid;
g_low=im2double(g_normalized)+n_low;
figure;
subplot(4,4,1);
imshow(g,[]);
title('no noise');
subplot(4,4,5);
imshow(g_high,[]);
title('high noise');
subplot(4,4,9);
imshow(g_mid,[]);
title('mid noise');
subplot(4,4,13);
imshow(g_low,[]);
title('low noise');
%%
G_High= fft2(double(g_high));
G_Mid= fft2(double(g_mid));
G_Low= fft2(double(g_low));
F_Restored_High = G_High./H_degrade;
F_Restored_Mid = G_Mid./H_degrade;
F_Restored_Low = G_Low./H_degrade;
f_restored_high=real(ifft2(F_Restored_High));
f_restored_mid=real(ifft2(F_Restored_Mid));
f_restored_low=real(ifft2(F_Restored_Low));
subplot(4,4,2);
imshow(f_restored,[]);
title('inverse');
subplot(4,4,6);
imshow(f_restored_high,[]);
title('inverse');
subplot(4,4,10);
imshow(f_restored_mid,[]);
title('inverse');
subplot(4,4,14);
imshow(f_restored_low,[]);
title('inverse');
%%
G_High= fft2(double(g_high));
G_Mid= fft2(double(g_mid));
G_Low= fft2(double(g_low));
F_Wiener = G./H_wiener;
F_Wiener_High = G_High./H_wiener;
F_Wiener_Mid = G_Mid./H_wiener;
F_Wiener_Low = G_Low./H_wiener;
f_wiener=real(ifft2(F_Wiener));
f_wiener_high=real(ifft2(F_Wiener_High));
f_wiener_mid=real(ifft2(F_Wiener_Mid));
f_wiener_low=real(ifft2(F_Wiener_Low));
subplot(4,4,3);
imshow(f_wiener,[]);
title('wiener');
subplot(4,4,7);
imshow(f_wiener_high,[]);
title('wiener');
subplot(4,4,11);
imshow(f_wiener_mid,[]);
title('wiener');
subplot(4,4,15);
imshow(f_wiener_low,[]);
title('wiener');
%%
%cls
F_Cls = G./H_cls;
F_Cls_High = G_High./H_cls;
F_Cls_Mid = G_Mid./H_cls;
F_Cls_Low = G_Low./H_cls;
f_cls=real(ifft2(F_Cls));
f_cls_high=real(ifft2(F_Cls_High));
f_cls_mid=real(ifft2(F_Cls_Mid));
f_cls_low=real(ifft2(F_Cls_Low));
subplot(4,4,4);
imshow(f_cls,[]);
title('cls');
subplot(4,4,8);
imshow(f_cls_high,[]);
title('cls');
subplot(4,4,12);
imshow(f_cls_mid,[]);
title('cls');
subplot(4,4,16);
imshow(f_cls_low,[]);
title('cls');
wie.rar_CLS MATLAB_CLS restoration_filter_image restoration_res
版权申诉
169 浏览量
2022-07-14
21:45:06
上传
评论
收藏 85KB RAR 举报
钱亚锋
- 粉丝: 88
- 资源: 1万+
最新资源
- 锄战三国村 修改:货币使用不减 v1.10(2) 原创 (中文).apk
- 基于python实现的单目双目视觉三维重建+源代码+图像图片(高分课程设计)
- 基于C+++OPENCV的全景图像拼接源码(课程设计)
- 基于Python+OpenCV对多张图片进行全景图像拼接,消除鬼影,消除裂缝+源代码+文档说明+界面截图(高分课程设计)
- 基于C++实现的全景图像拼接源码(课程设计)
- 基于SIFT特征点提取和RASIC算法实现全景图像拼接python源码+文档说明+界面截图+详细注释(95分以上课程大作业)
- 基于matlab实现眼部判别的疲劳检测系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的异常姿势识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 隐藏文件展示工具,用来展示被病毒隐藏的文件
- 基于Matlab的图像分割系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0