📄 morp.m
字号:
function main(void)
I=imread('99','bmp');
J=im2double(I);
f=J(:,:,1);
imshow(f,[]);
b=zeros(3,3);
%b=[-2,-2,-2;-2,-2,-2;-2,-2,-2];
%x = 0.1*randn(1,500); % Input to the filter
x = f([100:132],[100:132]);
figure,imshow(x,[]);
b = fir1(31,0.5); % FIR system to be identified
d = filter(b,1,x); % Desired signal
w0 = zeros(1,32); % Intial filter coefficients
k0 = 0.5*eye(32); % Initial state error correlation matrix
qm = 2; % Measurement noise covariance
qp = 0.1*eye(32); % Process noise covariance
s = initkalman(w0,k0,qm,qp);
[y,e,s] = adaptkalman(x,d,s);
figure,imshow(y,[]);
stem([b.',s.coeffs.']);
legend('Actual','Estimated');
title('System Identification of an FIR filter via Kalman Filter');
grid on;
[rs,cs]=size(f);
%g=zeros(rs,cs);
g=erode(f,b);
%figure,imshow(g,[]);
g=dilate(g,b);
figure,imshow(g,[]);
g=erode(f,b);
g=f-g;
figure,imshow(g,[]);
figure,mesh(g);
%******************************************************************
function g=erode(f,b)
m=size(b,1);
m=fix(m/2);
[rs,cs]=size(f);
g=zeros(rs,cs);
for i=1:rs;
for j=1:cs;
tmin=1;
for s=-m:m;
for t=-m:m;
if(i+s>0&&i+s<rs+1&&j+t>0&&j+t<cs+1)
temp=max(0,f(i+s,j+t)-b(s+m+1,t+m+1));
tmin=min(tmin,temp);
end
end
end
g(i,j)=tmin;
end
end
%******************************************************************
function g=dilate(f,b)
m=size(b,1);
m=fix(m/2);
[rs,cs]=size(f);
g=zeros(rs,cs);
for i=1:rs;
for j=1:cs;
tmax=0;
for s=m:-1:-m;
for t=m:-1:-m;
if(i-s>0&&i-s<rs+1&&j-t>0&&j-t<cs+1)
temp=min(1,f(i-s,j-t)+b(s+m+1,t+m+1));
tmax=max(tmax,temp);
end
end
end
g(i,j)=tmax;
end
end
%******************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -