Matlab里的disparity map 计算
(2010-11-21 15:54:10)
利用mean-shift function [fdsp dsp] = stereo(i1,i2, maxs) %----------------------------------------------------------------- % function [dsp_f dsp] = stereo(img_R,img_L, maxs) % % 3D from stereo. This function takes a stereopair % (that should already be registered so the only difference is inthe % 'x' dimension), and produces a 'disparity map.' The output here is % pixel disparity, which can be converted to actual distance fromthe % cameras if information about the camera geometry is known. % % The output here does show which objects are closer. % Brighter = closer % % EXAMPLE: % img_R = imread('tsuR.jpg'); % img_L = imread('tsuL.jpg'); % [dsp_f dsp] = stereo(img_R,img_L,20); % % Inputs: % img_R =right image % img_L =left image % maxs = maximum pixeldisparity. (depends on image pair) % % Outputs: % dsp = pixel disparities beforefinal filtering (0 indicates bad pixel) % dsp_f = final disparity mapafter mode filtering % % Algorithm: % 1) Compute pixel disparity by comparing shifted versions ofimages. % 2) Use 2D mode filter to replace low-confidence informationwith % informationfrom high-confidence neighbors. % % Coded by Shawn Lankton (http://www.shawnlankton.com) Feb.2008 %----------------------------------------------------------------- win_size = 7; %-- size of window used whensmoothing tolerance = 2; %-- how close R-L and L-R values need to be weight = 5;%-- weight on gradients opposed to color %--determine pixel correspondence Right-to-Left andLeft-to-Right [dsp1, diff1] = slide_images(i1,i2, 1, maxs, win_size,weight); [dsp2, diff2] = slide_images(i2,i1, -1, -maxs, win_size,weight); %--keep only high-confidence pixels dsp = winner_take_all(dsp1,diff1,dsp2,diff2,tolerance); %--try to eliminate bad pixesl fdsp = modefilt2(dsp,[win_size,win_size],2);