นางสาวปิยวรรณ ซอยรัมย์ รหัสนิสิต 58670034 กลุ่ม 3302
โปรแกรม MATLAB
หน้าตาของโปรแกรม MATLAB
เรื่อง DEM
ขั้นตอนต่อไป กด add folder เพื่อเอางานในไฟล์ จากนั้นกด save
จากนั้นกด เพื่อเลือกไฟล์ DEM
จากนั้นใส่ตัวแปร คาว่า DEM = GRIDobj('kidchakood.tif') แล้วกด Enter แล้วพิมคาว่า imagesc(DEM)
แล้วกด Enter จะรูปออกมาเป็นแบบข้างล่าง
รูปที่ได้จากการใส่ตัวข้างบน
จากนั้นเราอยากเห็นกราฟที่เป็น hill shade แล้วก็พิมพ์คาว่าimageschs(DEM,min(gradient8(DEM),1))แล้ว
กด Enter จะรูปออกมาเป็นแบบข้างล่าง
Plot (กราฟ)
ประกาศตัวแปร x y
สร้างกราฟ
กด Enter แสดงผลได้ดังนี้
ใสชื่อกราฟได้โดยใช้คาสั่ง Title
*ไม่ต้องปิดหน้าจอที่เป็นกราฟ แค่พับลง จะได้แสดงผลได้ดังนี้
ประกาศชื่อแกน x ใช้ xlabel (‘classroom’) กด Enter จะได้ผลดังนี้
ประกาศชื่อแกน y ใช้ ylabel (‘score’) กด Enter จะได้ผลดังนี้
สามารถเปลี่ยนสีกราฟเส้นได้โดยใช้คาสั่ง plot (x,y,’red’)
ทากราฟเป็นเส้นประ
ทากราฟเป็นจุดไข่ปลา
เปลี่ยนจุดตัดเป็นสัญลักษณ์อื่น ยกตัวอย่างเช่น วงกลม
แล้วยังเปลี่ยนสีได้อีก
RGB triplet คือ แม่สีหลัก
[ 0 0 0 ]
R G B เป็น 0 หมดคือสีดา
[ 1 1 1 ]
R G B เป็น 1 คือสีขาว
ถ้าอยากทาให้เป็นสีชมพูต้องนาสีแดงผสมกับสีขาว จะได้
[0.2 1 1]
R G B
ใส่คาอธิบายสัญลักษณ์ ใช้คาสั่ง legend('score of classroom')
สามารถเปลี่ยนตาแหน่งคาอธิบายสัญลักษณ์ไม่ให้บังกราฟได้ โดยใช้คาสั่ง
หรือสามารถกดที่ลูกศร แล้วย้ายได้เลย
กราฟ 3เส้น
ประกาศตัวแปร ดังนี้
plot กราฟ ใส่สี ใส่สัญลักษณ์ ได้ดังนี้
ใส่ชื่อของกราฟทั้ง3เส้น
ย้ายตาแหน่ง เพื่อไม่ให้บังเส้นกราฟ
การแสดงกราฟย่อย
ใช้คาสั่ง subplot รูปแบบของ subplot(m,n,p) m คือ แถว n คือ คอลัม p คือจานวน
plotกราฟ
กราฟ 3 มิติ
เราจะให้กราฟเป็น 3มิติ ให้เราพิมพ์คาว่าลงไปในโปรแกรม DEMc = crop(DEM,sub2ind(DEM.size,[150
350],[150 350])); )) แล้วกด Enter
จากนั้นพิมพ์ เพื่อให้อยู่ในรูปของตัวเลข[Z,x,y] = GRIDobj2mat(DEMc); แล้วกด Enterแล้วพิมพ์คานี้ต่อ
surf(x,y,double(Z)) เราก็จะได้รูปเป็น 3ติ แล้วเหมือนรูปข้างล่างค่ะ
รูป 3มิติที่เราใส่ตัวแปรลงไป
ถ้าเราอยากรู้ความสูงของยอดเขาแล้วสามารถไปกดได้ที่ Data cursor แล้วเอาเมาส์ไปกดได้ที่ยอดเขาเราก็จะ
รู้ความสูงของเขา
การทาการไหลของนา
การทาการไหลของน้า เราอย่าลืมคานี้ DEMf = fillsinks(DEM); เพราะว่าถ้าลืมจะเกิดร่องน้าแล้วพิมพ์คานี้
ต่อ
FD = FLOWobj(DEMf);
A = flowacc(FD);
imageschs(DEM,dilate(sqrt(A),ones(5)),'colormap',flipud(copper)); จากนั้นกด Enter จะได้รูปข้างล่าง
การใช้ drainagebasins
เราพิมพ์ DB = drainagebasins(FD);
DB = shufflelabel(DB);
nrDB = numel(unique(DB.Z(:)))-1; % nr of drainage basins
STATS = regionprops(DB.Z,'PixelIdxList','Area','Centroid');
imageschs(DEM,DB);
hold on
for run = 1:nrDB;
if STATS(run).Area*DB.cellsize^2 > 10e6;
[x,y] = ind2coord(DB,...
sub2ind(DB.size,...
round(STATS(run).Centroid(2)),...
round(STATS(run).Centroid(1))));
text(x,y,...
num2str(round(STATS(run).Area * DB.cellsize^2/1e6)),...
'BackgroundColor',[1 1 1]);
end
end
hold off
title('drainage basins (numbers refer to drainage basin area in km^2)') แล้วกด Enter จะได้ตามรูปข้างล่าง
เรื่อง web cam
พิมพ์คาว่า imaqtool แล้วก็จะขึ้นหน้า แล้วเราก็กดตรงด้านซ้ายแล้วไปกด ตรง preview แล้วจะขึ้นกล้องตาม
รูปด้านล่าง
หลังจากนั้นก็อบปี้ vid = videoinput('winvideo', 1, 'MJPG_1280x720'); ด้านขวามือ คือการเรียกรหัสเข้า
กล้อง
แล้วจากนั้นก็คลิกขวาวาง ลงในหน้าต่างที่ขึ้นมา
เรื่อง Image proaessive
พิมพ์คาว่า color imread แล้วกด enter แล้วจะขึ้นหน้าต่างตัวเลขมากมายเพราะว่ารูปมีขนาดใหญ่เกิน รอจน
ตัวเลขอยู่วิ่งหลังจากนั้นก็ พิมพ์ คาว่า whos color กด enter
นี้คือภาพที่ตัวเลขวิ่ง
แล้วหลังจากที่ตัวเลขวิ่งจนหยุดแล้วให้เรากด Enter และพิมพ์คาว่า figure,imshow(color) กด enter ก็จะขึ้น
รูปภาพที่เราเลือกไว้นั้นเอง
การแปลภาพสีเป็นสีเทา
กด Enterลงมาอีกบรรทัดหนึ่งและพิมพ์ figure,imshow(gray) และรูปภาพก็จะขึ้นรูปเป็นสีเทา
ตามที่เห็น
การแสดงกราฟเชิงคลื่น
ถ้าเราอยากดูกราฟของสีในภาพหรือเรียกว่า การแสดงกราฟเชิงคลื่นให้เราพิมพ์ ว่า figure,imhist(gray)แล้ว
จะขึ้นตามภาพนี้
การทารูปภาพเป็นขาวดา
การทาให้เป็นขาวดาพิมพ์คาว่า figure,imshow(BW) แล้วก็ขึ้นตามภาพ
และถ้าเราจะเรียกดูภาพที่สอง ให้พิมพ์คาว่า monkey imread และกด Enter แล้วพิมพ์
figure,imshow(monkey) แล้วกดก็จะขึ้นตามรูปภาพ
แล้วเราอยากดูกราฟของสีในภาพให้พิมพ์คาว่า figure,imhist(monkey) ก็จะขึ้นตามรูปภาพ
การแสดง สีให้พิมพ์ว่า image(C)
เรื่อง guide
พิมพ์ว่า guideแล้วเลือก Bank กด OK ภาพก็จะขึ้นตามภาพข้างล่าง
นี้คือรูปที่ได้จากคาสั่งข้างบน
และไปที่ ไฟล์ แล้วกด preferences แล้วกด โชว์เนม แล้วไปกดที่ Axes เอาเมาส์ไปลากไว้ที่ หน้าจอก็จะขึ้น
ตามรูป
หลังจากนั้นก็ไปกดที่ Push Button แล้วเอาเมาส์ไปลากวางไว้ที่หน้าตามภาพเพื่อ ในการใช้งานจะสามารถ
คลิกปุ่มนี้ได้
เรื่อง ภาพ 3D
จะแยกภาพออกจากกัน คือ pic 1 กับ pic 2 โดยโปรแกรม paint.
วางรูปแล้ว เลือก select แล้ว crop รูปฝั่งซ้ายมือ
Crop รูปเสร็จเรียบร้อยแล้วกด save as ต้อง save เป็นไฟล์ JPEG picture
จากนั้นทาแบบเดิมกับภาพที่ 2
จากนั้นกด save as เหมือนเดิม
การ Set ไฟล์ภาพ
กด “ Browse for folder ” เลือกไฟล์ 3D แต่ไม่ต้องเข้าไปในโฟลเดอร์ แล้วกด select
เสร็จแล้วกด New Script
โค้ดการทาภาพ 3D
I1 = rgb2gray(imread('pic1.jpg'));
I2 = rgb2gray(imread('pic2.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('lions_left.jpg', 'lion_right.jpg');
จากนั้นก็กด Run ภาพก็จะปรากฏขึ้นมาซ้อนๆกัน เป็นขั้นตอนว่าทายังไง
เปิด figure 8 ให้เปิดรูปใหญ่แล้วใส่แว่น 3D ได้เลยยยย

ปิยวรรณ