hIdtc = vision.ImageDataTypeConverter;
hCsc = vision.ColorSpaceConverter('Conversion','RGB to intensity');
leftI3chan = step(hIdtc,imread('vipstereo_hallwayLeft.png'));
leftI = step(hCsc,leftI3chan);
rightI3chan = step(hIdtc,imread('vipstereo_hallwayRight.png'));
rightI = step(hCsc,rightI3chan);
figure(1), clf;
clf; 用来清除图形的命令。一般在画图之前用。
imshow(rightI3chan), title('Right image');
figure(2), clf;
imshowpair(rightI,leftI,'ColorChannels','red-cyan'), axis image;
title('Color composite (right=red, left=cyan)');
Dbasic = zeros(size(leftI), 'single'); disparityRange = 15;
% Selects (2*halfBlockSize+1)-by-(2*halfBlockSize+1) block. halfBlockSize = 3;
blockSize = 2*halfBlockSize+1;
% Allocate space for all template matcher System objects. tmats = cell(blockSize);
% Initialize progress bar
hWaitBar = waitbar(0, 'Performing basic block matching...');
nRowsLeft = size(leftI, 1);//返回的是左侧图像的行数
% Scan over all rows.row 为行 scan 扫描所有行 for m=1:nRowsLeft 扫描所有行
% Set min/max row bounds for image block. 图像块的行界起始
minr = max(1,m-halfBlockSize);
maxr = min(nRowsLeft,m+halfBlockSize);一个窗口上下行
% Scan over all columns.
for n=1:size(leftI,2)
minc = max(1,n-halfBlockSize);
maxc = min(size(leftI,2),n+halfBlockSize);左右列
% Compute disparity bounds.
mind = max( -disparityRange, 1-minc );
maxd = min( disparityRange, size(leftI,2)-maxc );
% Construct template and region of interest.
template = rightI(minr:maxr,minc:maxc);一块,上下行、左右列
templateCenter = floor((size(template)+1)/2);向下取整
roi = [minc+templateCenter(2)+mind-1 ... minr+templateCenter(1)-1 ... maxd-
mind+1 1];
% Lookup proper TemplateMatcher object; create if empty.//模板匹配
if isempty(tmats{size(template,1),size(template,2)})
tmats{size(template,1),size(template,2)} = ...
vision.TemplateMatcher('ROIInputPort',true);
评论1