✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
Image noises are usually generated in the processes of collection, transmission, and storage of images, while some noises, named internal noises, come from the image itself. The noises decrease image visual effect and quality. Thus, it is very important to remove the noises from the images. In this paper, we propose a one-dimensional surface blur algorithm based on wavelet transform and bilateral filtering for image internal noise elimination and detail preservation. In our algorithm, we first transform the two-dimensional image into one-dimensional signal vectors by merging the pixels in each row and column of the image. Then, we decompose each of the vectors into two parts: the low-frequency and high-frequency components with a discrete wavelet transform. We further perform the bilateral filtering and a local variance-based thresholding method on the two components to smooth and denoise signals, respectively. Finally, we evaluate our algorithm's performance in a group of face images. The experimental results show that our algorithm achieved better performance on image denoising and detail preservation than a set of traditional smoothing methods and the state-of-the-art. Our algorithm is a simple, effective, and easy-to-implement method, and it is suitable for image smoothing to improve the image's visual effect and quality.
⛄ 完整代码
close all
A=imread('images.jpg');%A:读取图像
r=2; %r:半径
T=10; %T:阈值
w=zeros(2*r+1,2*r+1); %模板矩阵的尺寸
%图像初始化处理
figure,subplot(121);imshow(A);title("原图");
% img=rgb2gray(A); %源图片转灰度图
%
% img=double(img); %转为矩阵
R=double(A(:,:,1));
G=double(A(:,:,2));
B=double(A(:,:,3));
%解决边界值问题
[m,n]=size(R);
imgn=zeros(m+2*r,n+2*r); %创建一个长宽各增加[2r]的扩容矩阵
imgn(r+1:r+m,r+1:r+n)=R;
imgn(1:r,r+1:r+n)=R(1:r,1:n); %上边界填充
imgn(1:m+r,n+r+1:n+2*r)=imgn(1:m+r,n+1:n+r); %右边界填充
imgn(m+r+1:m+2*r,r+1:n+2*r)=imgn(m+1:m+r,r+1:n+2*r); %下边界填充
imgn(1:m+2*r,1:r)=imgn(1:m+2*r,r+1:2*r); %左边界填充
[m1,n1]=size(G);
imgn1=zeros(m1+2*r,n1+2*r); %创建一个长宽各增加[2r]的扩容矩阵
imgn1(r+1:r+m1,r+1:r+n1)=G;
imgn1(1:r,r+1:r+n1)=G(1:r,1:n1); %上边界填充
imgn1(1:m1+r,n1+r+1:n1+2*r)=imgn1(1:m1+r,n1+1:n1+r); %右边界填充
imgn1(m1+r+1:m1+2*r,r+1:n1+2*r)=imgn1(m1+1:m1+r,r+1:n1+2*r); %下边界填充
imgn1(1:m1+2*r,1:r)=imgn1(1:m1+2*r,r+1:2*r); %左边界填充
[m2,n2]=size(B);
imgn2=zeros(m2+2*r,n2+2*r); %创建一个长宽各增加[2r]的扩容矩阵
imgn2(r+1:r+m2,r+1:r+n2)=B;
imgn2(1:r,r+1:r+n2)=B(1:r,1:n2); %上边界填充
imgn2(1:m2+r,n2+r+1:n2+2*r)=imgn2(1:m2+r,n2+1:n+r); %右边界填充
imgn2(m2+r+1:m2+2*r,r+1:n2+2*r)=imgn2(m2+1:m2+r,r+1:n2+2*r); %下边界填充
imgn2(1:m2+2*r,1:r)=imgn2(1:m2+2*r,r+1:2*r); %左边界填充
%开始计算每个像素,共计算m*n次
for i=r+1:r+m
for j=r+1:r+n %遍历imgn 中部的源img部分
%计算式子的分母
w=1-abs(imgn(i-r:i+r,j-r:j+r)-imgn(i,j))/(2.5*T); %w是一个以img中的元素为核心,size=[2r+1][2r+1]的矩阵,这样的模板会计算m*n次
%灰度值溢出检查
for p=1:2*r+1
for q=1:2*r+1
if w(p,q) <=0
w(p,q)=0;
end
end
end
%计算式子的分子
s=w.*imgn(i-r:i+r,j-r:j+r);
%计算总式
imgn(i,j)=sum(sum(s))/sum(sum(w)); %一个sum()对一维数组求和,sum(sum())就是对二维矩阵求和
end
end
for i=r+1:r+m1
for j=r+1:r+n1 %遍历imgn 中部的源img部分
%计算式子的分母
w1=1-abs(imgn1(i-r:i+r,j-r:j+r)-imgn1(i,j))/(2.5*T); %w是一个以img中的元素为核心,size=[2r+1][2r+1]的矩阵,这样的模板会计算m*n次
%灰度值溢出检查
for p=1:2*r+1
for q=1:2*r+1
if w1(p,q) <=0
w1(p,q)=0;
end
end
end
%计算式子的分子
s1=w1.*imgn1(i-r:i+r,j-r:j+r);
%计算总式
imgn1(i,j)=sum(sum(s1))/sum(sum(w1)); %一个sum()对一维数组求和,sum(sum())就是对二维矩阵求和
end
end
for i=r+1:r+m2
for j=r+1:r+n2 %遍历imgn 中部的源img部分
%计算式子的分母
w2=1-abs(imgn2(i-r:i+r,j-r:j+r)-imgn2(i,j))/(2.5*T); %w是一个以img中的元素为核心,size=[2r+1][2r+1]的矩阵,这样的模板会计算m*n次
%灰度值溢出检查
for p=1:2*r+1
for q=1:2*r+1
if w2(p,q) <=0
w2(p,q)=0;
end
end
end
%计算式子的分子
s2=w2.*imgn2(i-r:i+r,j-r:j+r);
%计算总式
imgn2(i,j)=sum(sum(s2))/sum(sum(w2)); %一个sum()对一维数组求和,sum(sum())就是对二维矩阵求和
end
end
img=imgn(r+1:r+m,r+1:r+n); %从imgn截取出源img部分
img1=imgn1(r+1:r+m1,r+1:r+n1); %从imgn截取出源img部分
img2=imgn2(r+1:r+m2,r+1:r+n2); %从imgn截取出源img部分
res=cat(3,img,img1,img2);
subplot(122);imshow(uint8(res));title("SurfaceBlur算法后");
⛄ 运行结果
⛄ 参考文献
[1] Liu C , Pang M . One-dimensional image surface blur algorithm based on wavelet transform and bilateral filtering[J]. Multimedia Tools and Applications, 2021:1-15