1
votes

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 :

enter image description here

Ground-truth disparity map :

enter image description here

What I get :

enter image description here

Thank you in advance for your help.

1

1 Answers

0
votes

Ok, I figured it out. I was loading the disparity image with imread without specifying that it was a gray scale image (with IMREAD_GRAYSCALE). Therefore, openCV loaded it as an RGB image and when I was accessing a pixel of the disparity with at(), I was specifying uchar as the wanted type. So I guess there was kind of a conversion from Vec3b to uchar that gave false values.