MATLAB双目立体视觉实验

  • n2_492147
    了解作者
  • 10.6KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-07 05:26
    上传日期
根据相关文献利用自适应窗实现视差图生成算法。先进行ADCensus变换,然后计算自适应窗口。
Stereovision.zip
  • StereoDisparity.m
    6.7KB
  • CensusTrans.m
    1.9KB
  • StereoMatch.m
    3.4KB
  • ADCensus.m
    809B
  • StereoFixedW.m
    2.7KB
  • Steoro_disparity.mlx
    5.3KB
  • AD_Census.m
    652B
内容介绍
% Generate the disparity map based on two pictures captured in different % views. % Input, % img1: the reference image % img2: the match image, same size with img1. % Output, % DisparityMap: the generated disparity map function DisparityMap = StereoDisparity(img1, img2) img1 = int16(img1); img2 = int16(img2); % Initialize the parameters [height,width,~] = size(img1); ColorThreshold1 = 40; ColorThreshold2 = 20; SpatialThreshold1 = 8; SpatialThreshold2 = 16; CostThreshold = 1.1; % Since the window is irregualr, Landmark is applied to % indicate whether the disparity has been generated. Landmark = zeros(height,width,'logical'); DisparityMap = zeros(height,width,'uint8'); % Initilaize counter i,j i = 1; j = 1; % Initialize search parameters ScanScale = 100; Margin = 10; while i <= height while j <= width if ~Landmark(i,j) % Cross-based aggregation % For each pixel, calculates the vertical arm firstly; % Then calculates the horizontal arm for pixels in % vitical support. i_up = i-1; i_down = i+1; % Find the boundray of up arm while (i_up && i-i_up <SpatialThreshold1 ... && max(abs(img1(i_up,j,:)-img1(i,j,:)))<ColorThreshold1 ... && max(abs(img1(i_up,j,:)-img1(i_up+1,j,:)))<ColorThreshold1) i_up = i_up-1; end if (i-i_up >=SpatialThreshold1) while (i_up && i-i_up <SpatialThreshold2 ... && max(abs(img1(i_up,j,:)-img1(i,j,:)))<ColorThreshold2 ... && max(abs(img1(i_up,j,:)-img1(i_up+1,j,:)))<ColorThreshold2) i_up = i_up-1; end end i_up = i_up+1; % Find the boundray of bottom arm while (i_down <height && i_down-i <SpatialThreshold1... && max(abs(img1(i_down,j,:)-img1(i,j,:)))<ColorThreshold1... && max(abs(img1(i_up,j,:)-img1(i_down-1,j,:)))<ColorThreshold1) i_down = i_down+1; end if (i_down-i >=SpatialThreshold1) while (i_down <height && i_down-i <SpatialThreshold2... && max(abs(img1(i_down,j,:)-img1(i,j,:)))<ColorThreshold2... && max(abs(img1(i_up,j,:)-img1(i_down-1,j,:)))<ColorThreshold2) i_down = i_down+1; end end i_down = i_down-1; % ArmTbl stores the start/end point of horizontal arm ArmHeight = i_down-i_up + 1; ArmTbl = zeros(ArmHeight,2); for h = 1:ArmHeight j_left = j-1; j_right = j+1; % Find the boundary of left arm while (j_left && j-j_left <SpatialThreshold1 ... && max(abs(img1(h,j_left,:)-img1(h,j,:)))<ColorThreshold1 ... && max(abs(img1(h,j_left,:)-img1(h,j_left+1,:)))<ColorThreshold1) j_left = j_left-1; end if(j-j_left >=SpatialThreshold1) while (j_left && j-j_left <SpatialThreshold2 ... && max(abs(img1(h,j_left,:)-img1(h,j,:))) < ColorThreshold2 ... && max(abs(img1(h,j_left,:)-img1(h,j_left+1,:))) < ColorThreshold2) j_left = j_left-1; end end j_left = j_left+1; % Find the boundary of right arm while (j_right <width && j_right-j <SpatialThreshold1 ... && max(abs(img1(h,j_right,:)-img1(h,j,:))) < ColorThreshold1 ... && max(abs(img1(h,j_right,:)-img1(h,j_right-1,:))) < ColorThreshold1) j_right = j_right+1; end if (j_right-j >=SpatialThreshold1) while (j_right <width && j-j_right <SpatialThreshold2 ... && max(abs(img1(h,j_right,:)-img1(h,j,:))) < ColorThreshold2 ... && max(abs(img1(h,j_right,:)-img1(h,j_right-1,:))) < ColorThreshold2) j_right = j_right+1; end end j_right = j_right -1; ArmTbl(h,1) = j_left; ArmTbl(h,2) = j_right; end % Update Landmark matrix and find the maximum width of the window MinLeft = min(ArmTbl(:,1)); MaxRight = max(ArmTbl(:,2)); ArmWidth = MaxRight - MinLeft +1; for h=1:ArmHeight Landmark(i_up-1+h,ArmTbl(h,1):ArmTbl(h,2)) = true; end % Adjust ArmTbl to relative value RelativeTbl = ArmTbl - MinLeft + 1; % Initialize the MaskWindow and search for the matched region in img2 % Winner-take-all algorithom is applied here. MaskWindow = zeros(ArmHeight,ArmWidth,'int16'); for h=1:ArmHeight MaskWindow(h,RelativeTbl(h,1):RelativeTbl(h,2)) = 1; end Cost = 2*ones(ScanScale,1); Region = img1(i_up: i_up + ArmHeight-1,MinLeft:MaxRight,:); ReferRegion = Region.*repmat(MaskWindow,[1,1,3]); center = [i-i_up+1;j-ArmTbl(i-i_up +1,1)+1]; Area = sum(MaskWindow,'all'); RightSearchBoundry = MinLeft+ArmWidth +1; for k=1:ScanScale if (RightSearchBoundry <= width) Region = img2(i_up:i_up + ArmHeight -1,MinLeft+k:MinLeft+ArmWidth+k-1,:); MatchRegion = Region.*repmat(MaskWindow,[1,1,3]); Cost(k) = AD_Census(ReferRegion,MatchRegion,center,Area); elseif (MinLeft+k < width -Margin) Region = img2(i_up:i_up + ArmHeight -1,MinLeft+k:width,:); TruncatedWidth = width - MinLeft -k +1; MatchRegion = Region.*repmat(MaskWindow(:,1:TruncatedWidth),[1,1,3]); Area = sum(MaskWindow(:,1:TruncatedWidth),'all'); Cost(k) = AD_Census(ReferRegion(:,1:TruncatedWidth,:),MatchRegion,center,Area); end RightSearchBoundry = RightSearchBoundry +1; end [MinCost,Optim_d] = min(Cost); if MinCost <= CostThreshold for h=1:ArmHeight DisparityMap(i_up + h-1,ArmTbl(h,1):ArmTbl(h,2)) = Optim_d(1); end % DisparityMap(i,j) = Optim_d(1); end j = ArmTbl(i - i_up+1,2) + 1; % j = j+1; else j = j + 1; end end j = 1; i = i+1; end
评论
    相关推荐
    • 蛙跳算法MATLAB程序
      基本蛙跳算法MATLAB程序。用MATLAB编写的基础算法
    • 遗传算法Matlab程序
      应用数字群算法设计数字滤波器的matlab程序,遗传算法是最近几年流行的优化算法
    • Q算法MATLAB仿真
      移动机器人路径规划MATLAB仿真,使用Q-Learning算法
    • PSO 算法matlab程序
      这个程序就是最基本的粒子群优化算法程序,用Matlab实现。
    • 遗传算法MATLAB应用
      老师上课的参考书 主要是关于遗传算法的一些MATLAB应用,十分有意思 希望大家能喜欢
    • 遗传算法MATLAB实现
      遗传算法MATLAB实现,附WORD说明算法
    • 遗传算法matlab
      matlab程序下的遗传算法
    • 遗传算法matlab
      遗传算法是自然选择和群体学基础上的非数值优化方法。提供了些matlab实例计算
    • 遗传算法matlab
      matlab是科学计算常用的工具,遗传算法也是一种目前比较流行的一种算法,利用matlab写的遗传算法代码,供大家参考。
    • 遗传算法matlab代码
      遗传算法matlab代码,能够正常运行,对于刚开始接触遗传算法的人员有很好的帮助