Title: Introduction to Matlab
1Introduction to Matlab
22D Graphics
- x0pi/1002pi
- ysin(x)
- plot (x,y)
- hold on
- zcos(x)
- plot (x,z)
3- x0pi/1002pi
- ysin(x)
- zcos(x)
- subplot (2,1,1)
- plot (x,y)
- grid on
- title (Sine function)
- subplot (2,1,2)
- plot (x,z)
- grid off
- title (Cosine function)
4- x-2pipi/1002pi
- ysin(x)
- z2cos(x)
- subplot (2,1,1)
- plot (x,y,x,z)
- title (plot in same y-axis scale)
- subplot (2,1,2)
- plotyy(x,y,x,z)
- title (plot in different y-axis scales)
5- subplot(3,1,1)
- fplot('abs(exp(-jx(09))
- ones(10,1))',0 2pi)
- subplot(3,1,2)
- fplot('tan(x),sin(x),cos(x)',
- 2pi-1 1 -1 1)
- subplot(3,1,3)
- fplot('sin(1 ./ x)', 0.01 0.1 ,
- 1e-3)
Plot a function between specified limits
6- M0.5 , 1 , 1.6 , 1.2 , 0.8 , 2.1
- N2 3 4 5
- subplot (1,3,1)
- pie (M)
- title (case 1)
- subplot (1,3,2)
- pie (M , Mmax(M))
- title (case 2)
- subplot (1,3,3)
- pie (N,'North','South',
- 'East','West')
- title (case 3)
7- x1 5 8
- y4 9 2
- z3 6 7
- a2 3 9 7
- b5 8 6 1
- c2 4.7 3 9
- subplot (2,2,1)
- fill (x,y,r)
- subplot (2,2,2)
- fill (a,b,b)
- subplot (2,2,3)
- fill3 (x,y,z,r)
- subplot (2,2,4)
- fill3 (a,b,c,b)
8- x-30.23
- yexp (-x .x)
- subplot(1,2,1)
- bar(x,y)
- subplot(1,2,2)
- bar3(x,y)
9- x-30.23
- yexp(-x . x)
- subplot (1,2,1)
- barh (x,y)
- subplot (1,2,2)
- stairs (x,y)
10- x-pipi/100pi
- ysin(x)
- plot (x,y)
- title (Graph of the Sine function)
- ylabel ( ysin(x))
- xlabel ( -\pi \leq \itx \leq \pi)
- text (1,-1/3, text1)
text1
11- axis (Xmin Xmax Ymin Ymax Zmin Zmax)
- ???? ?????????? ??? ??????? ??????? ?? ???
???????? - axis (-2 2 -0.6 0.6)
12- axis auto
- ???? ?????????? ??????? ?? ??? MATLAB ???? ????
?????? ????? ???????.
13- axis tight
- ???? ?????????? ???? ????????? ????????
14- axis equal
- ???? ?????????? ?? ???? ????????? ?????? ????
?????
15- axis square
- ???? ?????????? ??? ??? ????
16?????? ????????? ?? ?????? ???? ????? ?????? ????????? ?? ?????? ???? ????? ?????? ????????? ?? ?????? ???? ????? ?????? ????????? ?? ?????? ???? ????? ?????? ????????? ?? ?????? ???? ????? ?????? ????????? ?? ?????? ???? ?????
????? ????? ????? ?????? ????? ??? ????
b ?????? . -
g ?????? o
r ?????? x -.
c ?????? ?????? --
m ???????? ??????
y ?????? s ????
k ?????? d ????
w ?????? v ???? ??? ??????
???? ??? ??????
gt ???? ??? ??????
lt ???? ??? ??????
p ??? ?????
h ??? ?? ????
?? ???? ???? ???? ????? ????? ???? ??? ?? ??????
????? ?????.
17example
- x19
- arand(3)
- brand(3)
- crand(3)
- figure
- hold on
- plot (x,a(),'bs')
- plot (x,b(),'gd')
- plot (x,c(),'r')
- plot (x,a().c(),'m')
- hold off
18Image Processing Toolbox
- Reading a Graphics Image
- RGB, map imread('ngc6543a.jpg')
- Writing Image
- imwrite(A,map,filename,fmt)
- imwrite(RGB,map, 'myfile.jpg', 'Quality', 100)
- Image types
- BMP (Microsoft Windows Bitmap)
- CUR (Microsoft Windows Cursor resource)
- GIF (Graphics Interchange Format)
- HDF (Hierarchical Data Format)
- ICO (Windows Icon resource
- JPEG (Joint Photographic Experts Group)
- PBM (Portable Bitmap)
- PCX (Windows Paintbrush)
- PGM (Portable Graymap)
- PNG (Portable Network Graphics)
- PPM (Portable Pixmap) RAS (Sun Raster image)
- TIFF (Tagged Image File Format)
- XWD (X Window Dump)
19- Querying a Graphics File
- info imfinfo(filename)
- Name of the file
- File format
- Version number of the file format
- File modification date
- File size in bytes
- Image width in pixels
- Image height in pixels
- Number of bits per pixel
- Image type
- RGB (truecolor), intensity (grayscale), or
indexed
20- Converting Image Storage Classes
- im2double,
- im2uint8
- im2uint16
21Image Types in the Toolbox
- Indexed Images
- size(X) m,n
- imshow(X,map)
22- Intensity Images
- size(X) m,n
- values 0255
- I rgb2gray(RGB)
- imshow(I)
23- Binary image
- size(X) m,n
- values 0,1
- imshow(BW)
24- RGB image (True color)
- size(RGB) m,n,c
- c3
- values 0255
- imshow(RGB)
25- Display multi images
- X1,map1imread('forest.tif')
- X2,map2imread('trees.tif')
- subplot(1,2,1), imshow(X1,map2)
- subplot(1,2,2), imshow(X2,map2)
26- Display multi images with different color map
- X1,map1imread('forest.tif')
- X2,map2imread('trees.tif')
- subplot(1,2,1), subimage(X1,map1)
- subplot(1,2,2), subimage(X2,map2)
27Image Arithmetic Functions
Function Description
imabsdiff Absolute difference of two images
imadd Add two images
imcomplement Complement an image
imdivide Divide two images
imlincomb Compute linear combination of two images
immultiply Multiply two images
imsubtract Subtract two images
28example
- I imread('rice.tif')
- J imread('cameraman.tif')
- K imadd(I,J)
- imshow(K)
29Exercise
- Read a color image and display it
- Convert it to gray image and display it
- Calculate its histogram and display it as bar and
line figures - Read another gray image
- Display the average image
- Display all images in one figure
30Hints