PatchMatch Stereo Matlab implementation
This code implementents PatchMatch stereo with a direct interface to Matlab. I just wrote the Matlab wrapper; most of the heavy lifting was done by the actual C++ implementation.
Required packages:
- Linux: I have only tested it on Linux 18.04, but other linux versions should work
- Matlab: I tried on R2018a
- OpenCV
- OpenMP: For parallelization at some places
Compiling
- From command-line: Run make from command line to compile the program. The output should be
pm_mex.mexa64
. - From matlab prompt: Run make.m
Testing
This repo has left.png
and right.png
from Middlebury dataset (Baby doll, 2009) for testing the code.
Run test.m
to test the code with representative parameters.
Usage:
[left_disparity, right_disparity] = patchmatch_stereo(left_img, right_img, opts);
where,
left_img
: Image captured with left camera (uint8, RGB)right_img
: Image captured with right camera (uint8, RGB)- opts (optional): Structure with options for patchmatch algorithm with the following entries:
alpha
(0.9): Penalty term for balance between gradient and color fidelitygamma
(10.0): Controls how similar the colors should be in two viewstau_c
(10.0): Tolerance term for color similaritytau_g
(2.0): Tolerance term for gradient similaritywinsize
: Window size for computing disparitymax_disparity
: Maximum allowable disparityniters
: Number of patchmatch iterations
Some common problems:
- When running the code, Matlab throws an error about libTiff. See this for a solution. Essentially you need to ask Matlab to look for libraries elsewhere.