MATLAB基本操作与图像处理

C11

E=eye(3,3);

R=rand(3,2);

S=[2 0;0 4];

O=zeros(2,3);

A=[E,R+R*S;O S^2]

C=A*A;

B=C



结果:

>> C11


E =


   1  0  0

   0  1  0

   0  0  1



R =


  0.9572  0.1419

  0.4854  0.4218

  0.8003  0.9157



S =


   2  0

   0  4



O =


   0  0  0

   0  0  0



A =


 Columns 1 through 4


  1.0000    0    0  2.8715

     0  1.0000    0  1.4561

     0    0  1.0000  2.4008

     0    0    0  4.0000

     0    0    0    0


 Column 5


  0.7094

  2.1088

  4.5787

     0

  16.0000



C =


 Columns 1 through 4


  1.0000    0    0 14.3575

     0  1.0000    0  7.2806

     0    0  1.0000 12.0042

     0    0    0 16.0000

     0    0    0    0


 Column 5


  12.0603

  35.8497

  77.8375

     0

 256.0000



B =


 Columns 1 through 4


  1.0000    0    0 14.3575

     0  1.0000    0  7.2806

     0    0  1.0000 12.0042

     0    0    0 16.0000

     0    0    0    0


 Column 5


  12.0603

  35.8497

  77.8375

     0

 256.0000


================================================================

C12

t=-1:0.01:1;

x=sin(2*pi*t);

y=cos(2*pi*10*t);

plot(t,x,t,y)

xlabel('t');ylabe('函数值')

legend('正弦函数','余弦函数');




结果:



C13

[x,y]=meshgrid(-10:0.05:10);

z=sin(pi*sqrt(x.^2+y.^2));

mesh(x,y,z)






结果




================================================================

C14

x=-5:0.1:5;

y1=tpdf(x,5);

y2=tpdf(x,10);

y3=tpdf(x,20);

z=normpdf(x,0,1);

plot(x,y1,x,y2,x,y3,x,z)

legend('y1','y2','y3','z')


结果




================================================================

C15

x=0:0.2:30;

y1=chi2pdf(x,5);

y2=chi2pdf(x,10);

y3=chi2pdf(x,20);

plot(x,y1,x,y2,x,y3)



结果



================================================================

C16

L=[1.015;0.985;1.020;2.016;1.981;3.032]

A=[1,0,0;0,1,0;0,0,1;1,1,0;0,1,1;1,1,1]

C=inv(A'*A)

X=C*A'*L

x1=X(1,1),x2=X(2,1),x3=X(3,1)

V=L-A*X

v1=V(1,1),v2=V(2,1),v3=V(3,1),v4=V(4,1),v5=V(5,1),v6=V(6,1)

b=sqrt((v1^2+v2^2+v3^2+v4^2+v5^2+v6^2)/3)

d11=C(1,1),d22=C(2,2),d33=C(3,3)

bx1=b*sqrt(d11)

bx2=b*sqrt(d22)

bx3=b*sqrt(d33)




结果

>> C16


L =


  1.0150

  0.9850

  1.0200

  2.0160

  1.9810

  3.0320



A =


   1  0  0

   0  1  0

   0  0  1

   1  1  0

   0  1  1

   1  1  1



C =


  0.5000 -0.2500    0

  -0.2500  0.5000 -0.2500

     0 -0.2500  0.5000



X =


  1.0280

  0.9830

  1.0130



x1 =


  1.0280



x2 =


  0.9830



x3 =


  1.0130



V =


  -0.0130

  0.0020

  0.0070

  0.0050

  -0.0150

  0.0080



v1 =


  -0.0130



v2 =


  0.0020



v3 =


  0.0070



v4 =


  0.0050



v5 =


  -0.0150



v6 =


  0.0080



b =


  0.0134



d11 =


  0.5000



d22 =


  0.5000



d33 =


  0.5000



bx1 =


  0.0095



bx2 =


  0.0095



bx3 =


  0.0095


>> 


================================================================


C17

x=[26.8 25.4 28.9 23.6 27.7 23.9 24.7 28.1 26.9 27.4 22.6 25.6];

y=[26.5 27.3 24.2 27.1 23.6 25.9 26.3 22.5 21.7 21.4 25.8 24.9];

A=[ones(1,12);x]';

B=[ones(1,12);y]';

a=inv(A'*A)*A'*y';

b=inv(B'*B)*B'*x';

x1=20:.1:30;

y2=20:.1:30;

y1=a(1)+a(2)*x1;

x2=b(1)+b(2)*y2;

plot(x,y,'o',x1,y1,y2,x2)

yg=a(1)+a(2)*x;

U=sum((yg-mean(y)).^2);

Q=sum((y-yg).^2);

F=U./(Q./10);

S2=Q/10;

S=Q+U;

U,Q,F,S2,S


结果:



>> C17


U =


  20.2621



Q =


  26.8845



F =


  7.5367



S2 =


  2.6885



S =


  47.1467


>> 




实验2



clc;

clear all

close all;

T=imread('f1.jpg');

%读入电极图像

M=imresize(T,[256 256]);

%将图像调整256×256,为了显示方便

YT=rgb2gray(M);

%将RGB 格式转换为灰度图像

%Figure(),

%figure

subplot(2,5,1)

imshow(YT);title('Original Pic');

%%

%显示原始图像

%去噪%

%1 中值滤波去噪%

Z1=medfilt2(YT,[5,5]);

%2 小波分析去噪%

%使用sym4 小波,设定全局阈值去噪%

[THR,SORH,KEEPAPP]=ddencmp('den','wv',Z1);

X=wdencmp('gbl',Z1, 'sym4',2,THR, SORH, KEEPAPP);

subplot(2,5,2)

%Figure,

imshow(X,[])

title('去噪图像') %显示去噪图像

%%

[Z1,s]=wavedec2(X,2, 'sym4');

%进行二层小波分解

len=length(Z1);

%处理分解系统,突出轮廓,弱化细节%

for i=1:len

if(Z1(i)>334)

Z1(i)=2* Z1(i);

else

Z1(i)=0.5* Z1(i);

end

end

Z=waverec2(Z1,s,'sym4'); %分解系数重构

%figure,

subplot(2,5,3)

imshow(Z,[])

title('增强图像') %显示增强图像

%%

BW1=edge(Z, 'canny', 0.15) %canny 边缘检测

%figure,

subplot(2,5,4)

imshow(BW1)

title('canny 检测效果') %显示边缘检测图像

%%

%填补缝隙%

se90=strel('line',3,90);

se0=strel('line',3, 0);

%膨胀操作%

BWsdil=imdilate(BW1, [se90,se0]);

%figure,

subplot(2,5,5)

imshow(BWsdil);

title('膨胀图像') %显示膨胀图像

%填充%

BWdfill=imfill(BWsdil, 'holes')

%figure,

subplot(2,5,6)

imshow(BWdfill)

title('填充图像') %显示填充图像

%移除与边界连通的目标%

BWnobord=imclearborder(BWdfill,4)

%figure, 

subplot(2,5,7)

imshow(BWnobord)

title('移除与边界连通的图像') %显示移除与边界连通的图像

%平滑%

seD=strel('diamond',1)

BWfinal1=imerode(BWnobord,seD)

BWfinal2=imerode(BWfinal1,seD)

%figure, 

subplot(2,5,8)

imshow(BWfinal2)

title('平滑图像') %显示平滑图像

%%

%计算裂纹面积%

count=0 %记录裂纹图像像素点的个数

[i,j]=size(BWfinal2);

for m=1:i

for n=1:j

if BWfinal2(m,n)>0 %判断是否为裂纹图像像素点

count=count+1;

end

end

end

S=count %统计裂纹图像像素点的个数

%%

BWfinal3=uint8(BWfinal2);

BW2=edge(BWfinal3, 'canny') %边缘提取

%figure, 

subplot(2,5,9)

imshow(BW2)

title('canny 检测效果') %显示边缘检测图像

[x,y]=size(BW2)

BW=bwperim(BW2, 8) %检测目标的边缘跟踪,用于计算周长

%检测垂直方向连续的周长像素点%

P1=0;

P2=0;

Ny=0; %记录垂直方向连续周长像素点的个数

for i=1:x

for j=1:y

if(BW(i,j)>0)

P2=j;

if((P2-P1)==1) %判断是否为垂直方向连续的周长像素点

Ny=Ny+1;

end

P1=P2;

end

end

end

%检测水平方向连续的周长像素点%

P1=0

P2=0

Nx=0

for j=1:y

for i=1:x

if(BW(i,j)>0)

P2=i

if((P2-P1)==1) %判断是否为水平方向连续的周长像



猜你喜欢

转载自blog.csdn.net/weixin_39257042/article/details/80429407