น.ส.พัชรินทร์ ลีบาง 58670357 กลุ่ม 3304

Post on 23-Jan-2018

144 Views

Category:

Education

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Matlab

MATLAB คืออะไร

MATLAB เป็นภาษาคอมพิวเตอร์ชั้นสูง (High-level Language) สาํหรับการคาํนวณทางเทคนิคท่ีประกอบดว้ยการคาํนวณเชิง

ตวัเลข กราฟิกท่ีซบัซอ้น และการจาํลองแบบเพ่ือใหม้องเห็นภาพพจน์ไดง้่ายและชดัเจนช่ือของ MATLAB ยอ่มาจาก matrix

laboratory เดิมโปรแกรม MATLAB ไดเ้ขียนข้ึนเพ่ือใชใ้นการคาํนวณทาง matrix หรือเป็น matrix software ท่ีพฒันาจากโพรเจก็

ท่ีช่ือ LINKPACK และ EISPACK

MATLAB ไดพ้ฒันามาดว้ยการแกปั้ญหาท่ีส่งมาจากหลายๆ ผูใ้ชเ้ป็นระยะเวลาหลายปีจึงทาํใหโ้ปรแกรม MATLAB มีฟังกช์นั

ต่างๆ ใหเ้ลือกใชม้ากมาย ในบางมหาวิทยาลยัไดใ้ชโ้ปรแกรม MATLAB เป็นหลกัสูตรพ้ืนฐานในการศึกษาทางดว้น

คณิตศาสตร์ วิศวกรรม และวิทยาศาสตร์แขนงต่างตลอดจนใจดว้นอุตสาหกรรมไดใ้ชโ้ปรแกรม MATLAB เป็นเคร่ืองมือ

สาํหรับใชใ้นงานวิจยั พฒันาและวเิคราะห์

โปรแกรม MATLAB จะมีกล่องเคร่ืองมือท่ีใชใ้นการหาคาํตอบเรียกวา่ Toolbox โดยโปรแกรม MATLAB จะมี toolbox ในแต่

ละสาขา เช่น การประมวลผลสัญญาณ (Signal processing toolbox) การประมวลผลภาพ (image processing toolbox) ระบบ

ควบคุม (control system toolbox) โครงข่ายประสาท (neural networks toolbox) ฟัซซ่ีลอจิก (fuzzy logic toolbox) เวฟเลท

(wavelet toolbox) การติดต่อส่ือสาร (communication toolbox) สถิติ (Statistics toolbox) และสาขาอ่ืนๆ มากมาย ภายใน toolbox

แต่ละสาขาก็จะมีฟังกช์นัต่างๆ ท่ีเก่ียวขอ้งกบัการแกปั้ญหาในสาขานั้นๆ ใหเ้ลือกประยกุตใ์ชง้านเป็นจาํนวนมาก

Time (s)

0 5 10 15 20 25 30

Dis

tanc

e (m

)

1

1.2

1.4

1.6

1.8

2

2.2

2.4

2.6

2.8

3Plot of Distance overTime

การสร้างกราฟ

ใชฟั้งกช์นั plot

กาํหนดตวัแปลแลว้ตามดว้ยคาํสั่ง plot

x = [3 9 27];

Y = [1 2 3];

plot(x,y)

การเขียนช่ือกราฟ

>> title(',,,,,,,,,’) % ช่ือกราฟ

>> xlabel('…..') % ป้ายช่ือจะแสดงในแกน x

>> ylabel('…..') % ป้ายช่ือจะแสดงในแกน y

การใส่สัญลกัษณ์ (Legends) สร้างเสน้ข้ึนมา 3 เสน้ โดยกาํหนดตวัแปร x,y,z และt โดยให ้

ตวัแปร x จบัคู่กบัตวัแปร t

ตวัแปร y จบัคู่กบัตวัแปร t

ตวัแปร z จบัคู่กบัตวัแปร t

ใช้คาํส่ัง legend('ช่ือ1', 'ช่ือ 2', 'ช่ือ 3')

การplot กราฟแบบย่อย

โดยการใชค้าํสั่ง subplot( rowของplotท่ีแสดง, column ของ plot ท่ีแสดง,จาํนวน plot) เช่น subplot(2,1,1);

2

1

0-1

-2-2

-1

0

1

0.5

0

-0.5

2

การทาํภาพแบบ 3D

ใชค้าํสั่ง [x,y] = meshgrid([-2:.2:2]);

Z = x.*exp(-x.^2-y.^2);

figure

surf(x,y,Z,gradient(Z))

gradient(Z)

colorbar

TopoToolbox

ทาํการ Download ก่อนโดยทาํการสืบคน้ทาง google แลว้พิมพค์าํวา่ topotoolbox

เปิดโฟร์เดอร์ topotoolbox จากนั้นพิมพค์าํสั่งน้ีลงไปในช่อง Command window DEM = GRIDobj

(‘kidchakood DEM’);

ถา้เรียกไดจ้ะมีโคด้ข้ึนมาในโปรแกรม

หลงัจากนั้น ใชค้าํสั่ง ใชค้าํสั่ง imagesc(DEM)

ถา้อยากใหค้วามลาดชนัท่ีชดัเจนมากข้ึนใชค้าํสั่ง imageschs(DEM,min(gradient8(DEM),1))

การแสดงพืน้ทีใ่นรูปแบบ plot in 3D

ใชค้าํสั่งDEMc = crop(DEM,sub2ind(DEM.size,[150 350],[150 350]));

[Z,x,y] = GRIDobj2mat(DEMc);

surf(x,y,double(Z))

Fill sinks การไหลของนํา้ การใช้ฟังก์ชัน FLOWobj

คาํสั่งFD = FLOWobj(DEMf);

A = flowacc(FD);

imageschs(DEM,dilate(sqrt(A),ones(5)),'colormap',flipud(copper));

การระบายของลุ่มนํา้

ใชค้าํสั่งน้ี

Image Processing Basic

พื้นฐานของการประมวลผลของภาพ โดยวธีิการดา้นต่างๆ เช่น การปรับสี, การปรับเชิงรังสี, การปรับแกก้าร

บิดเบ้ียวของภาพ

การปรับภาพสีเป็นภาพขาวดํา

1.Browse for folder เลือกโฟลเ์ดอร์ท่ีตอ้งการ Enter ตั้งช่ือตวัแปร ตามดว้ยช่ือภาพท่ีเลือก Enter

2.ใช ้whos picture เพื่อตรวจสอบขนาดของภาพ

3.figure,imshow(Pic) =การโชว์ภาพ เรียกภาพขึน้มา

4.Pic1 = rgb2gray(Pic) = การแปลงภาพส ี

5. figure,imshow(adjust1)

การเช็คเฮิทโปรแกรมของรูป imhist(Pic1)

ภาพขาว – ดํา

ช่ือตวัแปรใหม ่= im2bw(ช่ือตวั

แปรท่ีเก็บรูปภาพส)ี

Y = im2bw(a)

imshow(Y)

การใช้ฟังก์ชนั imaqtool เพ่ือตรวจสอบ driver ของกล้องWebcam

ทาํภาพ 3 มิติ

คน้หารูป stereo pair ใน Google และนาํมาตดัเป็น 2 ภาพ ใน paint

เข้า matlab

เพ่ิมโค้ด

I1 = rgb2gray(imread('left.jpg'));

I2 = rgb2gray(imread('right.jpg'));

imshowpair(I1, I2,'montage');

title('I1 (left); I2 (right)');

figure;

imshowpair(I1,I2,'ColorChannels','red-cyan');

title('Composite Image (Red - Left Image, Cyan - Right Image)');

blobs1 = detectSURFFeatures(I1, 'MetricThreshold', 2000);

blobs2 = detectSURFFeatures(I2, 'MetricThreshold', 2000);

figure;

imshow(I1);

hold on;

plot(selectStrongest(blobs1, 30));

title('Thirty strongest SURF features in I1');

figure;

imshow(I2);

hold on;

plot(selectStrongest(blobs2, 30));

title('Thirty strongest SURF features in I2');

[features1, validBlobs1] = extractFeatures(I1, blobs1);

[features2, validBlobs2] = extractFeatures(I2, blobs2);

indexPairs = matchFeatures(features1, features2, 'Metric', 'SAD', ...

'MatchThreshold', 5);

matchedPoints1 = validBlobs1(indexPairs(:,1),:);

matchedPoints2 = validBlobs2(indexPairs(:,2),:);

figure;

showMatchedFeatures(I1, I2, matchedPoints1, matchedPoints2);

legend('Putatively matched points in I1', 'Putatively matched points in I2');

[fMatrix, epipolarInliers, status] = estimateFundamentalMatrix(...

matchedPoints1, matchedPoints2, 'Method', 'RANSAC', ...

'NumTrials', 10000, 'DistanceThreshold', 0.1, 'Confidence', 99.99);

if status ~= 0 || isEpipoleInImage(fMatrix, size(I1)) ...

|| isEpipoleInImage(fMatrix', size(I2))

error(['Either not enough matching points were found or '...

'the epipoles are inside the images. You may need to '...

'inspect and improve the quality of detected features ',...

'and/or improve the quality of your images.']);

end

inlierPoints1 = matchedPoints1(epipolarInliers, :);

inlierPoints2 = matchedPoints2(epipolarInliers, :);

figure;

showMatchedFeatures(I1, I2, inlierPoints1, inlierPoints2);

legend('Inlier points in I1', 'Inlier points in I2');

[t1, t2] = estimateUncalibratedRectification(fMatrix, ...

inlierPoints1.Location, inlierPoints2.Location, size(I2));

tform1 = projective2d(t1);

tform2 = projective2d(t2);

I1Rect = imwarp(I1, tform1, 'OutputView', imref2d(size(I1)));

I2Rect = imwarp(I2, tform2, 'OutputView', imref2d(size(I2)));

% transform the points to visualize them together with the rectified images

pts1Rect = transformPointsForward(tform1, inlierPoints1.Location);

pts2Rect = transformPointsForward(tform2, inlierPoints2.Location);

figure;

showMatchedFeatures(I1Rect, I2Rect, pts1Rect, pts2Rect);

legend('Inlier points in rectified I1', 'Inlier points in rectified I2');

Irectified = cvexTransformImagePair(I1, tform1, I2, tform2);

figure;

imshow(Irectified);

title('Rectified Stereo Images (Red - Left Image, Cyan - Right Image)');

cvexRectifyImages('left1.jpg', 'right1.jpg');

กดrun

top related