Matlab learning 8-linear and nonlinear sharpening filter, nonlinear smoothing filter of image processing

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right


foreword

Spatial filtering enhancement

  • Convolution principle
    • Multi-dimensional continuous convolution
  • linear smoothing filter
    • Domain averaging, selective averaging, Wiener filtering
  • nonlinear smoothing filter
    • median filter
    • Order Statistical Filtering
  • Linear sharpening filter
    • Laplacian operator
  • nonlinear sharpening filter
    • Prewitt operator
    • Sobel operator
    • Log operator

Matlab Learning 8-Linear and nonlinear sharpening filter of image processing,
order statistical filter, Laplacian operator, gradient method


1. Order statistical filtering

Effect
insert image description here

the code

%序统计滤波器
img=imread("img/eight.tif");
subplot(2,3,1),imshow(img),xlabel("原始图像");

img1=imnoise(img,'salt & pepper',0.1);
subplot(2,3,2),imshow(img1),xlabel("椒盐噪声图像");

mask=[  0 1 0
        1 1 1
        0 1 0];
subplot(2,3,3),imshow(mask),xlabel("滤波模板");

K1=ordfilt2(img1,3,mask);
subplot(2,3,4),imshow(uint8(K1)),xlabel("中值滤波图像");

K2=ordfilt2(img1,1,mask);
subplot(2,3,5),imshow(uint8(K2)),xlabel("最小值滤波图像");

K3=ordfilt2(img1,5,mask);
subplot(2,3,6),imshow(uint8(K3)),xlabel("最大值滤波图像");

2. Laplacian operator

Effect
insert image description here

the code

%拉普拉斯算子实例
img=imread("img/eight.tif");
subplot(3,3,1),imshow(img),xlabel("原始图像");
mask1=fspecial('laplacian',0);
L1=filter2(mask1,img);
subplot(3,3,2),imshow(uint8(L1)),text(-14,285,'负中心系数的水平垂直模板滤波图像');
subplot(3,3,3),imshow(uint8(double(img)-L1)),xlabel('负中心系数的水平垂直模板减法叠加图像');

mask2=-mask1;
L2=filter2(mask2,img);
subplot(3,3,4),imshow(uint8(L2)),text(-14,285,'正中心系数的水平垂直模板滤波图像');
subplot(3,3,5),imshow(uint8(double(img)+L2)),xlabel('正中心系数的水平垂直模板加法叠加图像');

mask3=[ 1  1  1
        1 -8  1
        1  1  1];
L3=filter2(mask3,img);
subplot(3,3,6),imshow(uint8(L3)),text(-28,285,'负中心系数的水平垂直对角模板滤波图像');
subplot(3,3,7),imshow(uint8(double(img)-L3)),xlabel('负中心系数的水平垂直对角模板减法叠加图像');

mask4=-mask3;
L4=filter2(mask4,img);
subplot(3,3,8),imshow(uint8(L4)),text(-28,285,'正中心系数的水平垂直对角模板滤波图像');
subplot(3,3,9),imshow(uint8(double(img)+L4)),xlabel('正中心系数的水平垂直对角模板加法叠加图像');

3. Gradient filtering

Effect
insert image description here

the code

%梯度滤波
img=imread("img/img.jpg");
subplot(2,3,1),imshow(img),xlabel("原始图像");

img=double(img);
[Gx,Gy]=gradient(img);
G=sqrt(Gx.*Gx+Gy.*Gy);

img1=G;
subplot(2,3,2),imshow(uint8(img1)),xlabel("梯度法滤波图像");


img2=img;
K=find(G>=7);
img2(K)=G(K);
subplot(2,3,3),imshow(uint8(img2)),xlabel("第一种情况的滤波图像");

img3=img;
K=find(G>=7);
img3(K)=255;
subplot(2,3,4),imshow(uint8(img3)),xlabel("第二种情况的滤波图像");

img4=G;
K=find(G<=7);
img4(K)=255;
subplot(2,3,5),imshow(uint8(img4)),xlabel("第三种情况的滤波图像");

img5=img;
K=find(G<=7);
img5(K)=0;
Q=find(G>=7);
img5(Q)=255;
subplot(2,3,6),imshow(uint8(img5)),xlabel("第四种情况的滤波图像");

Click to get the source code
https://gitee.com/CYFreud/matlab/tree/master/image_processing/demo8_220425

Guess you like

Origin blog.csdn.net/CHengYuP/article/details/125037769