【图像去噪的扩散滤波】图像线性扩散滤波、边缘增强线性和非线性各向异性滤波(Matlab代码实现)

💥💥💞💞欢迎来到本博客❤️❤️💥💥

****🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️**座右铭:**行百里者,半于九十。

📋📋📋++本文目录如下:++🎁🎁🎁

目录

[💥1 概述](#💥1 概述)

[📚2 运行结果](#📚2 运行结果)

[2.1 non_aniso](#2.1 non_aniso)

[2.2 inhomo_iso](#2.2 inhomo_iso)

[2.3 heat_imp](#2.3 heat_imp)

[2.4 heat_explicit](#2.4 heat_explicit)

[🎉3 参考文献](#🎉3 参考文献)

[🌈4 Matlab代码实现](#🌈4 Matlab代码实现)


💥1 概述

【图像去噪的扩散滤波】图像线性扩散滤波、边缘增强线性和非线性各向异性滤波

各种基于扩散的图像滤波方法:

1.使用热方程的线性扩散滤波 - 使用隐式和显式欧拉方法求解。

  1. 边缘增强线性各向异性扩散滤波。

  2. 边缘增强非线性各向异性扩散滤波。

在图像处理领域,去除图像中的噪点和提升细节是非常重要的任务。为此,发展了各种基于扩散的图像滤波方法,旨在改善图像质量和增强图像特征。以下是其中几种常见的滤波方法:

  1. 线性扩散滤波:使用热方程模型来进行线性扩散滤波。这种方法可以使用隐式和显式欧拉方法来求解,以改善图像的平滑度和减少噪声。线性扩散滤波能够通过自适应地调整邻域像素的亮度值,实现图像的去噪和平滑。

  2. 边缘增强线性各向异性扩散滤波:这种方法结合了线性扩散滤波和各向异性过滤的思想,在保持图像平滑的同时突出了图像中的边缘特征。通过对邻域像素的梯度进行加权处理,边缘增强线性各向异性扩散滤波能够有效地提升图像的边缘细节,使图像更加清晰和锐利。

  3. 边缘增强非线性各向异性扩散滤波:与线性滤波相比,非线性滤波方法在处理图像时更加灵活和精确。边缘增强非线性各向异性扩散滤波通过考虑像素之间的非线性关系,使得处理后的图像在细节和边缘保留方面更具优势。这种方法能够在去除噪点的同时保持图像的细节和纹理信息。

这些基于扩散的图像滤波方法为图像去噪和增强提供了强大的工具。根据不同的应用需求和图像特征,选择合适的滤波方法能够显著改善图像质量,并提高图像的可视化效果。无论是在科学研究、医学影像还是图形设计领域,这些滤波方法都发挥着重要作用,为用户带来更好的图像处理体验。

📚 2 运行结果

2.1 non_aniso

2.2 inhomo_iso

2.3 heat_imp

2.4 heat_explicit

部分代码:

% set up finite difference parameters
alpha =.5;
k = 1;
h = 1;

lambda = (alpha^2)*(k/(h^2));

[m n] = size(w);
%stick image into a vector
w_vec = reshape(w,n*n,1);
w_old = w;
w_new = w;

%smooth the image
im_smth = filter_function(w,1);
im_smth = im_smth';
% required for g() calculation
[dx_im_smth dy_im_smth] = gradient(im_smth);
gr_im_smth = dx_im_smth.^2 + dy_im_smth.^2;

[mmm nnn] = size(gr_im_smth);
% g() calculation
for i=1:mmm
    for j=1:nnn
        g(i,j) = 1/(1+(gr_im_smth(i,j)/32));
    end
end
%g = g';
jj=1;

[im_sx im_sy]  = gradient(im_smth);
% diffusion tensor D is preconputed here
D = zeros(n*n,2,2);
for i=1:n*n
    row = ceil(i/n);
    col = i - (row-1) * n;
  %  if((col > 1) && (col < n) && (row > 1) && (row < n))
        
        % choose eigenvector parallel and perpendicular to gradient
        eigen_vec = [im_sx(row,col) im_sy(row,col); im_sy(row,col) -im_sx(row,col) ];
        %choose eigenvalues
        eigen_vec(:,1) = eigen_vec(:,1) ./ norm(eigen_vec(:,1));
        eigen_vec(:,2) = eigen_vec(:,2) ./ norm(eigen_vec(:,2));
        eigen_val = [g(row,col) 0;0 1];
        
        % form diffusion tensor
        D(i,:,:) = eigen_vec * eigen_val * (eigen_vec');        
        % end
end

figure;
for k=1:400 % for each iteration
    for i=1:n*n % solve using Jacobi iterations scheme
        row = ceil(i/n); %compute what row this pixel belongs to in original image
        col = i - (row-1) * n; % compute cols similarly

        %different if conditions handles pixels at different location in
        %the image as depending on their location they may or may not have
        %all their neighbor pixels which will be required for finite
        %differences
        
        if((col > 1) && (col < n) && (row > 1) && (row < n))
            
            s = -lambda * ((D(i,1,1) * w_old(i-1)) + ((D(i,1,1) - D(i,1,2) - D(i,2,1)) * (w_old(i+1))) +  ...
                (D(i,2,2) * w_old(i-n)) + ((D(i,2,2) - D(i,1,2) - D(i,2,1)) * (w_old(i+n))) + ((D(i,1,2) + D(i,2,1)) * w_old(i+n+1)));
            w_new(i) = (-s + w_old(i))/(1 + lambda * (2 * D(i,1,1) + 2 * D(i,2,2) - D(i,1,2) - D(i,2,1)));
            
        elseif((row == 1) && (col > 1) && (col < n))
            s = -lambda * ((D(i,1,1) * w_old(i-1)) + ((D(i,1,1) - D(i,1,2) - D(i,2,1)) * (w_old(i+1))) +  ...
                ((D(i,2,2) - D(i,1,2) - D(i,2,1)) * (w_old(i+n))) + ((D(i,1,2) + D(i,2,1)) * w_old(i+n+1)));
            
            %s = -(lambda) * (w_old(i+1) + w_old(i-1) + w_old(i+n));
            w_new(i) = (-s + w_old(i))/(1+4*lambda);
        elseif((row == n) && (col > 1) && (col < n))
            s = -lambda * ((D(i,1,1) * w_old(i-1)) + ((D(i,1,1) - D(i,1,2) - D(i,2,1)) * (w_old(i+1))) +  ...
                (D(i,2,2) * w_old(i-n)));
            
            %s = -(lambda) * (w_old(i+1) + w_old(i-1) + w_old(i-n));
            w_new(i) = (-s + w_old(i))/(1+4*lambda);
        elseif((col == 1) && (row > 1) && (row < n))
            s = -lambda * (((D(i,1,1) - D(i,1,2) - D(i,2,1)) * (w_old(i+1))) +  ...
                (D(i,2,2) * w_old(i-n)) + ((D(i,2,2) - D(i,1,2) - D(i,2,1)) * (w_old(i+n))) + ((D(i,1,2) + D(i,2,1)) * w_old(i+n+1)));
            
            %s = -(lambda) * (w_old(i+1) + w_old(i+n) + w_old(i-n));
            w_new(i) = (-s + w_old(i))/(1+4*lambda);
        elseif((col == n) && (row > 1) && (row < n))
            s = -lambda * ((D(i,1,1) * w_old(i-1)) +  ...
                (D(i,2,2) * w_old(i-n)) + ((D(i,2,2) - D(i,1,2) - D(i,2,1)) * (w_old(i+n))));            
            %s = -(lambda) * (w_old(i-1) + w_old(i+n) + w_old(i-n));
            w_new(i) = (-s + w_old(i))/(1+4*lambda);
        elseif((col==1) && (row==1))

% set up finite difference parameters

alpha =.5;

k = 1;

h = 1;

lambda = (alpha^2)*(k/(h^2));

[m n] = size(w);

%stick image into a vector

w_vec = reshape(w,n*n,1);

w_old = w;

w_new = w;

%smooth the image

im_smth = filter_function(w,1);

im_smth = im_smth';

% required for g() calculation

[dx_im_smth dy_im_smth] = gradient(im_smth);

gr_im_smth = dx_im_smth.^2 + dy_im_smth.^2;

[mmm nnn] = size(gr_im_smth);

% g() calculation

for i=1:mmm

for j=1:nnn

g(i,j) = 1/(1+(gr_im_smth(i,j)/32));

end

end

%g = g';

jj=1;

[im_sx im_sy] = gradient(im_smth);

% diffusion tensor D is preconputed here

D = zeros(n*n,2,2);

for i=1:n*n

row = ceil(i/n);

col = i - (row-1) * n;

% if((col > 1) && (col < n) && (row > 1) && (row < n))

% choose eigenvector parallel and perpendicular to gradient

eigen_vec = [im_sx(row,col) im_sy(row,col); im_sy(row,col) -im_sx(row,col) ];

%choose eigenvalues

eigen_vec(:,1) = eigen_vec(:,1) ./ norm(eigen_vec(:,1));

eigen_vec(:,2) = eigen_vec(:,2) ./ norm(eigen_vec(:,2));

eigen_val = [g(row,col) 0;0 1];

% form diffusion tensor

D(i,:,:) = eigen_vec * eigen_val * (eigen_vec');

% end

end

figure;

for k=1:400 % for each iteration

for i=1:n*n % solve using Jacobi iterations scheme

row = ceil(i/n); %compute what row this pixel belongs to in original image

col = i - (row-1) * n; % compute cols similarly

%different if conditions handles pixels at different location in

%the image as depending on their location they may or may not have

%all their neighbor pixels which will be required for finite

%differences

if((col > 1) && (col < n) && (row > 1) && (row < n))

s = -lambda * ((D(i,1,1) * w_old(i-1)) + ((D(i,1,1) - D(i,1,2) - D(i,2,1)) * (w_old(i+1))) + ...

(D(i,2,2) * w_old(i-n)) + ((D(i,2,2) - D(i,1,2) - D(i,2,1)) * (w_old(i+n))) + ((D(i,1,2) + D(i,2,1)) * w_old(i+n+1)));

w_new(i) = (-s + w_old(i))/(1 + lambda * (2 * D(i,1,1) + 2 * D(i,2,2) - D(i,1,2) - D(i,2,1)));

elseif((row == 1) && (col > 1) && (col < n))

s = -lambda * ((D(i,1,1) * w_old(i-1)) + ((D(i,1,1) - D(i,1,2) - D(i,2,1)) * (w_old(i+1))) + ...

((D(i,2,2) - D(i,1,2) - D(i,2,1)) * (w_old(i+n))) + ((D(i,1,2) + D(i,2,1)) * w_old(i+n+1)));

%s = -(lambda) * (w_old(i+1) + w_old(i-1) + w_old(i+n));

w_new(i) = (-s + w_old(i))/(1+4*lambda);

elseif((row == n) && (col > 1) && (col < n))

s = -lambda * ((D(i,1,1) * w_old(i-1)) + ((D(i,1,1) - D(i,1,2) - D(i,2,1)) * (w_old(i+1))) + ...

(D(i,2,2) * w_old(i-n)));

%s = -(lambda) * (w_old(i+1) + w_old(i-1) + w_old(i-n));

w_new(i) = (-s + w_old(i))/(1+4*lambda);

elseif((col == 1) && (row > 1) && (row < n))

s = -lambda * (((D(i,1,1) - D(i,1,2) - D(i,2,1)) * (w_old(i+1))) + ...

(D(i,2,2) * w_old(i-n)) + ((D(i,2,2) - D(i,1,2) - D(i,2,1)) * (w_old(i+n))) + ((D(i,1,2) + D(i,2,1)) * w_old(i+n+1)));

%s = -(lambda) * (w_old(i+1) + w_old(i+n) + w_old(i-n));

w_new(i) = (-s + w_old(i))/(1+4*lambda);

elseif((col == n) && (row > 1) && (row < n))

s = -lambda * ((D(i,1,1) * w_old(i-1)) + ...

(D(i,2,2) * w_old(i-n)) + ((D(i,2,2) - D(i,1,2) - D(i,2,1)) * (w_old(i+n))));

%s = -(lambda) * (w_old(i-1) + w_old(i+n) + w_old(i-n));

w_new(i) = (-s + w_old(i))/(1+4*lambda);

elseif((col==1) && (row==1))

🎉3 参考文献

文章中一些内容引自网络,会注明出处或引用为参考文献,难免有未尽之处,如有不妥,请随时联系删除。

[1]张建伟,王译禾,陈允杰.基于非线性扩散滤波结构信息的图像去噪方法[J].计算机工程与设计, 2016, 37(11):8.DOI:10.16208/j.issn1000-7024.2016.11.021.

[2]文武,苗放.复数域非线性扩散滤波在图像处理中的应用[J].微电子学与计算机, 2012.DOI:CNKI:SUN:WXYJ.0.2012-06-015.

[3]傅艳莉,李超,陈浩,等.各向异性扩散滤波远探测声波测井图像降噪方法[J].应用声学, 2022, 41(4):10.

[4]许韬.非线性扩散图像混合滤波去噪方法研究[J].计算机仿真, 2020, 037(012):460-464.

[5]李志伟,冯象初.维纳滤波和非线性扩散相结合的图像去噪[J].电子科技, 2007(9):4.DOI:10.3969/j.issn.1007-7820.2007.09.016.

🌈4 Matlab代码实现

相关推荐
凤枭香2 分钟前
Python OpenCV 傅里叶变换
开发语言·图像处理·python·opencv
远望清一色22 分钟前
基于MATLAB的实现垃圾分类Matlab源码
开发语言·matlab
蒙娜丽宁2 小时前
《Python OpenCV从菜鸟到高手》——零基础进阶,开启图像处理与计算机视觉的大门!
python·opencv·计算机视觉
好喜欢吃红柚子3 小时前
万字长文解读空间、通道注意力机制机制和超详细代码逐行分析(SE,CBAM,SGE,CA,ECA,TA)
人工智能·pytorch·python·计算机视觉·cnn
AI小杨3 小时前
【车道线检测】一、传统车道线检测:基于霍夫变换的车道线检测史诗级详细教程
人工智能·opencv·计算机视觉·霍夫变换·车道线检测
顶呱呱程序5 小时前
2-143 基于matlab-GUI的脉冲响应不变法实现音频滤波功能
算法·matlab·音视频·matlab-gui·音频滤波·脉冲响应不变法
撞南墙者6 小时前
OpenCV自学系列(1)——简介和GUI特征操作
人工智能·opencv·计算机视觉
王哈哈^_^6 小时前
【数据集】【YOLO】【VOC】目标检测数据集,查找数据集,yolo目标检测算法详细实战训练步骤!
人工智能·深度学习·算法·yolo·目标检测·计算机视觉·pyqt
柳鲲鹏7 小时前
OpenCV视频防抖源码及编译脚本
人工智能·opencv·计算机视觉
简简单单做算法8 小时前
基于Retinex算法的图像去雾matlab仿真
算法·matlab·图像去雾·retinex