abr 10, 2009 -

## Robust subpixel stereo matching for Matlab

Hi! I am a Brazilian guy that implemented the famous Zhang’s point match algorithm. The complete description of the algorithm can be find in the paper below. But, concisely, the algorithm consists of three steps:

• Establish initial correspondences using a classical relaxation technique
• Estimate robustly the epipolar geometry
• Establish correspondences using estimated epipolar geometry as in stereo matching

There may be a large percentage of false matches (usually around 20%, sometimes 40%) using heuristic matching techniques such as correlation, and a false match may be completely different from the valid matches. The robust technique implemented deals with these issues and can theoretically detect outliers when they make up as much as 50% of whole data.

This code have been developed for instructional and research purposes, and have been shared with students in my university in the past. The code was implemented in m-file script language that is mostly compatible with Matlab. Matlab is an integrated numerical analysis package that makes it very easy implement computational modeling codes.

The toolbox was tested in an Ubuntu Linux Box. But, it should also work in any system.

### List of Functions

• mc_rzhang.m (main function) – A robust point match function;
• mc_zhang.mexglx – Points correspondences by relaxation (C language implementation);
• fm_8point.m – Estimates the Fundamental Matrix by Hartley’s 8-point algorithm;
• fm_lmeds.m – Estimates the Fundamental Matrix by LMedS algorithm;
• pt_2DNrml.m – Normalizes the interest points by Hartley’s algorithm;
• fm_adjust.m – Calculates the adjust of a set of points to a Fundamental Matrix;
• cn_harris.m – Harris’ algorithm for corner detection;
• imshow.m – Shows a image in the Matlab screen;
• im_gray.m – If the image is colored, converts it to a gray image;
• rgb2gray.m – Converts a RGB image to a gray scale.

It is necessary that the Matlab is already installed. If everything is ready, unpack the file rzhang.tar.bz2 and go to directory called mc_zhang. Afterwards, type the command below.

`make && make install`

So, the functions will be available in the directory called rzhang. See the script test.m to know how to use the functions.

### References

Zhang, Z., Deriche, R., Faugeras, O. D., e Luong, Q. T. (1995). A robust technique for matching two uncalibrated images through the recovery of the unknown epipolar geometry. Artificial Intelligence, 78(1-2):87-119.

• Kresimir Williams

Hello Dr. de Franca,
I was attempting to use your stereo-matching code and got hung on the line
subset = mt_subset(ssnpts,npts);
apparently the function mt_subset doesn’t exist within the package. I tried a google search to no avail, so I assume this function is one of yours. I am working on a stereo application for measuring fish and am very interested in trying out your code.
Thanks,
Kresimir

• http://jaf.eng.br Alex

• Kresimir Williams

Hello Dr. de Franca,
I found a few more dependencies in the code. The functions ‘fm_estimate’ and ‘mt_lms’ are missing, and perhaps others.
Cheers,
Kresimir

• http://jaf.eng.br Alex

(fm_estimate is not a function. It is a pointer to a function. It’s OK.)

• http://www.prosenjitbanerjee.spaces.live.com Prosenjit Banerjee

I am trying to work the codes in Windows/MATLAB 2007b. The code shows an error “Undefined function or method ‘mc_zhang’ for input arguments of type ‘uint8′.”What should I do to obtain the function ‘mc_zhang’?

• http://jaf.eng.br Alex

You should compile the C language code to generate the DLL mc_zhang. You should modify the file “Makefile” to do this. I don’t know how to adapting the “Makefile” in the Windows. :-(

• Daniel

Hi Alex,

I just tried compiling the code on a Mac Pro with Intel processor. I use gcc to compile c-programs. I get the following error when I issue the ‘make’ command from within the /mc_zhang/ folder

————————————
gcc -c -fPIC geral.c
gcc -c -fPIC numerical.c
`matlab -e | grep “MATLAB=” | sed “s/MATLAB=//g”`/bin/mex LDFLAGS=’numerical.o geral.o -shared’ -output mc_zhang matchzh.c
Undefined symbols:
“_main”, referenced from:
start in crt1.10.5.o
collect2: ld returned 1 exit status

mex: link of ‘ “mc_zhang.mexmaci”‘ failed.

make: *** [all] Error 1
—————————————

Dan

• Alex

I don’t know! :-( My Makefile seems have problems in MacOS. Look… The command should be…
`mex LDFLAGS=’numerical.o geral.o -shared’ -output mc_zhang matchzh.c`
You can edit the Makefile and specify the right command, with the mex’s full path. Do you understand?

• Raj Samant

can u giv instructions how to exec code in windows version of matlab 2010a or 2012b ??

• J. Alex França

Hello, Haj! You need to configure the mex compiler. Have you done this? If yes, in the matlab command window, type the following.

mex -c geral.c numerical.c
mex -v LINKFLAGSPOST=’numerical.obj geral.obj’ -output mc_zhang matchzh.c

Simple, no? Enjoy!

• Olol85

Looks promising!