Selection when matrix dimensions exceed/ shorten
1 次查看(过去 30 天)
显示 更早的评论
I want to sweep a template over whole area of a bigger size image for matching purpose with increments of 10.
[h,w] = size(Templete);
for i = 1 : 10: size(Big_Image,1); for j = 1 : 10: size(Big_Image,2);
ROI_Big_Image = Big_Image(i:i+h , j:j+w ) ;
compare(Templete, ROI_Big_Image )
end end
Following Questions:
1. how I can make sure that some boundary pixels are not excluded due to size(Big_Image,1)/increment is not always perfectly dividable?
2. In another similar problem, I get an error of "Index exceeds matrix dimensions". Is there a smart way to avoid this error by selected within dimension area and adding dummy zeros to the rest?
0 个评论
回答(1 个)
Jan
2017-8-30
1. If you want to be sure, that the position at the border is not excluded, include it. There is no magic command for this, but you have to do it by your own.
s1 = size(Big_Image, 1);
k1 = 1:10:s1;
if k1(end) ~= s1
k1 = [k1, s1];
end
...
for i = k1
...
It is slower to use in index vector than to use the vector created for the for loop indexing dynamically. But perhaps here this delay does not matter.
2. You cannot magically avoid the error, but again you have to catch it by code. Check the limits before assigning or addressing.
Maybe this is a job for blockproc, which cares about the limits internally already.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!