【图像去噪】基于matlab最佳加权双边滤波图像去噪【含Matlab源码 459期】
【摘要】
一、双边滤波图像去噪简介
理论知识参考文献:基于联合双边滤波的图像去噪与融合方法研究
二、部分源代码
% Image Denoising using Optimally Weighted Bilat...
一、双边滤波图像去噪简介
理论知识参考文献:基于联合双边滤波的图像去噪与融合方法研究
二、部分源代码
% Image Denoising using Optimally Weighted Bilateral Filters
%
%
% Acronyms:
%
% SBF: Standard Bilateral Filter.
% RBF: Robust Bilater Filter.
% WBF: Weighted Bilateral Filter.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% parameters
sigma = 30; % noise
sigmas = 4; % spatial gaussian kernel
sigmar1 = 20; % range gaussian kernel for SBF
sigmar2 = 20; % range gaussian kernel for RBF
w = 6*round(sigmas)+1;
tol = 0.01;
%
% read input image
%
f0 = double(imread('./images/cameraman.tif'));
[m,n]=size(f0);
%
% generate noise
%
noise=sigma*randn(m,n);
%
% noisy input for the algorithm
%
f = double(f0) + noise;
%
% compute SBF and divergence
%
L = 0;
[M, N]=computeTruncation(f, sigmar1, w, tol);
[f1, div1] = computeDivergence(f, f, sigmas,sigmar1,L,w,N,M);
%
% compute RBF and divergence
%
L = 1;
h = ones(2*L+1, 2*L+1) /((2*L+1)^2) ;
barf = imfilter(f,h);
[M, N] = computeTruncation(barf, sigmar2, w, tol);
[f2, div2] = computeDivergence(f, barf,sigmas,sigmar2,L,w,N,M);
%
% compute optimal weights
%
A = [norm(f1,'fro')^2, sum(sum(f1.*f2));
sum(sum(f1.*f2)), norm(f2,'fro')^2];
b = [sum(sum(f1.*f)) - sigma^2*div1;
sum(sum(f2.*f)) - sigma^2*div2];
theta = A\b;
%
% form the WBF
%
bfoptSURE = theta(1)*f1 + theta(2)*f2;
% computing PSNR's
peak=255;
PSNRnoisy = 10 * log10(m*n*peak^2/ ...
sum(sum((f - f0).^2)) ); % noisy PSNR
PSNR_f1 = 10 * log10(m * n * peak^2 ...
/ sum(sum((f1 - f0).^2)) ); % SBF PSNR
PSNR_f2 = 10 * log10(m * n * peak^2 ...
/ sum(sum((f2 - f0).^2)) ); % RBF PSNR
PSNRb_f = 10 * log10(m * n * peak^2 ...
/ sum(sum((bfoptSURE - f0).^2)) ); % WBF PSNR
%
% display
%
h=figure('Units','normalized','Position',[0 0.5 1 0.5]);
set(h,'name','Denoising Results')
colormap gray,
%
subplot(2,3,1)
imshow(uint8(f0));
title('Clean Image')
%
subplot(2,3,2)
imshow(uint8(f));
title(['Noisy Image, PSNR = ', ...
num2str(PSNRnoisy,'%.2f')]);
%
subplot(2,3,3)
imshow(uint8(f1));
title(['SBF, PSNR = ', ...
num2str(PSNR_f1,'%.2f')]);
%
subplot(2,3,4)
imshow(uint8(f2));
title(['RBF, PSNR = ', ...
num2str(PSNR_f2,'%.2f')]);
%
subplot(2,3,5)
imshow(uint8(bfoptSURE));
title(['WBF, PSNR = ', ...
num2str(PSNRb_f,'%.2f')]);
%
subplot(2,3,6)
imshow(uint8(bfoptSURE-f0));
title('Residual Noise in WBF');
% compute filter and divergence using shiftable algorithm
%
function [F, div] = computeDivergence ...
(f,barf,sigmas,sigmar,L,w,N,M)
filt = fspecial('gaussian', [w w], sigmas);
ct = (w+1)/2;
centerWt = filt(ct,ct);
gamma = 1/(sqrt(N)*sigmar);
twoN = 2^N;
[m,n] = size(f);
S = zeros(m,n);
delR = zeros(m,n);
delS = zeros(m,n);
if M == 0
for k = 0 : N
omegak = (2*k - N)*gamma;
ck = nchoosek(N,k)/twoN;
U = exp(-ii*omegak*barf);
W = conj(U);
V = W.*f;
barV = imfilter(V, filt);
barW = imfilter(W, filt);
B = ck*U.*barV;
C = ck*U.*barW;
R = R + B;
S = S + C;
delR = delR + omegak*B;
delS = delS + omegak*C;
end
F = real(R./S);
delR = centerWt - (1/(2*L+1))^2*ii*delR;
delS = -ii*(1/(2*L+1))^2*delS;
else
sumck = 0;
sumckwk = 0;
if N < 50
for k = M : N - M
omegak = (2*k - N)*gamma;
warning('off'); %#ok<WNOFF>
ck = nchoosek(N,k)/twoN;
U = exp(-ii*omegak*barf);
W = conj(U);
V = W.*f;
barV = imfilter(V, filt);
barW = imfilter(W, filt);
B = ck*U.*barV;
C = ck*U.*barW;
sumck = sumck + ck;
sumckwk = sumckwk + ck*omegak;
R = R + B;
S = S + C;
delR = delR + omegak*B;
delS = delS + omegak*C;
end
else
for k = M : N - M
omegak = (2*k - N)*gamma;
warning('off'); %#ok<WNOFF>
% Sterling's approximation
ck = exp(logfactorial(N) - logfactorial(k) ...
- logfactorial(N-k) - N*log(2));
W = conj(U);
V = W.*f;
barV = imfilter(V, filt);
barW = imfilter(W, filt);
B = ck*U.*barV;
C = ck*U.*barW;
sumck = sumck + ck;
sumckwk = sumckwk + ck*omegak;
R = R + B;
S = S + C;
delR = delR + omegak*B;
delS = delS + omegak*C;
end
end
F =real(R./S);
delR = centerWt*sumck + ii*(1/(2*L+1))^2* ...
(centerWt*sumckwk*f - delR);
delS = ii*(1/(2*L+1))^2*(centerWt*sumckwk - delS);
end
div = real(sum(sum((S.*delR - R.*delS)./S.^2)));
end
- 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
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/114436650
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)