I am trying to construct a right-view image from a left-view image and its disparity map. I use the middleburry dataset 2003 (http://vision.middlebury.edu/stereo/data/scenes2003/) with the full size images, which means the value v of each pixel in the disparity map corresponds to a shift of v pixels on the left-view image.
My algorithm is quite simple. For each pixel of coordinates (x, y) in the left-view image, I copy this pixel on the right-view image but at the coordinates (x - d, y) where d is the value of the disparity map at the coordinates (x, y). If the disparity value is 0, I just don't do anything. I use openCV to manipulate the images.
Here is my code:
void computeCorrespondingImage(const cv::Mat &img, const cv::Mat &disparity, cv::Mat &dest,
const bool leftInput, const int disparityScale)
{
const int shiftDirection = leftInput ? -1 : 1;
dest.create(img.rows, img.cols, img.type());
for (int i(0) ; i < img.rows ; ++i) {
for (int j(0) ; j < img.cols ; ++j) {
const uchar d(disparity.at<const uchar>(i, j));
const int computedColumn(j + shiftDirection * (d / disparityScale));
// No need to consider pixels who would be outside of the image's bounds
if (d > 0 && computedColumn >= 0 && computedColumn < img.cols) {
dest.at<cv::Vec3b>(i, computedColumn) = img.at<const cv::Vec3b>(i, j);
}
}
}
}
Since the disparity map is a ground-truth disparity map, I would expect to get an image quite like the right-view image provided in the dataset with some black areas (for which the disparity is unknown). However, for some reasons it's like the computed right-view image is split at the center, making the image unusable.
Left-view image :
Ground-truth disparity map :
What I get :
Thank you in advance for your help.