what is the function of... ?please explain the statement ' roi'. and ' isempty'
1 次查看(过去 30 天)
显示 更早的评论
for m=1:size(leftI,1)
% Set min/max row bounds for image block.
minr = max(1,m-halfBlockSize);
maxr = min(size(leftI,1),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 = [minr+templateCenter(1)-2 ...
minc+templateCenter(2)+mind-2 ...
1 maxd-mind+1];
% Lookup proper TemplateMatcher object; create if empty.
if isempty(tmats{size(template,1),size(template,2)})
tmats{size(template,1),size(template,2)} = ...
video.TemplateMatcher('ROIInputPort',true);
end
thisTemplateMatcher = tmats{size(template,1),size(template,2)};
% Run TemplateMatcher object.
loc = step(thisTemplateMatcher, leftI, template, roi);
Dbasic(m,n) = loc(2) - roi(2) + mind;
end
end
0 个评论
采纳的回答
Wayne King
2011-10-1
tmats is created as an empty cell array 7x7
The code:
if isempty(tmats{size(template,1),size(template,2)})
tmats{size(template,1),size(template,2)} = ...
vision.TemplateMatcher('ROIInputPort',true);
end
says "if the element of the cell array tmats{4,4} (the size of the template in the row and column dimension the first time through the for loop) is empty, place the System object handle vision.TemplateMatcher('ROIInputPort',true) in that element of the cell array"
The next time through the loop the column location changes as explained in the demo.
2 个评论
Wayne King
2011-10-1
that's just an ellipsis to move the line of code to the next line without generating an error
x = randn(100,1);
mu = ...
mean(x);
% this will error
x = randn(100,1);
mu =
mean(x);
更多回答(1 个)
Image Analyst
2011-10-1
isempty() basically checks to see if the variable has been assigned and has a value or not. roi means "region of interest" and is the portion of the array to operate on.
3 个评论
Wayne King
2011-10-1
Hi Neenu, that is just the definition of the region of interest as ImageAnalyst has said. I suggest you place a breakpoint in that for loop and then use F10 to step through it, you will see how the region of interest changes and how the location of where the System object handle placement changes as well.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!