Hi @Kenny Manjarrez Gracia ,
Your code appears to follow the correct sequence for rectifying stereo images and calculating disparity. However, there are several aspects you might want to consider for improving the quality of your rectified images and the resulting disparity map.
Calibration Parameters
Ensure that the stereoParams variable loaded from stereoParametersD.mat is accurate. It should contain intrinsic and extrinsic parameters that reflect the actual physical arrangement of your cameras. You can visualize these parameters by using showReprojectionErrors(stereoParams) to ensure that they align well with your calibration patterns.
Image Quality
Make sure that the images you are loading (e.g., image19_cam1.png and image19_cam2.png) are of high quality with sufficient texture for disparity calculation. Low-contrast or blurry images can lead to poor rectification and disparity maps.Consider preprocessing your images (e.g., applying histogram equalization) to enhance their features before rectification.
Rectification Process
The rectifyStereoImages function should be used correctly, but double-check that stereoParams indeed matches your camera setup. If your images are not aligned properly after rectification, it may indicate an issue with the calibration or the rectification parameters.
Disparity Calculation
The disparity function can be sensitive to image quality and calibration accuracy. If you are getting unexpected results, experiment with different disparity algorithms available in MATLAB, such as disparityBM (Block Matching) or disparitySGM (Semi-Global Matching). Example modification:
disparityMap = disparityBM(OutL_gray, OutR_gray);
For more information on disparityBM function, please refer to
https://www.mathworks.com/help/vision/ref/disparitybm.html
Visualization
- When visualizing the disparity map, ensure that you are interpreting the values correctly. The display range [0, 64] may not be suitable for all datasets. Consider adjusting this range based on the actual range of disparity values calculated.
- Use imshow(dispar, []) to auto-scale the display based on minimum and maximum values.
Here are some additional insights I would like to share with you.
Multiple Image Pairs: Since you have 20 pairs of images, consider averaging or refining your disparity maps across multiple pairs to improve robustness.
Error Analysis: If possible, analyze any discrepancies in results across different image pairs to identify systematic issues in calibration or environmental factors affecting image capture (lighting conditions, occlusions).
Testing with Known Patterns: If feasible, test your setup with known geometric patterns or structures to verify that your calibration parameters yield expected results.
Hope this helps.
If issues persist after these adjustments, consider revisiting each step methodically or consulting additional resources on stereo vision and image processing techniques.