View
291
Download
2
Category
Preview:
Citation preview
การใชโปรแกรมMATLAP โปรแกรมนจะงายกวาการเขยนภาษา C เนองจากไมตองเขยนโคดหลายๆบรรทด
เขยนค าสงไดเลย
, คอ การแบงตวเลขออกจากกน ถาไมใส , โปรแกรมจะเขาใจวาเปนเลขตวเดยวกน
; คอ ค าสงใหขนบรรทดใหม
ถาเขยนโคดผด แต enter ไปแลวจะไมสามารถแกไขไดอก ใหเขยนโคดใหมขนมา
แทนไดเลย
การนบแบบเรยงคา
คาเรมตน : คาสดทาย
คาเรมตน : นบทละเทาไร : คาสดทาย
การ plot graph
การ plot กราฟ
กราฟนใชคา x = 0 3 6 9 12 15 18 ตามทเคยก าหนดไว
ก าหนดคา x เพอใหกราฟมความแตกตางอยาเหนไดชด
การเปลยนลกษณะกราฟ
Plot (x, ‘ส เสน ลกษณะพกด’)
1.Plot (x, ‘--bs’) 2. Plot (x, ‘b--o’)
3. Plot (x, ‘c*’) 4. Plot (x, ‘c--*’) 6. Plot (x, ‘y--*’)
การท าเครองคดเลข
เลอก Push Button เพอสรางชองส าหรบแสดง
ผลลพธและชองส าหรบปมเครองคดเลข
ส าหรบเปลยนสพนหลง ตงชอกรอบ และแกไขกรอบ
สราง 4 แถว 5 คอลม
เลอก Push Button เพอสรางปมตวเลขและ
เครองหมาย
*ท าแบบนทงตวเลขและเครองหมาย
ใส 0 ตรง String
ใส zero ตรง Text box
พมพ code เพอใหเลขปรากฏในชอง input
str=get(handles.input,'String'); str=strcat(str,'0'); set(handles.input,'String',str);
คลกขวาทชองตวเลข เลอก View Callbacks
เลอก Callback เพอทจะเขยน code ใหเลข
หรอเครองหมายนนสามารถใชงานได
กด Run เพอทดสอบวากดเลข 0 แลวจะแสดงในชองinputหรอไม ถาเลข 0 สามารถ
แสดงในชอง input กใหท าการ
Coppy code อนเดมแลวเปลยนจากเลข “0” เปนเลขอนๆของแตละฟงกชน ท าไป
เรอยๆ ตงแต 0-9 และเครองหมาย - + X / แลวท าการทดสอบอกครงเพอดวาตวเลข
สามารถใชงานไดทกตวหรอไม
พมพ 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);
การเรยกภาพ
เปด browse for folder เพอเปดไฟลภาพ
เรยกไฟลภาพโดย imread (ชอไฟล ทอยของภาพในไดเรกทอร) กรณทเปดทอยของ
ไฟลแลว พมพแตชอไฟล
ตวเลขทงหมดคอสตางๆ
ในภาพ
บอกใหทราบวาเปน
ภาพส
figure,imshow(I) คอฟงกชนใหแสดงภาพ
Figure คอ พนทส าหรบเรยกภาพ , กราฟ
I คอ ชอภาพทไดถกก าหนดขน
การเปลยนภาพสเปนสเทา
Ggray = rgb2gray(I)
Imhist คอฟงกชนบอกคากราฟ
กราฟทเหนในภาพคอจ านวนพกเซล
Im2bw การท าภาพขาวด า
การท าตารางเมตรกซ
**จ านวนเลขตองเทากน คาตวเลขตางกนได**
Image คอบอกคาส
Colorbar แสดงเฉดส
ตารางเมตรกซ
การเรยกกลอง webcam
Imaqtool เรยกกลองเวบแคม
เลอก Start priview
การท าภาพ 3มต
เปดภาพ กด seract แลวกด crop ภาพทางซาย แลวกด ctrl z เพอกลบมาท าขางขวา
ใช new script คอการเขยนค าสงทเดยว
ค าสงเปลยนภาพสเปนเทา
L1 = rgb2gray(imread('left.jpg')); L2 = rgb2gray(imread('right.jpg'));
เปลยนภาพเทา เปน แดง-ฟาออน
ตรงไตเตล จะพมพตวเลกหรอตวพมพใหญกได
hold on; ใหภาพอยในเฟลมเดยวกน
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;
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('left.jpg', 'right.jpg');
การเปลยนสภาพเปน RGB (สจากแมส 3 ส คอสแดง สเขยว และส
น าเงน)
ใช imread ในการเรยกภาพ โดยพมพ imread ตามดวยชอภาพและ
นามสกลของภาพ เชน imread(‘B40.TIP’) ภาพจะปรากฏขนดงรป
ใชค าสง 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 ภาพจะเปลยนเปนเหมอนภาพดานบน
Recommended