22
การใช้โปรแกรมMATLAP โปรแกรมนี ้จะง่ายกว่าการเขียนภาษา C เนื่องจากไม่ต้องเขียนโค้ดหลายๆบรรทัด เขียนคาสั่งได้เลย , คือ การแบ่งตัวเลขออกจากกัน ถ้าไม่ใส่ , โปรแกรมจะเข้าใจว่าเป็นเลขตัวเดียวกัน ; คือ คาสังให้ขึ ้นบรรทัดใหม่ ถ้าเขียนโค้ดผิด แต่ enter ไปแล้วจะไม่สามารถแก้ไขได้อีก ให้เขียนโค้ดใหม่ขึ ้นมา แทนได้เลย

โปรแกรม Matlap

Embed Size (px)

Citation preview

Page 1: โปรแกรม Matlap

การใชโปรแกรมMATLAP โปรแกรมนจะงายกวาการเขยนภาษา C เนองจากไมตองเขยนโคดหลายๆบรรทด

เขยนค าสงไดเลย

, คอ การแบงตวเลขออกจากกน ถาไมใส , โปรแกรมจะเขาใจวาเปนเลขตวเดยวกน

; คอ ค าสงใหขนบรรทดใหม

ถาเขยนโคดผด แต enter ไปแลวจะไมสามารถแกไขไดอก ใหเขยนโคดใหมขนมา

แทนไดเลย

Page 2: โปรแกรม Matlap

การนบแบบเรยงคา

คาเรมตน : คาสดทาย

คาเรมตน : นบทละเทาไร : คาสดทาย

การ plot graph

การ plot กราฟ

กราฟนใชคา x = 0 3 6 9 12 15 18 ตามทเคยก าหนดไว

Page 3: โปรแกรม Matlap

ก าหนดคา x เพอใหกราฟมความแตกตางอยาเหนไดชด

Page 4: โปรแกรม Matlap

การเปลยนลกษณะกราฟ

Plot (x, ‘ส เสน ลกษณะพกด’)

1.Plot (x, ‘--bs’) 2. Plot (x, ‘b--o’)

3. Plot (x, ‘c*’) 4. Plot (x, ‘c--*’) 6. Plot (x, ‘y--*’)

Page 5: โปรแกรม Matlap

การท าเครองคดเลข

เลอก Push Button เพอสรางชองส าหรบแสดง

ผลลพธและชองส าหรบปมเครองคดเลข

ส าหรบเปลยนสพนหลง ตงชอกรอบ และแกไขกรอบ

Page 6: โปรแกรม Matlap

สราง 4 แถว 5 คอลม

เลอก Push Button เพอสรางปมตวเลขและ

เครองหมาย

Page 7: โปรแกรม Matlap

*ท าแบบนทงตวเลขและเครองหมาย

ใส 0 ตรง String

ใส zero ตรง Text box

Page 8: โปรแกรม Matlap

พมพ code เพอใหเลขปรากฏในชอง input

str=get(handles.input,'String'); str=strcat(str,'0'); set(handles.input,'String',str);

คลกขวาทชองตวเลข เลอก View Callbacks

เลอก Callback เพอทจะเขยน code ใหเลข

หรอเครองหมายนนสามารถใชงานได

Page 9: โปรแกรม Matlap

กด Run เพอทดสอบวากดเลข 0 แลวจะแสดงในชองinputหรอไม ถาเลข 0 สามารถ

แสดงในชอง input กใหท าการ

Coppy code อนเดมแลวเปลยนจากเลข “0” เปนเลขอนๆของแตละฟงกชน ท าไป

เรอยๆ ตงแต 0-9 และเครองหมาย - + X / แลวท าการทดสอบอกครงเพอดวาตวเลข

สามารถใชงานไดทกตวหรอไม

Page 10: โปรแกรม Matlap

พมพ code เพอใชฟงกชน +/- str=get(handles.input,'String'); s=str2double(str); e=-(s); t=num2str(e); set(handles.input,'String',t);

พมพ codeเพอใชฟงชนสแควรท str=get(handles.input,'String'); s=str2double(str); sqr=sqrt(s); t=num2str(sqr); set(handles.result,'String',t);

พมพ code เพอใชฟงชน % str=get(handles.input,'String'); s=str2double(str); per=s/100; t=num2str(per); set(handles.result,'String',t);

พมพ code เพอใชฟงชน 1/X str=get(handles.input,'String'); s=str2double(str); div=(1/s); t=num2str(div); set(handles.result,'String',t);

พมพ code เพอใชฟงชนผลลพธ str=get(handles.input,'String'); str=evel(str); set(handles.result,'String',str); str=get(handles.input,'String'); str=eval(str,'.'); set(handles.result,'String',str);

Page 11: โปรแกรม Matlap

การเรยกภาพ

เปด browse for folder เพอเปดไฟลภาพ

เรยกไฟลภาพโดย imread (ชอไฟล ทอยของภาพในไดเรกทอร) กรณทเปดทอยของ

ไฟลแลว พมพแตชอไฟล

ตวเลขทงหมดคอสตางๆ

ในภาพ

บอกใหทราบวาเปน

ภาพส

Page 12: โปรแกรม Matlap

figure,imshow(I) คอฟงกชนใหแสดงภาพ

Figure คอ พนทส าหรบเรยกภาพ , กราฟ

I คอ ชอภาพทไดถกก าหนดขน

การเปลยนภาพสเปนสเทา

Ggray = rgb2gray(I)

Page 13: โปรแกรม Matlap

Imhist คอฟงกชนบอกคากราฟ

กราฟทเหนในภาพคอจ านวนพกเซล

Im2bw การท าภาพขาวด า

Page 14: โปรแกรม Matlap

การท าตารางเมตรกซ

**จ านวนเลขตองเทากน คาตวเลขตางกนได**

Image คอบอกคาส

Colorbar แสดงเฉดส

ตารางเมตรกซ

Page 15: โปรแกรม Matlap

การเรยกกลอง webcam

Imaqtool เรยกกลองเวบแคม

เลอก Start priview

Page 16: โปรแกรม Matlap

การท าภาพ 3มต

เปดภาพ กด seract แลวกด crop ภาพทางซาย แลวกด ctrl z เพอกลบมาท าขางขวา

ใช new script คอการเขยนค าสงทเดยว

ค าสงเปลยนภาพสเปนเทา

L1 = rgb2gray(imread('left.jpg')); L2 = rgb2gray(imread('right.jpg'));

Page 17: โปรแกรม Matlap

เปลยนภาพเทา เปน แดง-ฟาออน

ตรงไตเตล จะพมพตวเลกหรอตวพมพใหญกได

hold on; ใหภาพอยในเฟลมเดยวกน

Page 18: โปรแกรม Matlap

Code การเขยนภาพ 3 มต

I1 = rgb2gray(imread('Lion1.jpg')); I2 = rgb2gray(imread('Lion2.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;

Page 19: โปรแกรม Matlap

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 '...

Page 20: โปรแกรม Matlap

'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);

Page 21: โปรแกรม Matlap

figure; imshow(Irectified); title('Rectified Stereo Images (Red - Left Image, Cyan - Right Image)'); cvexRectifyImages('left.jpg', 'right.jpg');

การเปลยนสภาพเปน RGB (สจากแมส 3 ส คอสแดง สเขยว และส

น าเงน)

ใช imread ในการเรยกภาพ โดยพมพ imread ตามดวยชอภาพและ

นามสกลของภาพ เชน imread(‘B40.TIP’) ภาพจะปรากฏขนดงรป

Page 22: โปรแกรม Matlap

ใชค าสง imshow ท าการเปลยนแมแบบสใหเปน RGB

ใชcode NIR = histeq(imread('B40.TIF')); G = histeq(imread('B50.TIP')); R = histeq(imread ('B40.TIP')); RGB = cat(3,NIR,G.R); figure,imshow(RGB); เมอกด F5 ภาพจะเปลยนเปนเหมอนภาพดานบน