Matlab里的disparity map 计算

Matlab里的disparity map 计算

(2010-11-21 15:54:10)
标签:

it

matlab

立体视觉

分类:机器视觉
利用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);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值