Matlab 58170042 (1)

Post on 22-Jan-2017

122 views 1 download

transcript

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_pro\LS5\B40.TIF')); G = histeq(imread('D:\Com_pro\LS5\B50.TIF')); B = histeq(imread('D:\Com_pro\LS5\B30.TIF'));

RGB = cat(3,R,G,B); figure,imshow(RGB);

กด run และ save จากนนคลก change folder

จะได