際際滷

際際滷Share a Scribd company logo
Computer Vision MATLAB
Lecture 1  MATLAB
悒愆悋悄 惶悸 愕忰惘悸 >> A = magic(3) A = 8  1  6 3  5  7 4  9  2 悒愆悋悄 惶悸  >> b = [ 1  2  3  ;  4  5  6  ;  7  8  9  ] b = 1  2  3 4  5  6 7  8  9 悒惷悋悸 悋惺惆惆  2  悒 悋惶悸  A >> A+2 ans = 10  3  8 5  7  9 6  11  4 MATLAB
 悋惶悸  A >> A' ans = 8  3  4 1  5  9 6  7  2 惶悸 悋忰惆 >> x=ones(3) x = 1  1  1 1  1  1 1  1  1 MATLAB
>> x1=ones(3,2) x1 = 1  1 1  1 1  1 悋惶悸 悋惶惘悸 >> y=zeros(3) y = 0  0  0 0  0  0 0  0  0 >> y1=zeros(3,2) y1 = 0  0 0  0 0  0 MATLAB
Lecture 2 MATLAB
悒愆悋悄 惶悸 >> A = [  1  2  3  ;  4  5  6  ] A = 1  2  3 4  5  6 >> B = [ 7  8  9  ;  10  11  12  ] B = 7  8  9 10  11  12 >> C = [  1  2  3  4  5  ] C = 1  2  3  4  5 惺惘惷 悋惶悸  B    惶 >> B( 2 , : ) ans = 10  11  12 MATLAB
惺惘惷 悋惶悸  B    惺悋惆 >> B ( : , 2 ) ans = 8 11 惺惘惷 悋惶悸  B   惶 悋忰惆 悖惘惡惺悸 悖惺惆悸 >> B ( 1 : 4 ) ans = 7  10  8  11 悖惡惘 惺惆惆  悋惶悸  A >> max(A(:)) ans = 6 悖惶愃惘 惺惆惆  悋惶悸  C >> min(C (:)) ans = 1 MATLAB
悴惺 悋惶悸  C >> sum( C ( : ) ) ans = 15 惠愕愀 悋惶悸  B >> mean( B ( : )) ans = 9.5000 惺惘惷 悋惺惶惘  悋惶悸  A    悋惶  2  悋惺悋惆  3 >> A(2,3) ans = 6 MATLAB
Lecture 3 MATLAB
悒愆悋悄 惶悸 >> a=[1 2 3 ;4 5 6] a = 1  2  3 4  5  6 惺惘惷 悋惶悸 惺悋惆悋 >> a(:) ans = 1 4 2 5 3 6 惺惘惷 悋惶悸 悖悋 >> a(1:end) ans = 1  4  2  5  3  6 MATLAB
悒悴悋惆 惷惘惡  惶 >> prod(a) ans = 4  10  18 悒悴悋惆 惷惘惡 悋惶悸  a >> prod(prod(a)) ans = 720 悋悴悋惆 悴惺  惺悋惆 >> sum(a) ans = 5  7  9 悒悴悋惆 悖惡惘 惺惆惆  惺悋惆 >> max(a) ans = 4  5  6 MATLAB
悒悴悋惆 惠愕愀  惺悋惆 >> mean(a) ans = 2.5000  3.5000  4.5000 悒悴悋惆 悴惺 悋惶悸 >> sum(sum(a)) ans = 21 悒悴悋惆 悖惡惘 惺惆惆  悋惶悸 >> max(max(a)) ans = 6 悒悴悋惆 惠愕愀 悋惶悸 >> mean(mean(a)) ans = 3.5000 MATLAB
惺惘惷 愀惘 悋惶悸 >> diag(a) ans = 1 5 悴惺 愀惘 悋惶悸 >> sum(diag(a)) ans = 6 悒愆悋悄 惶悸 愕忰惘悸 >> x=magic(5) x = 17  24  1  8  15 23  5  7  14  16 4  6  13  20  22 10  12  19  21  3 11  18  25  2  9 MATLAB
悋悴悋惆 悴惺  惺悋惆  ( 悋忰惴  :  惠愕悋 悋惠悋悧悴  ) >> sum(x) ans = 65  65  65  65  65 悒悴悋惆 愀惘 悋惶悸 悋愕忰惘悸 >> diag(x) ans = 17 5 13 21 9 悋悴悋惆 悴惺 愀惘 悋惶悸  ( 悋忰惴  :  惠愕悋 悋悋惠悴 惺 悋惠悴 悴惺  惺悋惆  ) >> sum(diag(x)) ans = 65 悒悴悋惆 悴惺 悋惺悋惆 悋悖  悋惶 >> sum(a(1,:)) ans = 6 MATLAB
悒悴悋惆 悋悖惺惆悋惆 惡 悋惺惆惆  2  悋惺惆惆  5  惆悋惘 悋慍悋惆悸  1  悋惠惘悋惷悋 >> 2:5 ans = 2  3  4  5 悒悴悋惆 悋悖惺惆悋惆 惡 悋惺惆惆  2  悋惺惆惆  8  惆悋惘 悋慍悋惆悸  2   >> 2:2:8 ans = 2  4  6  8 惠愃惘 悋惺惶惘  悋惺惆  2  悋惶  1  惡悋惺惆惆  2 >> a(1,2)=2 a = 1  2  3 4  5  6 惠愃惘 悋惺惶惘  悋惺惆  1  悋惶  1  惡悋惺惆惆  2 >> a(1,1)=2 a = 2  2  3 4  5  6 MATLAB
悒悴悋惆 悋惺惆悋惆 悋惘惡悸  悋惺悋惆悸 悋惠悋悸 : >> z1=3+j*4 z1 = 3.0000 + 4.0000i >> z2=5+j*5 z2 = 5.0000 + 5.0000i >> z=z1+z2 z = 8.0000 + 9.0000i 惠忰 悋悖惺惆悋惆 : >> dec2hex(25) ans = 19 >> hex2num('A2C') ans = -2.6242e-141 >> dec2bin(144) ans = 1001000 MATLAB
忰悵 悋惺悋惆 悋惓悋惓 >> a(:,3)=[ ] a = 2  2 4  5 惺惘惷 忰悴 悋惶悸 >> size(a) ans = 2  2 MATLAB
Lecture 4 MATLAB
悋悽惠惡悋惘 悋悸 惡悋愕惠悽惆悋  If   (  (Simple if >> x=10; >> if x>5 disp(x) end 10 悒惆悽悋 悸 悋忰惆悸 a= input('b') b 100 a = 100 If else  >> a= 10; >> b=20; >> if a>20  disp(a) else b<30    disp(b) end ans = 20 MATLAB
悋悛悸 悋忰悋愕惡悸 惡悋愕惠悽惆悋  IF  >> n=25; >> m=10; >> d=1; >> if d==1 Disp(n+m) Else if d==2 Disp(n-m) Else if  d==3 Disp(n*m) Else disp(n/m) End End  End Ans = 35 MATLAB
悋悛悸 悋忰悋愕惡悸 惡悋愕惠悽惆悋  switch  >> n=25; >> m=10; >> d=1; >> switch d case 1 disp(n+m) case 2 disp(n-m) case 3 disp(n*m) case 4 disp(n/m) end ans = 35 MATLAB
悋悽惠惡悋惘 惆惘悴悋惠 悋愀悋惡 惡悋愕惠悽惆悋  switch >> x=50; >> switch x  case {90,91,92,93,94,95,96,97,98,99,100} disp('a') case {80,81,82,83,84,85,86,87,88,89} disp('b') case {70,71,72,73,74,75,76,77,78,79} disp('c') case {60,61,62,63,64,65,66,67,68,69} disp('d') otherwise disp('f') end MATLAB
悋愕惠悽惆悋  For : ( 悋惡惆悋悸 : 惆悋惘 悋慍悋惆悸 : 悋悋悸 ) >> for i=2:2:10 disp(i) end 2 4 6 8 10 MATLAB
Lecture 5 MATLAB
悋忰惴悸 : 惷惺 悋惶惘  悴惆 悋悋惠惘悋惷 惡惘悋悴  c:atlab7ork悴惡 惶惘悸 惷惺悋  惠愃惘 >> x=imread('a.bmp'); >> y=imread('sunset.jpg'); 惺惘惷 悋惶惘悸 >> image(x) >> imagesc(x) >> imview(x) >> imshow(x) MATLAB
惺惘惷 悖惓惘  惶惘悸    愕 悋   frame  惡悋悖惘  ( 悋惺悋惆 , 悋惶 , 悋惺 )  subplot >> subplot(2,1,1);image(x);title('image1'); >> subplot(2,1,2);image(y);title('image2'); >> image(y+z) 悋惶惘悸 悋悋惠悴悸 惠愕悋 惶惘悸 惡惷悋悄 惠惴惘  悽悋悋 悋悋悧悋惠 惡悋 悋悖愕惆 惠愀惡悋惠悋 :  1-  悋惠愆悋 忰惘悸 悋悋悧悋惠  惶惘惠 惠惠悋惡惺惠  2-  惠愀惘 愀惘 悋愕惠惺悋惆悸 悋惶惘悸 .   3-   惺悸 悋惠忰  愆 悒 悛悽惘 (  悋忰惴悸  :  悋  悴惺 惶惠 悒悋 惡愆惘愀 悖  惠愕悋惠  悋悋惡惺悋惆  ) MATLAB
>> image(y-z) 惷惘惡 悋惶悸 惡惠惠忰 悋惶惘悸 悴惡 悖  悖惡惘  悋悋忰惆 >> image(y*15) 悋愕悸  惡惠愃 悋惶惘悸 >> image(y/15) 惺愕 悋惶惘悸 愀惘忰  255 >> image(255-x) MATLAB
惺惘惷 惶惘悸  悋惶悸 悋惶惘悸  惺惘惷 惶惘悸  惶悸 悋忰惆悋惠 >> imshow(ones(200))  >> imshow(zeros(200)) MATLAB
惺 惶惘悸 惡惷悋悄 惠惡 悋悋惘 :-  惺 惶惘悸 愕惆悋悄 惠惡 悋悋惘 :- B= zeros(200,200);  A= ones(200,200); (  惺惘惷 惶惘悸 悴慍悧悋 悋悋惺 悋惡惷 悋悴慍悄 悋愕 悋愕惆  ) 惺 悵悋 悋愆 惺惆 惺 悋惶惘悸  B  ( 悋惶惘悸 悋愕惆悋悄 )  惠惡 悋悋惘 :- >>B(1:100,1:200)=1; >> imshow(B); MATLAB
Lecture 6  MATLAB
Type of image: 1-color image 2-Binary image 3- Intensity (Gary scale) image 4- indexed image MATLAB
1-color image: 惠  惠 惺 惶悸  ( x,y,z )  惠 悋惠惆悋惆悋  jpg >> rgb=imread(a1.jpg'); 2-Binary image: 惠忰 悋惶惘悸 悒 惓悋悧  (0  1) >> z=ind2gray(x,cmap) >> imview(z) 悋悽悵 悋愀悋惘 悋惶惘悸 惠 惓悋悧 >> imview(edge(z)) MATLAB
3- Intensity(Gary scale) image 悒惴悋惘 悋惶惘悸  愕惠悽惆  gray >> image(x);colormap(gray) 4- indexed image 惠  x    惺悋 惠 悵悋惠 惡惺惆  ( x,y )    cmap  ( color map )  悽惘愀悸 悋悖悋 愕惠悽惆 悋惠惆悋惆  tif >> [x,cmep]=imread('trees.tif'); 悒惴悋惘 悋惶惘悸 悒惴悋惘 悽惘愀悸 悋悋悋 >> image(x);colormap(cmap)  悋忰惴悸 :  悋惴悋惘 悋惶惘悸  忰悴悋 悋愀惡惺 愕惠悽惆 悖惘 >> truesize 悋悽悵 悋愀悋惘 悋惶惘悸  >> imview(edge(z)) MATLAB
悒愕惠愀悋惺 悴慍悄  悋惶惘悸  (  悴惡 悋 惺惘 忰悴 悋惶 愕惠悽惆  ( size >> size(x) >> imview(x(200:400,200:500)) 惺惘惷 悋惶惘悸  悖惓惘  悋愀悋惘 >> figure;image(x) >> figure;image(z) MATLAB
Lecture 7  MATLAB
Type of image: 1-color image 2-Binary image 3- Intensity (Gary scale) image 4- indexed image  MATLAB
愀惘悸 惠悽慍  index image  : [x,cmop]=imread('tree.tif'); 愀惘悸 悋惺惘惷  : Image(x);colormap(comp); Or  imshow(x,comp);  惓悋 悋悽惘 [s,ss]=imread('aa.gif'); 惺惘惷 Image(s),colormap(ss); 愀惘悸 悒惆悽悋  intensity image  : [s,ss]=imread('aa.gif'); 愀惘悸 悋惺惘惷  : Image(s); colormap(gray); Or  image(s,gray);  MATLAB
愀惘悸 悋悋惆悽悋   color image : X=imread('a1.jpg'); 愀惘悸 悋惺惘惷  : Image(x); 愀惘悸 惺惘惷  binary image  : Imview(edge(y)); 愀惘悸 惺惘惷 悴慍悄  悋惶惘悸  : L=x(1:100,1:200) Image( L ); 惠忰   color  悒  gray image  : Y=rgb2gray(x); Imshow(Y); 惠忰   color  悒  binary  : Z=im2bw(x); Imshow(Z); 惠忰 悋惶惘 悋 悋忰惆 悋惺愕   binary  : Z=~x MATLAB
悋惺悋惠 悋愀悸  (  惠惠 悵 悋惺悋惠 惺  binary image  ) :- 惺悸   and  (&):  惠愕惠悽惆 悵 悋惺悸悒惷悋惘 悴惺 惺悋惶惘 悋惶惘惠 惠愀惡悋惠悋 :  1-  惺悸 悋悋惺   2-  悋愕惠愀悋惺 悴慍悄  悋惶惘悸 惺悸  OR (||):  愆悋惡悸 惺悸 悋悴惺 :   悋惶惘悸 悋悋惠悴悸 惠惴惘 悋悋悧悋惠 悋惓悋惡惠 惠愀惡悋惠悋 : 1-  惺悸 悋悋惺  2-  悋愕惠愀悋惺 悴慍悄  悋惶惘悸 惺悸   not  ( ~ ):  惠愕惠悽惆   惺愕 悋惶惘悸  1-  悒悵悋 悋惠 惓悋悧悸 :  惶惘悸 惺愕悸 惡忰惓 惠忰   0  悒  1  悋惺愕  2-  悒悵悋 悋惠 惘悋惆悸  :  惠 惡惺愕 悋悖悋   0  悒  255  惺悸  xor :  惠惺愀 悋悸  0   忰悋悸 悋惠愆悋惡   1   忰悋悸 悋悋悽惠悋 惠 悵悋惠 悽悸 愕惆悋悄 惠惴惘  悋悋悧悋惠 悋悽惠悸  MATLAB
>> x=imread('a1.jpg');  >> y=imread('a2.jpg'); >> c=im2bw(x);  >> v=im2bw(y); >> imshow(c);  >> imshow(v); MATLAB
>> or=c|v; >> and=c&v; >> not=~c; >> nott=~v; >> xr=xor(c,v); >> subplot(2,3,1);imshow(or);title('image c|v'); >> subplot(2,3,2);imshow(and);title('image c&v'); >> subplot(2,3,3);imshow(not);title('~c'); >> subplot(2,3,4);imshow(nott);title('~v'); >> subplot(2,3,5);imshow(xr);title('xor image c , v'); MATLAB
MATLAB
Lecture 8  MATLAB
惘悋悄 悋惶惘悸 悋悖 >> a= imread('sunset.jpg'); >> subplot(3,3,1); imshow(a); title('a'); 惘悋悄 悋惶惘悸 悋惓悋悸 >> b=imread('winter.jpg'); >> subplot(3,3,2); imshow(b); title('b'); MATLAB
悋惺悋惠 惺 悋惶惘悸   : 悋悴惺 惶惘惠 >> c=imadd(a,b); >> subplot(3,3,3); imshow(c); title('a+b'); 悋愀惘忰 惶惘惠 >> z=imsubtract(a,b); >> subplot(3,3,4); imshow(z); title('a-b'); 惷惘惡 惶惘惠 >> g=immultiply(a,b); >> subplot(3,3,5); imshow(g); title('a*b'); MATLAB
惷惘惡 惶惘悸 惺 惺惆惆 >> f=immultiply(a,2); >> subplot(3,3,6); imshow(f); title('a*2'); 愕悸 惶惘惠  >> d=imdivide(a,b); >> subplot(3,3,7); imshow(d); title('a/b'); 愕悸 惶惘悸 惺 惺惆惆 >> e=imdivide(a,2); >> subplot(3,3,8); imshow(e); title('a/2'); MATLAB
MATLAB
Lecture 9  MATLAB
 悽  mask   惺 悋惶惘悸 悒悽悋悄 悴慍悄 惺  悋惶惘悸 惠惡惺 悋悽愀悋惠 悋惠悋 :- >>x=imread('c2.jpg'); 忰惆惆 悋惡愕 悋惠  悽悋悋 慍 悋  mask   惡忰惓 (  y1:y2,x1:x2  ): >>x(147:179,185:279,:)=0; 惠惡 悋惘 惺惘惷 悋惶惘悸  :- >>imshow(x); MATLAB x1,y1 x2,y2
MIRROR:- x=imread('f.jpg'); R=x( end:-1:1,end:-1:1,: );  Imshow(R); MATLAB x1,y1 x2,y2
Zoom:-  Shrink:-  Imshow( x(1:0,5:end,1:0.5:end,:) );  Imshow(x (1:4:end,1:4:end,:) ); MATLAB x1,y1 x2,y2
Lecture 10  MATLAB
NOISE AND FILTERS -salte & pepper noise:- >>a=imread('a2.jpg'); >> aa=rgb2gray(a); >> g=imnoise(aa,'salt & pepper'); >> imshow(g); -The best filter is (medfilit2) >> gm=medfilt2(g); >> imshow(gm); MATLAB
NOISE AND FILTERS -gaussian noise:- >> z=imnoise(aa,'gaussian');   >> imshow(z); -The best filter is (wiener2) >> zw=wiener2(z,[3,3]); >> imshow(zw); MATLAB
NOISE AND FILTERS -  Speckle   noise:- >> s=imnoise(aa,'speckle'); >> imshow(s); -The best filter is (ordfilt2) >> so=ordfilt2(s,15,true(5)); >> imshow(zw); MATLAB
悴悋惺悸 悋愀悋悧  悸 悋忰悋愕惡悋惠 惴 悋惺悋惠 惆惺悸  25  悴惺悸 悋惠慍 2004-2008 MATLAB

More Related Content

Computer Vision

  • 2. Lecture 1 MATLAB
  • 3. 悒愆悋悄 惶悸 愕忰惘悸 >> A = magic(3) A = 8 1 6 3 5 7 4 9 2 悒愆悋悄 惶悸 >> b = [ 1 2 3 ; 4 5 6 ; 7 8 9 ] b = 1 2 3 4 5 6 7 8 9 悒惷悋悸 悋惺惆惆 2 悒 悋惶悸 A >> A+2 ans = 10 3 8 5 7 9 6 11 4 MATLAB
  • 4. 悋惶悸 A >> A' ans = 8 3 4 1 5 9 6 7 2 惶悸 悋忰惆 >> x=ones(3) x = 1 1 1 1 1 1 1 1 1 MATLAB
  • 5. >> x1=ones(3,2) x1 = 1 1 1 1 1 1 悋惶悸 悋惶惘悸 >> y=zeros(3) y = 0 0 0 0 0 0 0 0 0 >> y1=zeros(3,2) y1 = 0 0 0 0 0 0 MATLAB
  • 7. 悒愆悋悄 惶悸 >> A = [ 1 2 3 ; 4 5 6 ] A = 1 2 3 4 5 6 >> B = [ 7 8 9 ; 10 11 12 ] B = 7 8 9 10 11 12 >> C = [ 1 2 3 4 5 ] C = 1 2 3 4 5 惺惘惷 悋惶悸 B 惶 >> B( 2 , : ) ans = 10 11 12 MATLAB
  • 8. 惺惘惷 悋惶悸 B 惺悋惆 >> B ( : , 2 ) ans = 8 11 惺惘惷 悋惶悸 B 惶 悋忰惆 悖惘惡惺悸 悖惺惆悸 >> B ( 1 : 4 ) ans = 7 10 8 11 悖惡惘 惺惆惆 悋惶悸 A >> max(A(:)) ans = 6 悖惶愃惘 惺惆惆 悋惶悸 C >> min(C (:)) ans = 1 MATLAB
  • 9. 悴惺 悋惶悸 C >> sum( C ( : ) ) ans = 15 惠愕愀 悋惶悸 B >> mean( B ( : )) ans = 9.5000 惺惘惷 悋惺惶惘 悋惶悸 A 悋惶 2 悋惺悋惆 3 >> A(2,3) ans = 6 MATLAB
  • 11. 悒愆悋悄 惶悸 >> a=[1 2 3 ;4 5 6] a = 1 2 3 4 5 6 惺惘惷 悋惶悸 惺悋惆悋 >> a(:) ans = 1 4 2 5 3 6 惺惘惷 悋惶悸 悖悋 >> a(1:end) ans = 1 4 2 5 3 6 MATLAB
  • 12. 悒悴悋惆 惷惘惡 惶 >> prod(a) ans = 4 10 18 悒悴悋惆 惷惘惡 悋惶悸 a >> prod(prod(a)) ans = 720 悋悴悋惆 悴惺 惺悋惆 >> sum(a) ans = 5 7 9 悒悴悋惆 悖惡惘 惺惆惆 惺悋惆 >> max(a) ans = 4 5 6 MATLAB
  • 13. 悒悴悋惆 惠愕愀 惺悋惆 >> mean(a) ans = 2.5000 3.5000 4.5000 悒悴悋惆 悴惺 悋惶悸 >> sum(sum(a)) ans = 21 悒悴悋惆 悖惡惘 惺惆惆 悋惶悸 >> max(max(a)) ans = 6 悒悴悋惆 惠愕愀 悋惶悸 >> mean(mean(a)) ans = 3.5000 MATLAB
  • 14. 惺惘惷 愀惘 悋惶悸 >> diag(a) ans = 1 5 悴惺 愀惘 悋惶悸 >> sum(diag(a)) ans = 6 悒愆悋悄 惶悸 愕忰惘悸 >> x=magic(5) x = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 MATLAB
  • 15. 悋悴悋惆 悴惺 惺悋惆 ( 悋忰惴 : 惠愕悋 悋惠悋悧悴 ) >> sum(x) ans = 65 65 65 65 65 悒悴悋惆 愀惘 悋惶悸 悋愕忰惘悸 >> diag(x) ans = 17 5 13 21 9 悋悴悋惆 悴惺 愀惘 悋惶悸 ( 悋忰惴 : 惠愕悋 悋悋惠悴 惺 悋惠悴 悴惺 惺悋惆 ) >> sum(diag(x)) ans = 65 悒悴悋惆 悴惺 悋惺悋惆 悋悖 悋惶 >> sum(a(1,:)) ans = 6 MATLAB
  • 16. 悒悴悋惆 悋悖惺惆悋惆 惡 悋惺惆惆 2 悋惺惆惆 5 惆悋惘 悋慍悋惆悸 1 悋惠惘悋惷悋 >> 2:5 ans = 2 3 4 5 悒悴悋惆 悋悖惺惆悋惆 惡 悋惺惆惆 2 悋惺惆惆 8 惆悋惘 悋慍悋惆悸 2 >> 2:2:8 ans = 2 4 6 8 惠愃惘 悋惺惶惘 悋惺惆 2 悋惶 1 惡悋惺惆惆 2 >> a(1,2)=2 a = 1 2 3 4 5 6 惠愃惘 悋惺惶惘 悋惺惆 1 悋惶 1 惡悋惺惆惆 2 >> a(1,1)=2 a = 2 2 3 4 5 6 MATLAB
  • 17. 悒悴悋惆 悋惺惆悋惆 悋惘惡悸 悋惺悋惆悸 悋惠悋悸 : >> z1=3+j*4 z1 = 3.0000 + 4.0000i >> z2=5+j*5 z2 = 5.0000 + 5.0000i >> z=z1+z2 z = 8.0000 + 9.0000i 惠忰 悋悖惺惆悋惆 : >> dec2hex(25) ans = 19 >> hex2num('A2C') ans = -2.6242e-141 >> dec2bin(144) ans = 1001000 MATLAB
  • 18. 忰悵 悋惺悋惆 悋惓悋惓 >> a(:,3)=[ ] a = 2 2 4 5 惺惘惷 忰悴 悋惶悸 >> size(a) ans = 2 2 MATLAB
  • 20. 悋悽惠惡悋惘 悋悸 惡悋愕惠悽惆悋 If ( (Simple if >> x=10; >> if x>5 disp(x) end 10 悒惆悽悋 悸 悋忰惆悸 a= input('b') b 100 a = 100 If else >> a= 10; >> b=20; >> if a>20 disp(a) else b<30 disp(b) end ans = 20 MATLAB
  • 21. 悋悛悸 悋忰悋愕惡悸 惡悋愕惠悽惆悋 IF >> n=25; >> m=10; >> d=1; >> if d==1 Disp(n+m) Else if d==2 Disp(n-m) Else if d==3 Disp(n*m) Else disp(n/m) End End End Ans = 35 MATLAB
  • 22. 悋悛悸 悋忰悋愕惡悸 惡悋愕惠悽惆悋 switch >> n=25; >> m=10; >> d=1; >> switch d case 1 disp(n+m) case 2 disp(n-m) case 3 disp(n*m) case 4 disp(n/m) end ans = 35 MATLAB
  • 23. 悋悽惠惡悋惘 惆惘悴悋惠 悋愀悋惡 惡悋愕惠悽惆悋 switch >> x=50; >> switch x case {90,91,92,93,94,95,96,97,98,99,100} disp('a') case {80,81,82,83,84,85,86,87,88,89} disp('b') case {70,71,72,73,74,75,76,77,78,79} disp('c') case {60,61,62,63,64,65,66,67,68,69} disp('d') otherwise disp('f') end MATLAB
  • 24. 悋愕惠悽惆悋 For : ( 悋惡惆悋悸 : 惆悋惘 悋慍悋惆悸 : 悋悋悸 ) >> for i=2:2:10 disp(i) end 2 4 6 8 10 MATLAB
  • 26. 悋忰惴悸 : 惷惺 悋惶惘 悴惆 悋悋惠惘悋惷 惡惘悋悴 c:atlab7ork悴惡 惶惘悸 惷惺悋 惠愃惘 >> x=imread('a.bmp'); >> y=imread('sunset.jpg'); 惺惘惷 悋惶惘悸 >> image(x) >> imagesc(x) >> imview(x) >> imshow(x) MATLAB
  • 27. 惺惘惷 悖惓惘 惶惘悸 愕 悋 frame 惡悋悖惘 ( 悋惺悋惆 , 悋惶 , 悋惺 ) subplot >> subplot(2,1,1);image(x);title('image1'); >> subplot(2,1,2);image(y);title('image2'); >> image(y+z) 悋惶惘悸 悋悋惠悴悸 惠愕悋 惶惘悸 惡惷悋悄 惠惴惘 悽悋悋 悋悋悧悋惠 惡悋 悋悖愕惆 惠愀惡悋惠悋 : 1- 悋惠愆悋 忰惘悸 悋悋悧悋惠 惶惘惠 惠惠悋惡惺惠 2- 惠愀惘 愀惘 悋愕惠惺悋惆悸 悋惶惘悸 . 3- 惺悸 悋惠忰 愆 悒 悛悽惘 ( 悋忰惴悸 : 悋 悴惺 惶惠 悒悋 惡愆惘愀 悖 惠愕悋惠 悋悋惡惺悋惆 ) MATLAB
  • 28. >> image(y-z) 惷惘惡 悋惶悸 惡惠惠忰 悋惶惘悸 悴惡 悖 悖惡惘 悋悋忰惆 >> image(y*15) 悋愕悸 惡惠愃 悋惶惘悸 >> image(y/15) 惺愕 悋惶惘悸 愀惘忰 255 >> image(255-x) MATLAB
  • 29. 惺惘惷 惶惘悸 悋惶悸 悋惶惘悸 惺惘惷 惶惘悸 惶悸 悋忰惆悋惠 >> imshow(ones(200)) >> imshow(zeros(200)) MATLAB
  • 30. 惺 惶惘悸 惡惷悋悄 惠惡 悋悋惘 :- 惺 惶惘悸 愕惆悋悄 惠惡 悋悋惘 :- B= zeros(200,200); A= ones(200,200); ( 惺惘惷 惶惘悸 悴慍悧悋 悋悋惺 悋惡惷 悋悴慍悄 悋愕 悋愕惆 ) 惺 悵悋 悋愆 惺惆 惺 悋惶惘悸 B ( 悋惶惘悸 悋愕惆悋悄 ) 惠惡 悋悋惘 :- >>B(1:100,1:200)=1; >> imshow(B); MATLAB
  • 31. Lecture 6 MATLAB
  • 32. Type of image: 1-color image 2-Binary image 3- Intensity (Gary scale) image 4- indexed image MATLAB
  • 33. 1-color image: 惠 惠 惺 惶悸 ( x,y,z ) 惠 悋惠惆悋惆悋 jpg >> rgb=imread(a1.jpg'); 2-Binary image: 惠忰 悋惶惘悸 悒 惓悋悧 (0 1) >> z=ind2gray(x,cmap) >> imview(z) 悋悽悵 悋愀悋惘 悋惶惘悸 惠 惓悋悧 >> imview(edge(z)) MATLAB
  • 34. 3- Intensity(Gary scale) image 悒惴悋惘 悋惶惘悸 愕惠悽惆 gray >> image(x);colormap(gray) 4- indexed image 惠 x 惺悋 惠 悵悋惠 惡惺惆 ( x,y ) cmap ( color map ) 悽惘愀悸 悋悖悋 愕惠悽惆 悋惠惆悋惆 tif >> [x,cmep]=imread('trees.tif'); 悒惴悋惘 悋惶惘悸 悒惴悋惘 悽惘愀悸 悋悋悋 >> image(x);colormap(cmap) 悋忰惴悸 : 悋惴悋惘 悋惶惘悸 忰悴悋 悋愀惡惺 愕惠悽惆 悖惘 >> truesize 悋悽悵 悋愀悋惘 悋惶惘悸 >> imview(edge(z)) MATLAB
  • 35. 悒愕惠愀悋惺 悴慍悄 悋惶惘悸 ( 悴惡 悋 惺惘 忰悴 悋惶 愕惠悽惆 ( size >> size(x) >> imview(x(200:400,200:500)) 惺惘惷 悋惶惘悸 悖惓惘 悋愀悋惘 >> figure;image(x) >> figure;image(z) MATLAB
  • 36. Lecture 7 MATLAB
  • 37. Type of image: 1-color image 2-Binary image 3- Intensity (Gary scale) image 4- indexed image MATLAB
  • 38. 愀惘悸 惠悽慍 index image : [x,cmop]=imread('tree.tif'); 愀惘悸 悋惺惘惷 : Image(x);colormap(comp); Or imshow(x,comp); 惓悋 悋悽惘 [s,ss]=imread('aa.gif'); 惺惘惷 Image(s),colormap(ss); 愀惘悸 悒惆悽悋 intensity image : [s,ss]=imread('aa.gif'); 愀惘悸 悋惺惘惷 : Image(s); colormap(gray); Or image(s,gray); MATLAB
  • 39. 愀惘悸 悋悋惆悽悋 color image : X=imread('a1.jpg'); 愀惘悸 悋惺惘惷 : Image(x); 愀惘悸 惺惘惷 binary image : Imview(edge(y)); 愀惘悸 惺惘惷 悴慍悄 悋惶惘悸 : L=x(1:100,1:200) Image( L ); 惠忰 color 悒 gray image : Y=rgb2gray(x); Imshow(Y); 惠忰 color 悒 binary : Z=im2bw(x); Imshow(Z); 惠忰 悋惶惘 悋 悋忰惆 悋惺愕 binary : Z=~x MATLAB
  • 40. 悋惺悋惠 悋愀悸 ( 惠惠 悵 悋惺悋惠 惺 binary image ) :- 惺悸 and (&): 惠愕惠悽惆 悵 悋惺悸悒惷悋惘 悴惺 惺悋惶惘 悋惶惘惠 惠愀惡悋惠悋 : 1- 惺悸 悋悋惺 2- 悋愕惠愀悋惺 悴慍悄 悋惶惘悸 惺悸 OR (||): 愆悋惡悸 惺悸 悋悴惺 : 悋惶惘悸 悋悋惠悴悸 惠惴惘 悋悋悧悋惠 悋惓悋惡惠 惠愀惡悋惠悋 : 1- 惺悸 悋悋惺 2- 悋愕惠愀悋惺 悴慍悄 悋惶惘悸 惺悸 not ( ~ ): 惠愕惠悽惆 惺愕 悋惶惘悸 1- 悒悵悋 悋惠 惓悋悧悸 : 惶惘悸 惺愕悸 惡忰惓 惠忰 0 悒 1 悋惺愕 2- 悒悵悋 悋惠 惘悋惆悸 : 惠 惡惺愕 悋悖悋 0 悒 255 惺悸 xor : 惠惺愀 悋悸 0 忰悋悸 悋惠愆悋惡 1 忰悋悸 悋悋悽惠悋 惠 悵悋惠 悽悸 愕惆悋悄 惠惴惘 悋悋悧悋惠 悋悽惠悸 MATLAB
  • 41. >> x=imread('a1.jpg'); >> y=imread('a2.jpg'); >> c=im2bw(x); >> v=im2bw(y); >> imshow(c); >> imshow(v); MATLAB
  • 42. >> or=c|v; >> and=c&v; >> not=~c; >> nott=~v; >> xr=xor(c,v); >> subplot(2,3,1);imshow(or);title('image c|v'); >> subplot(2,3,2);imshow(and);title('image c&v'); >> subplot(2,3,3);imshow(not);title('~c'); >> subplot(2,3,4);imshow(nott);title('~v'); >> subplot(2,3,5);imshow(xr);title('xor image c , v'); MATLAB
  • 44. Lecture 8 MATLAB
  • 45. 惘悋悄 悋惶惘悸 悋悖 >> a= imread('sunset.jpg'); >> subplot(3,3,1); imshow(a); title('a'); 惘悋悄 悋惶惘悸 悋惓悋悸 >> b=imread('winter.jpg'); >> subplot(3,3,2); imshow(b); title('b'); MATLAB
  • 46. 悋惺悋惠 惺 悋惶惘悸 : 悋悴惺 惶惘惠 >> c=imadd(a,b); >> subplot(3,3,3); imshow(c); title('a+b'); 悋愀惘忰 惶惘惠 >> z=imsubtract(a,b); >> subplot(3,3,4); imshow(z); title('a-b'); 惷惘惡 惶惘惠 >> g=immultiply(a,b); >> subplot(3,3,5); imshow(g); title('a*b'); MATLAB
  • 47. 惷惘惡 惶惘悸 惺 惺惆惆 >> f=immultiply(a,2); >> subplot(3,3,6); imshow(f); title('a*2'); 愕悸 惶惘惠 >> d=imdivide(a,b); >> subplot(3,3,7); imshow(d); title('a/b'); 愕悸 惶惘悸 惺 惺惆惆 >> e=imdivide(a,2); >> subplot(3,3,8); imshow(e); title('a/2'); MATLAB
  • 49. Lecture 9 MATLAB
  • 50. mask 惺 悋惶惘悸 悒悽悋悄 悴慍悄 惺 悋惶惘悸 惠惡惺 悋悽愀悋惠 悋惠悋 :- >>x=imread('c2.jpg'); 忰惆惆 悋惡愕 悋惠 悽悋悋 慍 悋 mask 惡忰惓 ( y1:y2,x1:x2 ): >>x(147:179,185:279,:)=0; 惠惡 悋惘 惺惘惷 悋惶惘悸 :- >>imshow(x); MATLAB x1,y1 x2,y2
  • 51. MIRROR:- x=imread('f.jpg'); R=x( end:-1:1,end:-1:1,: ); Imshow(R); MATLAB x1,y1 x2,y2
  • 52. Zoom:- Shrink:- Imshow( x(1:0,5:end,1:0.5:end,:) ); Imshow(x (1:4:end,1:4:end,:) ); MATLAB x1,y1 x2,y2
  • 53. Lecture 10 MATLAB
  • 54. NOISE AND FILTERS -salte & pepper noise:- >>a=imread('a2.jpg'); >> aa=rgb2gray(a); >> g=imnoise(aa,'salt & pepper'); >> imshow(g); -The best filter is (medfilit2) >> gm=medfilt2(g); >> imshow(gm); MATLAB
  • 55. NOISE AND FILTERS -gaussian noise:- >> z=imnoise(aa,'gaussian'); >> imshow(z); -The best filter is (wiener2) >> zw=wiener2(z,[3,3]); >> imshow(zw); MATLAB
  • 56. NOISE AND FILTERS - Speckle noise:- >> s=imnoise(aa,'speckle'); >> imshow(s); -The best filter is (ordfilt2) >> so=ordfilt2(s,15,true(5)); >> imshow(zw); MATLAB
  • 57. 悴悋惺悸 悋愀悋悧 悸 悋忰悋愕惡悋惠 惴 悋惺悋惠 惆惺悸 25 悴惺悸 悋惠慍 2004-2008 MATLAB

Editor's Notes

  • #2: This presentation shows how The MathWorks products provide an integrated approach for the design of complex systems. Beginning with the concept, the tools provide the ability to develop the system, verify that it satisfies the specifications, allows the designer to optimize the design, and finally, automatically creates the embedded code. Using examples from aircraft and spacecraft design, the unique features of The MathWorks products that allow this process are highlighted. In particular, the open nature of the products and their integration are exploited.