Create disparityMap for Stereo image

7 ビュー (過去 30 日間)
Kristian  Salma
Kristian Salma 2022 年 4 月 2 日
編集済み: Aishwarya 2023 年 10 月 11 日
Hi guys, I would like you to ask for help.
I useing Matlbab where I run on my stereo images rectifycation (rectifyStereoImages) algorithm the result are looking good, but when we try to apply the disparityMap (disparityBM) algorith we get some strange output for it.
I would appreciate any help I can get, thank youu.
The program code is below :
I1 = imread('red1.jpg');
I2 = imread('red2.jpg');
I1gray = rgb2gray(I1);
I2gray = rgb2gray(I2);
figure;
imshowpair(I1, I2,'montage');
title('I1 (left); I2 (right)');
figure;
imshow(stereoAnaglyph(I1,I2));
title('Composite Image (Red - Left Image, Cyan - Right Image)');
blobs1 = detectSURFFeatures(I1gray, 'MetricThreshold', 500);
blobs2 = detectSURFFeatures(I2gray, 'MetricThreshold', 500);
%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(I1gray, blobs1);
[features2, validBlobs2] = extractFeatures(I2gray, 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', 'LMedS', ...
'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, I2Rect] = rectifyStereoImages(I1, I2, tform1, tform2);
figure;
imshow(stereoAnaglyph(I1Rect, I2Rect));
title('Rectified Stereo Images (Red - Left Image, Cyan - Right Image)');
A = stereoAnaglyph(I1Rect, I2Rect);
figure
imshow(A);
title('Test')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = rgb2gray(A);
I1g = rgb2gray(I1Rect);
I2g = rgb2gray(I2Rect);
disparityRange = [0 16];
disparityMap = disparityBM(I1g,I2g,'DisparityRange',disparityRange,'UniquenessThreshold', 30);
figure
imshow(disparityMap,disparityRange)
title('Disparity Map')
colormap jet
colorbar

回答 (1 件)

Aishwarya
Aishwarya 2023 年 10 月 11 日
編集済み: Aishwarya 2023 年 10 月 11 日
Hi Kristian,
As per my understanding you would like to improve the results obtained of disparity map generated using “disparityBM function. After reviewing the information provided, here are some suggestions to improve the results:
1. Improvement in camera calibration:
2. Mismatched stereo pair:
  • Verify that both cameras have the same intrinsic and extrinsic parameters to ensure accurate depth estimation.
3. Tuning disparity range and other parameters of “disparityBM” function:
  • The default “BlockSize” parameter is not changed in the code. Consider tuning “BlockSize” parameter. Small block will results in more detailed disparity map but also more noise. On the other hand, a larger block gives smoother disparity map with less details and fails near boundaries.
  • For detailed instructions on tuning the disparity range using the "disparityBM" function, refer to the "Choosing Range of Disparity" subsection in the document provided: https://www.mathworks.com/help/vision/ref/disparitybm.html
4. Try different disparity mapping method:
  • Semi-global matching is more computationally expensive than block matching, but it can produce high-quality results. It is recommended to try both algorithms and compare their results for the specific application.
  • For instance, I have implemented the "disparityBM" algorithm. Subsequently, I compared these results with those obtained using the "disparitySGM" method.
5. Image post-processing
  • Consider applying Morphological transformation such as dilation or smoothing using gaussian blurr to the disparityMap.
Please note that the provided links below contain documentation that you may find helpful for further reference:
Hope this helps!
Regards,
Aishwarya

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by