matlab图像处理范例代码Word文档格式.docx
- 文档编号:16635377
- 上传时间:2022-11-25
- 格式:DOCX
- 页数:47
- 大小:28.11KB
matlab图像处理范例代码Word文档格式.docx
《matlab图像处理范例代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《matlab图像处理范例代码Word文档格式.docx(47页珍藏版)》请在冰豆网上搜索。
Equalorgreaterthan
./
Element-by-elementdivision
.*
Element-by-elementmultiplication
Enterthefollowingsequenceofcommands(pressEnteraftereachcommand):
1
5*5+2*2
2
9*(1/(12-3)-(1/3^2))
3
s=2;
h=3;
g=s+h
4
pr=s*h
5
u=[1,2,3]
6
u=[123]
7
v=[-1,0,-3]
8
w=u-2*v
9
range=
1:
12
10
odd=1:
2:
11
down=20:
-0.5:
even=odd+1
13
u'
14
v'
15
w'
16
pi
17
xgrid=0:
.05:
18
x=xgrid*pi
19
y=sin(x)
20
a=2.;
b=a^2
21
sqrt(9)
22
Z=zeros(2.5)
The
Colon
Operator
Itoccursindifferentforms.Trythefollowingexercises:
1:
(itisarowvectorcontainingtheintegersfrom1to10)
100:
-7:
50
0:
pi/4:
pi
sum(A(1:
4,4))
sum(A(:
end))
(itcomputesthesumoftheelementsinthelastcolumnofA)
sum(
16
)/4
II.BasicPlotting
CreatingaPlot
plot
functionhasdifferentformsanddependsontheinputarguments:
plot(y)
whereyisavector
plot(x,y)
wherexandyarevectors.
PlottinginPolarCoordinates
polar
isthefunctionthatisusedforpolarcoordinateplot:
e.g.
polar([02*pi],[01])
ControllingtheAxis
*Matlabselectsaxislimitsontherangeoftheplotteddata.Tospecifythelimitsmanuallyyouneedtousetheaxiscommand:
axis([xmin,xmax,ymin,ymax])
.
*Thecommand
axis('
equal'
)
makesthe
x-
and
y-axesequalinlength.Tomakethex-andy-dataunitsequalusethecommand:
square'
*Toaddatitletotheplotuse:
title('
TitleofthePlot'
)
*Toadd
x-,
y-labelsuse:
xlabel('
x-Axis'
ylabel('
y-Axis'
GridLines
grid
commandsetsgridlines.
III.Examples
Makem-filesthatplotthefollowingfunctions:
III.1
Explainhowthefollowingfunctionworks.Find/defineaproblem.
functiondrawline1
x=[12];
y=[14];
y=2.*x+3.;
plot(x,y);
);
title('
PlotoftheFunction'
'
FontSize'
12);
III.2
functiondrawline2
x=[1,2];
y=2.*x+3;
plot(x,y,'
g'
12);
axis([-105-520]);
III.3
functiondrawline3
x=[015];
y=x+1.;
plot(y,'
r'
grid
III.4
functiondrawsin1
x=0:
2\pi'
Sineofx'
PlotoftheSineFunction'
12)
x=0:
pi/100:
2*pi;
y=sin(x);
plot(x,y)
III.5
functiondrawsin2
plot(sin(0:
.01:
10));
III.6
functiondrawsin3
10;
plot(sin(x));
III.7
%generateaspiralinpolarcoordinates
theta=0:
0.2:
5*pi;
rho=theta.^2;
polar(theta,rho,'
go'
III.8
functionDrawsquare1;
%Todrawasquareusingnodes
%Firstofalldefinethenodes
Node=[-2-2;
-22;
22;
2-2;
-2-2];
%Drawthesquare
plot(Node(:
1),Node(:
2))
axis([-5,5,-5,5]);
axissquare;
III.9
functionDrawsquare2;
fill(Node(:
2),'
red'
2-IntoductiontoMatlab:
DrawingtheCurvesand2DObjects
I-1SpecifyingLineStylesandColours.PlottingLinesandMarkers.
Ifwespecifyamarkerstylebutnotalinestyle,Matlabdrawsonlythemarker.
To
specifycolour
usecommand
plot(x,y,'
colour_style_marker'
wherecolourstringsare
'
c'
cyan
red
white
green
y'
yellow
b'
blue
k'
black
m'
magenta
Linestyle
stringsare
-'
solid
--'
dashed
:
'
dotted
-.'
dash-dot
Forexample:
plot(x,y,'
r:
plotsareddottedline.
markertypes
are
+'
s'
square
x'
x
p'
pentagram
0'
v'
downtriangle
*'
d'
diamond
s'
plotsareddottedlineandplacessquaremarkersateachdatapoint.
I-2Knowingwhereyouare:
Usethe
pwd
commandtoknowwhereyouare
dir
commandtolistthefilesinyourcurrentdirectory
cd
commandtochangedirectory
I-3Reminder:
Read"
IntroductiontoMatlab"
anddoComputerGraphicsExercises-pages11-13.
II-1.Examples
Makem-filesthatplotthefollowinggraphs:
II.1
functiondrawParabola;
%Todrawparabolay=(x+3)^2+25inafigurewindow.
%Definethestartandendpointsonthex-axis
x=
-
18:
15
;
y=(x+3).^2+25;
Explaintheprogramandresults.
II.2
functiondrawEllipse;
%todrawtheellipse(x^2)/16+(y^2)/4=1
%youneedtogetparametricrepresentationoftheellipse,i.e.x=acos(t);
y=bsin(t)
t=0:
0.01:
a=16.;
b=4.;
x=a*cos(t);
y=b*sin(t);
),grid
Explaintheprogramandresults.Isthereanyproblemintheprogram?
II.3
functiondrawHyperbola;
%Drawhyperbolay=3/xinafigurewindow.
x=0.01:
1;
y=3./x;
plot(x,y,'
II-2Examples
II.4
Make
NewObject.m
file
functionNewObject;
%Todrawanobjectusingfill
X1=[-2-20];
Y1=[-110];
X2=[-110];
Y2=[220];
X3=[220];
Y3=[1-10];
X4=[1-10];
Y4=[-2-20];
%Drawtheobject
fill(X1,Y1,'
green'
X2,Y2,'
X3,Y3,'
X4,Y4,'
II.5
functiondrawFig(N);
%HelloI'
mafunctiondrawFig
R=10;
t=0:
2*pi/N:
x=R*sin(t);
y=R*cos(t);
holdon
linewidth'
2)
for
J=1:
N
K=1:
J
XP=[x(K)x(J)];
YP=[y(K)y(J)];
plot(XP,YP,'
end
end
axissquare
1)Savethisprogramwith
drawFig.m
2)InMatlabCommandWindowtype
helpdrawFig
3)Nowtype,e.g.
drawFig(4)
II.6
functionCircleSimple(R);
%DrawsacirclecentredontheoriginofradiusR
K=0;
pi/36:
K=K+1;
X(K)=R*cos(t);
Y(K)=R*sin(t);
fill(X,Y,'
Explaintheprogramandresults.
3-2DTransforms&
DataStructures
I.MatlabSection
UsetheMatlab
help
systemtoreadaboutthefollowingcommands:
tic,toc,drawnow,clock
etime.
II.1
Programmingtherotation
Firststep
Makethefollowingfiles(seeprogramsbelow):
testT1.m
Rotatesquare.m
Secondstep
Run
testT1.m
Thirdstep
Explaintheprogramandresults
function
testT1
theta=0:
360
Rotatesquare(theta);
drawnow;
t=clock;
while
etime(clock,t)<
0.15
Rotatesquare.m
%Firstofalldefinethenodesinthehomogeneousformat
%seeTopic2&
"
MathematicalPages"
Node=[-2-222-2;
-222-2-2;
11111]
%Nowconverttherotationangletoradians
%Remember180degs.=piradians
thetarad=pi*theta/180;
%Nowletusdefinetherotationmatrix
Ctheta=cos(thetarad);
Stheta=sin(thetarad);
Rot=[Ctheta-Stheta0;
SthetaCtheta0;
001]
%Nowrotatethesquare
NewNode=Rot*Node;
plot(NewNode(1,:
),NewNode(2,:
));
%Setthelimitstotheaxesandensuretheyareofequaldimension
Firststep:
Makethefollowingfiles(seeprogramsbelow):
fig1.
txt
Tut3.m
rotate.m,scale.m,Readobject.m
Tut3.m
fig1.txt
0,6
6,0
0,-6
-6,0
Tut3
N=readobject('
NP=N;
holdoff
patch(NP(:
1),NP(:
edgecolor'
axis([-10,10,-10,10]);
tic
timeinterval=0;
timeinterval<
timeinterval=toc
NR=rotate(N,45);
NR=scale(NR'
0.8,0.8);
NP=NR'
blue'
%
NR=rotate(N,150);
0.5,0.5);
rotate.m
NR=rotate(N,theta)
%TorotatethenodearrayNbytheangletheta
R=zeros(3,3);
R(1,1)=Ctheta;
R(2,2)=Ctheta;
R(1,2)=-Stheta;
R(2,1)=Stheta;
R(3,3)=1;
NR=R*N'
scale.m
NS=scale(N,SX,SY)
%ToscalethenodearrayNbySXandSY
S=zeros(3,3);
S(1,1)=SX;
S(2,2)=SY;
S(3,3)=1;
NS=S*N'
Readobject.m
N=Readobject(FN)
%Toloaddatafromatextfile'
FN'
intoanodearrayN
temp=dlmread(FN);
[a,b]=size(temp);
N=ones(a,3);
N(:
1)=temp(:
1);
2)=temp(:
2);
II-3
Spiral
%Todrawa3Dspiral
%ForefficiencywecalculateX,YandZforasingleturn
R=5;
C=2;
thetastep=10*pi/180;
theta=[0:
thetastep:
2*pi];
X=R*cos(theta);
Y=R*sin(theta);
Z=C*theta;
%N
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab 图像 处理 范例 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)