SlideShare a Scribd company logo
1 of 24
Download to read offline
COMPUTER PROGRAMMING
MATLAB
เสนอ
อาจารย์กฤษณะ อิ่มสวาสดิ์
จัดทาโดย
นางสาวโสภิตา ทองสร้าง 58170042 กลุ่ม 01
นิสิตชั้นปีที่ 1 ปีการศึกษา 2558
คณะภูมิสารสนเทศศาสตร์
มหาวิทยาลัยบูรพา
แมตแล็บ (อังกฤษ: MATLAB: Matrix Laboratory) เป็นซอฟต์แวร์ในการคานวณและการเขียน
โปรแกรม โปรแกรมหนึ่ง ที่มีความสามารถครอบคลุมตั้งแต่ การพัฒนาอัลกอริธึม การสร้างแบบจาลองทาง
คณิตศาสตร์ และการทาซิมูเลชั่นของระบบ การสร้างระบบควบคุม และโดยเฉพาะเรื่อง image processing
และ wavelet การสร้างเมตริกซ์ ผลิตโดยบริษัทแมตเวิรกส์ ตัวแทนจาหน่ายในประเทศไทยคือ บริษัท เทค
ซอร์ส ซิสเท็มส์ (ประเทศไทย) จากัด
แมตแล็บเป็นโปรแกรมสาเร็จรูปที่ใช้กันอย่างแพร่หลายในแวดวงของนักวิทยาศาสตร์และ วิศวกร
ในปัจจุบัน ชื่อโปรแกรม MATLAB นั้นย่อมาจาก Matrix Laboratory แมตแล็บได้เริ่มต้น ขึ้นเพื่อต้องการให้
เราสามารถแก้ปัญหาตัวแปรที่มีลักษณะเป็นเมทริดซ์ได้ง่ายขึ้น แมตแล็บ เริ่มพัฒนาครั้งแรกโดย Dr. Cleve
Molor ซึ่งเขียนโปรแกรมนี้ขึ้นมาด้วยภาษาฟอร์แทรน โดยโปรแกรมนี้ได้พัฒนาภายใต้โครงการ LINPACK
และ EISPACK
การทางานของโปรแกรม
แมตแล็บสามารถทางานได้ทั้งในลักษณะของการติดต่อโดยตรง คือการเขียนคาสั่งเข้าไปทีละคาสั่ง
เพื่อให้แมตแล็บประมวลผลไปเรื่อยๆ หรือสามารถที่จะรวบรวม ชุดคาสั่งเรานั้นเป็นโปรแกรมก็ได้ข้อ
สาคัญอย่างหนึ่งของแมตแล็บก็คือข้อมูลทุกตัวจะถูกเก็บใน ลักษณะของแถวลาดับ คือในแต่ละตัวแปรจะ
ได้รับการแบ่งเป็นส่วนย่อยเล็กๆขึ้น ซึ่งการใช้ตัวแปรเป็นแถวลาดับ ในแมตแล็บเราไม่จาเป็นที่จะต้องจอง
มิติเหมือนกับ การเขียนโปรแกรมในภาษาขั้นต่าทั่วไป ซึ่งทาให้เราสามารถที่จะแก้ปัญหาของตัวแปรที่อยู่ใน
ลักษณะ ของเมทริกซ์และเวกเตอร์ได้โดยง่าย ซึ่งทาให้เราลดเวลาการทางานลงได้อย่างมากเมื่อเทียบกับการ
เขียน โปรแกรมโดยภาษาซีหรือภาษาฟอร์แทรน
การสร้าง plot กราฟแบบสามมิติ
ป้อนคาสั่งต่อไปนี้ลงใน command line
>> plot(a)
>> x = [-3:1:3];
>> y = [-3:1:3];
>> [xx,yy] = meshgrid(x,y);
>> zz = xx.^2 - yy.^2;
>> figure
>> surf(xx,yy,zz)
>> plot(a)
>> x = [-3:1:3];
>> y = [-3:1:3];
>> [xx,yy] = meshgrid(x,y);
>> zz = xx.^2 - yy.^2;
>> figure
>> surf(xx,yy,zz)
>> shading interp
>> colorbar
Image Progressing
1.วิธีโหลดไฟล์ภาพเข้าโปรแกรม
ใช้คาสั่ง a = imread(‘ชื่อไฟล์รูปภาพ.jpg’) กด enter
2.คาสั่งเปิดไฟล์ภาพ (สี)
ใช้คาสั่ง figure,imshow(…..ชื่อตัวแปรที่กาหนด…)
3.คาสั่งแปลงสีภาพให้เป็นสีเทา
กาหนดตัวแปร g = rgb2gray
4.ดูกราฟฮิสโตแกรมของภาพ
ใช้คาสั่ง Imhist(g)
5.คาสั่งปรับแก้ภาพ ทาให้ภาพชัดขึ้น
ใช้คาสั่ง ad = imadjust(b)
Figure,imshow(ad)
การทา 3D stereo
1ตัดรูป 3d stereo แบ่งออก ซ้าย-ขวา
Browse เอานารูปที่ตัดแล้วเข้ามา
ใส่โค้ดใน command line
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 จะแสดงผลเป็นภาพ 3D
Guide
1.พิมพ์ guide แล้ว Enter จะมีกล่องข้อความแสดงขึ้นมา
2.เลือก bank gui จะได้แบบนี้
หากชื่อเครื่องมือด้ายซ้ายมือไม่มี ให้คลิกที่ไฟล์เลือก preferences.. ติ้กเลือก show name in component
สร้างปุ่มโดยใช้ push button
เลือก axes
เปลี่ยนชื่อและตกแต่งปุ่ม
ใส่ tag เพื่อใช้ในการคีย์โค้ด
ออกแบบได้ตามต้องการ
ใส่โค้ด
Save
หลังจาก save จะได้โค้ดแบบนี้
แล้ว copy โค้ดข้างล่างนี้
global x
[filename, pathname] = uigetfile('*.jpg','Load Image');
if filename==0
msgbox('Please Choose Image','Error')
return
end
x=imread(filename);
axes(handles.axes1);
imshow(x); title('Loaded Image');
ไปวางในบรรทัดที่ 81
แล้ว copy โค้ดนี้ไปใส่ในบรรทัดที่ 57
set(handles.axes1,'Visible','off');
จากนั้นคลิกที่ปุ่ม gray ทาเหมือนข้างบน copy โค้ดด้านล่างไปใส่ในบรรทัดที่ 97
global x
a=rgb2gray(x)
axes(handles.axes1);
imshow(a); title('Gray scale');
จากนั้นคลิกที่ปุ่ม his ทาเหมือนข้างบน copy โค้ดด้านล่างไปใส่ในบรรทัดที่ 107
global x
c=rgb2gray(x)
imhist(c);
axes(handles.axes1);
จากนั้นคลิกที่ปุ่ม BW ทาเหมือนข้างบน copy โค้ดด้านล่างไปใส่ในบรรทัดที่ 117
global x
c=rgb2gray(x)
imhist(c);
axes(handles.axes1);
จากนั้นคลิกที่ปุ่ม reset ทาเหมือนข้างบน copy โค้ดด้านล่างไปใส่ในบรรทัดที่ 117
global x
axes(handles.axes1);
imshow(x);
จากนั้นกด run แล้วเลือก change folder
จะได้ดังนี้
จากนั้นกลับไปที่หน้าหลัก กด save
จากนั้นกลับมาหน้านี้
กด run และอัพโหลดรูปภาพ จากนั้นลองกด gray
การผสมสีภาพ browse folder
Select Folder
กด new script และวางโค้ด
R = histeq(imread('D:Com_proLS5B40.TIF'));
G = histeq(imread('D:Com_proLS5B50.TIF'));
B = histeq(imread('D:Com_proLS5B30.TIF'));
RGB = cat(3,R,G,B);
figure,imshow(RGB);
กด run และ save จากนั้นคลิก change folder
จะได้

More Related Content

Viewers also liked (8)

Power supply designed by amani james
Power supply  designed by amani  jamesPower supply  designed by amani  james
Power supply designed by amani james
 
58170038
5817003858170038
58170038
 
Mayeutica dialectica
Mayeutica dialecticaMayeutica dialectica
Mayeutica dialectica
 
Stredná Ázia
Stredná ÁziaStredná Ázia
Stredná Ázia
 
Južná Ázia
Južná ÁziaJužná Ázia
Južná Ázia
 
Clearafin ppt copy
Clearafin ppt copyClearafin ppt copy
Clearafin ppt copy
 
Reseña histórica une
Reseña histórica uneReseña histórica une
Reseña histórica une
 
7 чудес мира
7 чудес мира7 чудес мира
7 чудес мира
 

Similar to Matlab 58170042 (1)

น.ส.ลลิตภัทร สงวนผิว 58670381 กลุ่ม3302
น.ส.ลลิตภัทร สงวนผิว 58670381 กลุ่ม3302น.ส.ลลิตภัทร สงวนผิว 58670381 กลุ่ม3302
น.ส.ลลิตภัทร สงวนผิว 58670381 กลุ่ม3302Nawarat Sornchai
 
สุมิตรา
สุมิตราสุมิตรา
สุมิตราFirstii Romeo
 
ปิยวรรณ
ปิยวรรณปิยวรรณ
ปิยวรรณFirstii Romeo
 

Similar to Matlab 58170042 (1) (6)

น.ส.ลลิตภัทร สงวนผิว 58670381 กลุ่ม3302
น.ส.ลลิตภัทร สงวนผิว 58670381 กลุ่ม3302น.ส.ลลิตภัทร สงวนผิว 58670381 กลุ่ม3302
น.ส.ลลิตภัทร สงวนผิว 58670381 กลุ่ม3302
 
สุมิตรา
สุมิตราสุมิตรา
สุมิตรา
 
Mat lab2
Mat lab2Mat lab2
Mat lab2
 
ปิยวรรณ
ปิยวรรณปิยวรรณ
ปิยวรรณ
 
58170110 01
58170110 0158170110 01
58170110 01
 
Matlab
MatlabMatlab
Matlab
 

More from Beer Srisudaporn

More from Beer Srisudaporn (14)

นางสาวรัตน์ชนก นาทองลาย
นางสาวรัตน์ชนก   นาทองลายนางสาวรัตน์ชนก   นาทองลาย
นางสาวรัตน์ชนก นาทองลาย
 
นางสาวศรีสุดาพร คำอ้าย
นางสาวศรีสุดาพร   คำอ้ายนางสาวศรีสุดาพร   คำอ้าย
นางสาวศรีสุดาพร คำอ้าย
 
นางสาวสุดารัตน์ เนตรวงค์
นางสาวสุดารัตน์   เนตรวงค์นางสาวสุดารัตน์   เนตรวงค์
นางสาวสุดารัตน์ เนตรวงค์
 
นางสาวฐิติมาพร ขจรฟุ้ง
นางสาวฐิติมาพร ขจรฟุ้งนางสาวฐิติมาพร ขจรฟุ้ง
นางสาวฐิติมาพร ขจรฟุ้ง
 
Merged document 4
Merged document 4Merged document 4
Merged document 4
 
Merged document 3
Merged document 3Merged document 3
Merged document 3
 
Merged document
Merged documentMerged document
Merged document
 
Lab5
Lab5Lab5
Lab5
 
Lab4
Lab4Lab4
Lab4
 
Lab3
Lab3Lab3
Lab3
 
Lab2
Lab2Lab2
Lab2
 
Lab1
Lab1Lab1
Lab1
 
Lab1
Lab1Lab1
Lab1
 
Matrabเจน
MatrabเจนMatrabเจน
Matrabเจน
 

Matlab 58170042 (1)

  • 1. COMPUTER PROGRAMMING MATLAB เสนอ อาจารย์กฤษณะ อิ่มสวาสดิ์ จัดทาโดย นางสาวโสภิตา ทองสร้าง 58170042 กลุ่ม 01 นิสิตชั้นปีที่ 1 ปีการศึกษา 2558 คณะภูมิสารสนเทศศาสตร์ มหาวิทยาลัยบูรพา
  • 2. แมตแล็บ (อังกฤษ: MATLAB: Matrix Laboratory) เป็นซอฟต์แวร์ในการคานวณและการเขียน โปรแกรม โปรแกรมหนึ่ง ที่มีความสามารถครอบคลุมตั้งแต่ การพัฒนาอัลกอริธึม การสร้างแบบจาลองทาง คณิตศาสตร์ และการทาซิมูเลชั่นของระบบ การสร้างระบบควบคุม และโดยเฉพาะเรื่อง image processing และ wavelet การสร้างเมตริกซ์ ผลิตโดยบริษัทแมตเวิรกส์ ตัวแทนจาหน่ายในประเทศไทยคือ บริษัท เทค ซอร์ส ซิสเท็มส์ (ประเทศไทย) จากัด แมตแล็บเป็นโปรแกรมสาเร็จรูปที่ใช้กันอย่างแพร่หลายในแวดวงของนักวิทยาศาสตร์และ วิศวกร ในปัจจุบัน ชื่อโปรแกรม MATLAB นั้นย่อมาจาก Matrix Laboratory แมตแล็บได้เริ่มต้น ขึ้นเพื่อต้องการให้ เราสามารถแก้ปัญหาตัวแปรที่มีลักษณะเป็นเมทริดซ์ได้ง่ายขึ้น แมตแล็บ เริ่มพัฒนาครั้งแรกโดย Dr. Cleve Molor ซึ่งเขียนโปรแกรมนี้ขึ้นมาด้วยภาษาฟอร์แทรน โดยโปรแกรมนี้ได้พัฒนาภายใต้โครงการ LINPACK และ EISPACK การทางานของโปรแกรม แมตแล็บสามารถทางานได้ทั้งในลักษณะของการติดต่อโดยตรง คือการเขียนคาสั่งเข้าไปทีละคาสั่ง เพื่อให้แมตแล็บประมวลผลไปเรื่อยๆ หรือสามารถที่จะรวบรวม ชุดคาสั่งเรานั้นเป็นโปรแกรมก็ได้ข้อ สาคัญอย่างหนึ่งของแมตแล็บก็คือข้อมูลทุกตัวจะถูกเก็บใน ลักษณะของแถวลาดับ คือในแต่ละตัวแปรจะ ได้รับการแบ่งเป็นส่วนย่อยเล็กๆขึ้น ซึ่งการใช้ตัวแปรเป็นแถวลาดับ ในแมตแล็บเราไม่จาเป็นที่จะต้องจอง มิติเหมือนกับ การเขียนโปรแกรมในภาษาขั้นต่าทั่วไป ซึ่งทาให้เราสามารถที่จะแก้ปัญหาของตัวแปรที่อยู่ใน ลักษณะ ของเมทริกซ์และเวกเตอร์ได้โดยง่าย ซึ่งทาให้เราลดเวลาการทางานลงได้อย่างมากเมื่อเทียบกับการ เขียน โปรแกรมโดยภาษาซีหรือภาษาฟอร์แทรน
  • 3. การสร้าง plot กราฟแบบสามมิติ ป้อนคาสั่งต่อไปนี้ลงใน command line >> plot(a) >> x = [-3:1:3]; >> y = [-3:1:3]; >> [xx,yy] = meshgrid(x,y); >> zz = xx.^2 - yy.^2; >> figure >> surf(xx,yy,zz)
  • 4. >> plot(a) >> x = [-3:1:3]; >> y = [-3:1:3]; >> [xx,yy] = meshgrid(x,y); >> zz = xx.^2 - yy.^2; >> figure >> surf(xx,yy,zz) >> shading interp >> colorbar
  • 5. Image Progressing 1.วิธีโหลดไฟล์ภาพเข้าโปรแกรม ใช้คาสั่ง a = imread(‘ชื่อไฟล์รูปภาพ.jpg’) กด enter 2.คาสั่งเปิดไฟล์ภาพ (สี) ใช้คาสั่ง figure,imshow(…..ชื่อตัวแปรที่กาหนด…) 3.คาสั่งแปลงสีภาพให้เป็นสีเทา กาหนดตัวแปร g = rgb2gray
  • 7. การทา 3D stereo 1ตัดรูป 3d stereo แบ่งออก ซ้าย-ขวา Browse เอานารูปที่ตัดแล้วเข้ามา ใส่โค้ดใน command line 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;
  • 8. 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 จะแสดงผลเป็นภาพ 3D
  • 9.
  • 10. Guide 1.พิมพ์ guide แล้ว Enter จะมีกล่องข้อความแสดงขึ้นมา 2.เลือก bank gui จะได้แบบนี้
  • 11. หากชื่อเครื่องมือด้ายซ้ายมือไม่มี ให้คลิกที่ไฟล์เลือก preferences.. ติ้กเลือก show name in component สร้างปุ่มโดยใช้ push button เลือก axes
  • 15. หลังจาก save จะได้โค้ดแบบนี้ แล้ว copy โค้ดข้างล่างนี้ global x [filename, pathname] = uigetfile('*.jpg','Load Image'); if filename==0 msgbox('Please Choose Image','Error') return end x=imread(filename); axes(handles.axes1); imshow(x); title('Loaded Image'); ไปวางในบรรทัดที่ 81
  • 16. แล้ว copy โค้ดนี้ไปใส่ในบรรทัดที่ 57 set(handles.axes1,'Visible','off'); จากนั้นคลิกที่ปุ่ม gray ทาเหมือนข้างบน copy โค้ดด้านล่างไปใส่ในบรรทัดที่ 97 global x a=rgb2gray(x)
  • 17. axes(handles.axes1); imshow(a); title('Gray scale'); จากนั้นคลิกที่ปุ่ม his ทาเหมือนข้างบน copy โค้ดด้านล่างไปใส่ในบรรทัดที่ 107 global x c=rgb2gray(x) imhist(c); axes(handles.axes1);
  • 18. จากนั้นคลิกที่ปุ่ม BW ทาเหมือนข้างบน copy โค้ดด้านล่างไปใส่ในบรรทัดที่ 117 global x c=rgb2gray(x) imhist(c); axes(handles.axes1); จากนั้นคลิกที่ปุ่ม reset ทาเหมือนข้างบน copy โค้ดด้านล่างไปใส่ในบรรทัดที่ 117 global x axes(handles.axes1); imshow(x);
  • 22. การผสมสีภาพ browse folder Select Folder กด new script และวางโค้ด R = histeq(imread('D:Com_proLS5B40.TIF')); G = histeq(imread('D:Com_proLS5B50.TIF')); B = histeq(imread('D:Com_proLS5B30.TIF'));
  • 23. RGB = cat(3,R,G,B); figure,imshow(RGB); กด run และ save จากนั้นคลิก change folder