Image lengthening of 'rectifyStereoImages' function application results
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hi. I apply 'rectifyStereoImages' function for rectify stereo image. But results are littlebit weird.
[J1, J2] = rectifyStereoImages(I1, I2, stereoParams, 'OutputView', 'full');
I ran just this code.
I1, I2`s size : 2592x1944, but J1, J2`s size 8704x2378. It`s too long and there is no effect changing the option 'OutputView', 'full' → 'vaild' or reverse.
My stereo camera system is each camera tilts 20 degrees, -20 degrees towards the center (the optical axis draws a V shape), is it common for the output image to be longer when this function is applied?
(first row : input image, second row : output image)

Accepted Answer
Song-Hyun Ji
on 3 Jul 2023
Edited: Song-Hyun Ji
on 3 Jul 2023
I am not sure what is your 'steroParams' but they would affect the result. Here is my test code.
ld = load('wideBaselineStereo');
leftImages = imageDatastore(fullfile(toolboxdir('vision'), 'visiondata', ...
'calibration', 'wideBaseline', 'left'));
rightImages = imageDatastore(fullfile(toolboxdir('vision'), 'visiondata', ...
'calibration', 'wideBaseline', 'right'));
[imagePoints, boardSize] = detectCheckerboardPoints(leftImages.Files, rightImages.Files);
squareSizeInMillimeters = 29;
worldPoints = generateCheckerboardPoints(boardSize, squareSizeInMillimeters);
stereoParams = estimateStereoBaseline(imagePoints, worldPoints, ...
ld.intrinsics1, ld.intrinsics2);
figure; showReprojectionErrors(stereoParams)
I1 = readimage(leftImages, 1);
I2 = readimage(rightImages, 1);
[J1,J2] = rectifyStereoImages(I1,I2,stereoParams,'OutputView','full');
imshow(J1);

6 Comments
JONGHAK LEE
on 3 Jul 2023
Thank you for your reply. When I ran the your code, I found the same phenomenon. This might be a common phenomenon of the 'rectifyStereoImages()' function.
Song-Hyun Ji
on 4 Jul 2023
In my example, it can create a red-cyan anaglyph to see the stereo effect.
figure; imshow(stereoAnaglyph(J1, J2));

JONGHAK LEE
on 4 Jul 2023
yes, I got same result about my target images. It seems to be due to including black area.

by the way, Are you interested in stereo matching? If so, the code below would be helpful. I have to use SGM or BM, but in my case SGM was not satisfactory, and BM failed completely in any block size.
%% SGM
disparityRange = [0 48];
disparityMap = disparitySGM(J1,J2,"DisparityRange",disparityRange,"UniquenessThreshold",20);
figure
imshow(disparityMap,disparityRange)
title("Disparity Map")
colormap jet
colorbar
%% BM
disparityRange = [0 64];
disparityMap = disparityBM(J1, J2, 'BlockSize', 15, 'DisparityRange', disparityRange);
figure
imshow(disparityMap,disparityRange)
title('Disparity Map')
colormap jet
colorbar
-SGM

-BM

Song-Hyun Ji
on 4 Jul 2023
I think there might be some factors to get the expected result. I made the following example to get the failed result. If you think there is a product problem, please contact the Technical Support team with the reproducible sample files.
close all;
I1 = imread('rectified_left.png');
I2 = imread('rectified_right.png');
A = stereoAnaglyph(I1,I2);
figure;
tiledlayout(3,2)
nexttile([1 2]);
imshow(A)
title('Red-Cyan composite view of the rectified stereo pair image')
J1 = im2gray(I1);
J2 = im2gray(I2);
disparityRange = [0 48];
disparityMap = disparityBM(J1,J2,'DisparityRange',disparityRange,'UniquenessThreshold',20);
nexttile
imshow(disparityMap,disparityRange)
title('Disparity Map BM')
colormap jet
colorbar
disparityRange = [0 48];
disparityMap = disparitySGM(J1,J2,"DisparityRange",disparityRange,"UniquenessThreshold",20);
nexttile
imshow(disparityMap,disparityRange)
title("Disparity Map SGM")
colormap jet
colorbar
%%
I2 = imread('rectified_left.png'); % changed the 2nd image to left camera
I1 = imread('rectified_right.png'); % changed the 1st image to right camera
J1 = im2gray(I1);
J2 = im2gray(I2);
disparityRange = [0 48];
disparityMap = disparityBM(J1,J2,'DisparityRange',disparityRange,'UniquenessThreshold',20);
nexttile
imshow(disparityMap,disparityRange)
title('Disparity Map BM Failed')
colormap jet
colorbar
disparityRange = [0 48];
disparityMap = disparitySGM(J1,J2,"DisparityRange",disparityRange,"UniquenessThreshold",20);
nexttile
imshow(disparityMap,disparityRange)
title("Disparity Map SGM Failed")
colormap jet
colorbar

JONGHAK LEE
on 5 Jul 2023
Edited: JONGHAK LEE
on 5 Jul 2023
Hi, Ji. Thanks for your code and I`m pleased that it is helpful for research.
It works in my environment and for the test, I tried to proceed by replacing only input I1, I2 with another images. Even though I just replaced input images, result is similar to the result of I answered earlier, and also It seems similar to the result of 'Failed' in the example you presented.
close all;
I1 = imread('mouse3_left.jpg');
I2 = imread('mouse3_right.jpg');
A = stereoAnaglyph(I1,I2);
figure;
tiledlayout(3,2)
nexttile([1 2]);
imshow(A)
title('Red-Cyan composite view of the rectified stereo pair image')
J1 = im2gray(I1);
J2 = im2gray(I2);
disparityRange = [0 48];
disparityMap = disparityBM(J1,J2,'DisparityRange',disparityRange,'UniquenessThreshold',20);
nexttile
imshow(disparityMap,disparityRange)
title('Disparity Map BM')
colormap jet
colorbar
disparityRange = [0 48];
disparityMap = disparitySGM(J1,J2,"DisparityRange",disparityRange,"UniquenessThreshold",20);
nexttile
imshow(disparityMap,disparityRange)
title("Disparity Map SGM")
colormap jet
colorbar
%%
I2 = imread('mouse2_left.jpg'); % changed the 2nd image to left camera
I1 = imread('mouse2_right.jpg'); % changed the 1st image to right camera
J1 = im2gray(I1);
J2 = im2gray(I2);
disparityRange = [0 48];
disparityMap = disparityBM(J1,J2,'DisparityRange',disparityRange,'UniquenessThreshold',20);
nexttile
imshow(disparityMap,disparityRange)
title('Disparity Map BM Failed')
colormap jet
colorbar
disparityRange = [0 48];
disparityMap = disparitySGM(J1,J2,"DisparityRange",disparityRange,"UniquenessThreshold",20);
nexttile
imshow(disparityMap,disparityRange)
title("Disparity Map SGM Failed")
colormap jet
colorbar

Thanks for your help.
Song-Hyun Ji
on 7 Jul 2023
It is necessary to rectify the input images I1 and I2. Rectification ensures that corresponding points in the stereo pair image are aligned along the same rows. To rectify the input stereo pair image, you can utilize the rectifyStereoImages function. It is important to note that the reference image must remain consistent for both rectification and disparity map computation.
More Answers (0)
Categories
Find more on Stereo Vision in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)