Selection when matrix dimensions exceed/ shorten
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Jan
on 30 Aug 2017
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 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!