📄 convolution.m
字号:
clear all;
close all'
clc
L=imread('Lenna.jpg');
L=rgb2gray(L);
L=im2double(L);
subplot(2,2,1), imshow(L);title('Original picture'); subplot(2,2,3), imhist(L);title('Original Histogram');
Lnoise=imnoise(L,'gaussian');
subplot(2,2,2), imshow(Lnoise);title('Noisy picture'); subplot(2,2,4), imhist(Lnoise);title('Noisy Histogram');
% conv2 = Two-dimensional convolution
k1=ones(3)/9; % kernel of 3 by 3 (LPF)
LnConv=conv2(Lnoise,k1,'same');
figure(2), subplot(2,2,1), imshow(LnConv);title('Noisy picture after conv with LPF'); subplot(2,2,3), imhist(LnConv);title('Noisy Histogram after conv with LPF');
k2=ones(5)/25;% kernel of 5 by 5 (LPF)
LnConv2=conv2(Lnoise,k2,'same');
figure(3), subplot(2,2,1), imshow(LnConv2);title('Noisy picture after conv with LPF of 5 by 5'); subplot(2,2,3), imhist(LnConv2);title('Noisy Histogram after conv with LPF of 5 by 5');
k3=ones(7)/49;% kernel of 7 by 7 (LPF)
LnConv3=conv2(Lnoise,k3,'same');
subplot(2,2,2), imshow(LnConv3);title('Noisy picture after conv with LPF of 7 by 7'); subplot(2,2,4), imhist(LnConv3);title('Noisy Histogram after conv with LPF of 7 by 7');
% filter2 = Two-dimensional digital filtering
nonL1 = medfilt2(LnConv,[3 3]);
nonL2 = medfilt2(LnConv2,[3 3]);
nonL3 = medfilt2(LnConv3,[3 3]);
figure(4), subplot(2,2,1), imshow(nonL1); title('After convolution with non linear Median filter 3 by 3'); subplot(2,2,3), imhist(nonL1); title('After convolution with non linear Median filter 3 by 3');
subplot(2,2,2), imshow(nonL2); title('After convolution with non linear Median filter 5 by 5'); subplot(2,2,4), imhist(nonL2); title('After convolution with non linear Median filter 5 by 5');
figure(5), subplot(2,2,1), imshow(nonL3); title('After convolution with non linear Median filter 7 by 7'); subplot(2,2,3), imhist(nonL3); title('After convolution with non linear Median filter 7 by 7');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -