%% Lucy_Richardson滤波器
clc,clear,close all % 清理命令区、清理工作区、关闭显示图形
warning off % 消除警告
feature jit off % 加速代码运行
[filename ,pathname]=...
uigetfile({'*.bmp';'*.tif';'*.jpg';},'选择图片'); %选择图片路径
str=[pathname filename]; % 合成路径+文件名
im = imread(str); % 读图
im = im(40:250,40:220); % 截取部分分析,考虑背景像素0(黑色)的影响
% 转化为灰度图像
if size(im,3)==1
im = im;
else
im = rgb2gray(im);
end
im = imnoise(im,'gaussian',0,1e-3); % 原图像 + 白噪声
figure,
subplot(121),imshow(im);title('原始图像')
colormap(jet) % 颜色
shading interp % 消隐
im1 = Lucy_Richardson(im, 5, 10, 50);
subplot(122),imshow(uint8(im1));title('Lucy_Richardson滤波图像')
colormap(jet) % 颜色
shading interp % 消隐
function resim = Lucy_Richardson(ifbl, LEN, THETA, iterations)
% Lucy_Richardson滤波器
%函数输入:
% ifbl: 输入的图像矩阵
% LEN: 模糊旋转长度,模糊的像素个数
% THETA: 模糊旋转角
% iterations: 迭代次数
%函数输出:
% resim: 重构滤波图像
if ~isa(ifbl,'double')
ifbl = double(ifbl);
end
ifbl = medfilt2(abs(ifbl)); %中值滤波
est = ifbl; % 初始化模糊图像赋值操作
% 点扩展函数PSF
PSF = fspecial('motion',LEN,THETA);
% 转化PSF函数到期望的维数 光传递函数OTF
OTF = psf2otf(PSF,size(ifbl));
i = 1;
while i<=iterations
fest = fft2(est); % 转化到频域
fblest = OTF.*fest; % 频率相乘
ifblest = ifft2(fblest); % 傅里叶反变换,转换到时域
% 计算模糊前的图像 与 去模糊后的图像 的比值
iratio = ifbl./(ifblest+eps);
firatio = fft2(iratio); % 转化到频域
corrvec = OTF .* firatio; % 计算相关性向量
icorrvec = ifft2(corrvec);% 傅里叶反变换,转换到时域
% 计算估计的去模糊图像矩阵
aftercorr = icorrvec.*est;
est = aftercorr;
i = i+1;
end
resim = abs(est); % 重构滤波图像
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交