Selection when matrix dimensions exceed/ shorten
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Jan
le 30 Août 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 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!