SlideShare a Scribd company logo
1 of 13
Download to read offline
Lab 9
figure
figure อย่างเดียว จะไม่มีรูปขึ้น จะเป็นหน้าต่างสีเทา
การทาภาพให้เป็นสีเทา
ภาพที่ได้ออกมา
2 ภาพเมื่อเปรียบเทียบกัน
figure,imhist(gray) เรียกดูค่าการรังสีเชิงคลื่น
การแปลงเป็นขาว-ดา im2bw ( Black_White = im2bw(I))
figure,imshow(Black_White)
figure,imhist(Black_White)
ตารางเมตริก
เมื่อพิมพ์ colorbar จะมีแถบสีขึ้นด้านข้าง
เปิดภาพ กด seract แล้วกด crop
แล้วกด ctrl z เพื่อกลับมาทาข้างขวาอีกรอบ
ใช้ new script คือการเขียนคาสั่งทีเดียว
คาสั่งเปลี่ยนภาพสีเป็นเทา
L1 = rgb2gray(imread('left.jpg'));
L2 = rgb2gray(imread('right.jpg'));
เปลี่ยนภาพเทา เป็น แดง-ฟ้ าอ่อน
ตรงไตเติล จะพิมพ์ตัวเล็กหรือตัวพิมพ์ใหญ่ก็ได้
hold on;
ให้ภาพอยู่ในเฟลมเดียวกัน
%read image and transform gray
L1 = rgb2gray(imread('left.jpg'));
L2 = rgb2gray(imread('right.jpg'));
%part is showpair between left and right
imshowpair(L1,L2,'montage');
title('L1(left);L2(right)');
figure;
imshowpair(L1,L2,'ColorChannel','red-cyan');
title('Composite Image (Red - Left Image, Cyan - Right Image)');
blobs1 = detectSURFFeatures(L1,'MetricThreshold',2000);
blobs2 = detectSURFFeatures(L2,'MetricThreshold',2000);
figure;
imshow(L1);
hold on;
plot(selectStrongest(blobs1, 30));
title('Thirty strongest SURE features in L1');
figure;
imshow(L2);
hold on;
plot(selectStrongest(blobs2, 30));
title('Thirty strongest SURE features in L2');
[features1, validBlobs1] = extractFeatures(L1, blobs1);
[features1, validBlobs2] = extractFeatures(L2, blobs2);
indexPairs = matchFeatures(features1, features2, 'Metric',
'SAD','MatchThreshold', 5)
matchedPoints1 = validBlobs1(indexPairs(:,1),:);
matchedPoints2 = validBlobs2(indexPairs(:,2),:);
figure;
showMatchedFeatures(L1, L2, matchedPoints2);
legend('Putatively matched points in L1', 'Putatively matched points in L2');
[fMatrix, epipolarInliers, status] =
estimateFundamentalMatrix(matchedPoints1, matchedPoints2,'Method',
'RANSAC','NumTrials', 10000, 'DistanceThreshold', 0.1, 'Confidence', 99.99);
if status ~= 0 || is EpipoleInImage(fMatrix', size(L1))|| is
EpipoleInImage(fMatrix', size(L2))
erro(['Either not enought matching points were found']);
end
inlierPoints1 = matchedPoints1(epipolarInliers, :);
inlierPoints2 = matchedPoints2(epipolarInliers, :);
figure;
showMatchedFeatures(L1, L2, inlierPoints1, inlierPoints2);
legend('Inlier points in L1', 'Inlier points in L2');
[t1, t2] = estimateUncalibratedRectification(fMatrix, ...
inlierPoints1.Location, inlierPoints2.Location, size(L2));
tform1 = projective2d(t1);
tform2 = projective2d(t2);
I1Rect = imwarp(L1, tform1, 'OutputView', imref2d(size(L1)));
I2Rect = imwarp(L2, tform2, 'OutputView', imref2d(size(L2)));
% transform the points to visualize them together with the rectified images
pts1Rect = transformPointsForward(tform1, inlierPoints1.Location);
pts2Rect = transformPointsForward(tform2, inlierPoints2.Location);
figure;
showMatchedFeatures(L1Rect, L2Rect, pts1Rect, pts2Rect);
legend('Inlier points in rectified L1', 'Inlier points in rectified L2');
Irectified = cvexTransformImagePair(L1, tform1, L2, tform2);
figure;
imshow(Irectified);
title('Rectified Stereo Images (Red - Left Image, Cyan - Right Image)');
cvexRectifyImages('left.jpg', 'right.jpg');
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');

More Related Content

More from putthita

More from putthita (8)

Photoshop
PhotoshopPhotoshop
Photoshop
 
Photoshop
PhotoshopPhotoshop
Photoshop
 
Math กราฟ
Math กราฟMath กราฟ
Math กราฟ
 
Math กราฟ
Math กราฟMath กราฟ
Math กราฟ
 
Math กราฟ
Math กราฟMath กราฟ
Math กราฟ
 
Mathlab
MathlabMathlab
Mathlab
 
Math กราฟ
Math กราฟMath กราฟ
Math กราฟ
 
ภาษา C เบื้องต้น
ภาษา C เบื้องต้นภาษา C เบื้องต้น
ภาษา C เบื้องต้น
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

Mathlab

  • 2. figure อย่างเดียว จะไม่มีรูปขึ้น จะเป็นหน้าต่างสีเทา การทาภาพให้เป็นสีเทา
  • 7. เปิดภาพ กด seract แล้วกด crop แล้วกด ctrl z เพื่อกลับมาทาข้างขวาอีกรอบ ใช้ new script คือการเขียนคาสั่งทีเดียว
  • 8. คาสั่งเปลี่ยนภาพสีเป็นเทา L1 = rgb2gray(imread('left.jpg')); L2 = rgb2gray(imread('right.jpg')); เปลี่ยนภาพเทา เป็น แดง-ฟ้ าอ่อน ตรงไตเติล จะพิมพ์ตัวเล็กหรือตัวพิมพ์ใหญ่ก็ได้ hold on; ให้ภาพอยู่ในเฟลมเดียวกัน
  • 9. %read image and transform gray L1 = rgb2gray(imread('left.jpg')); L2 = rgb2gray(imread('right.jpg')); %part is showpair between left and right imshowpair(L1,L2,'montage'); title('L1(left);L2(right)'); figure;
  • 10. imshowpair(L1,L2,'ColorChannel','red-cyan'); title('Composite Image (Red - Left Image, Cyan - Right Image)'); blobs1 = detectSURFFeatures(L1,'MetricThreshold',2000); blobs2 = detectSURFFeatures(L2,'MetricThreshold',2000); figure; imshow(L1); hold on; plot(selectStrongest(blobs1, 30)); title('Thirty strongest SURE features in L1'); figure; imshow(L2); hold on; plot(selectStrongest(blobs2, 30)); title('Thirty strongest SURE features in L2'); [features1, validBlobs1] = extractFeatures(L1, blobs1); [features1, validBlobs2] = extractFeatures(L2, blobs2); indexPairs = matchFeatures(features1, features2, 'Metric', 'SAD','MatchThreshold', 5) matchedPoints1 = validBlobs1(indexPairs(:,1),:); matchedPoints2 = validBlobs2(indexPairs(:,2),:); figure; showMatchedFeatures(L1, L2, matchedPoints2); legend('Putatively matched points in L1', 'Putatively matched points in L2'); [fMatrix, epipolarInliers, status] = estimateFundamentalMatrix(matchedPoints1, matchedPoints2,'Method', 'RANSAC','NumTrials', 10000, 'DistanceThreshold', 0.1, 'Confidence', 99.99); if status ~= 0 || is EpipoleInImage(fMatrix', size(L1))|| is EpipoleInImage(fMatrix', size(L2)) erro(['Either not enought matching points were found']); end inlierPoints1 = matchedPoints1(epipolarInliers, :); inlierPoints2 = matchedPoints2(epipolarInliers, :); figure; showMatchedFeatures(L1, L2, inlierPoints1, inlierPoints2); legend('Inlier points in L1', 'Inlier points in L2'); [t1, t2] = estimateUncalibratedRectification(fMatrix, ... inlierPoints1.Location, inlierPoints2.Location, size(L2)); tform1 = projective2d(t1); tform2 = projective2d(t2); I1Rect = imwarp(L1, tform1, 'OutputView', imref2d(size(L1))); I2Rect = imwarp(L2, tform2, 'OutputView', imref2d(size(L2))); % transform the points to visualize them together with the rectified images pts1Rect = transformPointsForward(tform1, inlierPoints1.Location); pts2Rect = transformPointsForward(tform2, inlierPoints2.Location); figure; showMatchedFeatures(L1Rect, L2Rect, pts1Rect, pts2Rect); legend('Inlier points in rectified L1', 'Inlier points in rectified L2'); Irectified = cvexTransformImagePair(L1, tform1, L2, tform2);
  • 11. figure; imshow(Irectified); title('Rectified Stereo Images (Red - Left Image, Cyan - Right Image)'); cvexRectifyImages('left.jpg', 'right.jpg'); I1 = rgb2gray(imread('Lion1.jpg')); I2 = rgb2gray(imread('Lion2.jpg'));
  • 12. 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);
  • 13. 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');