필터 지우기
필터 지우기

Selection when matrix dimensions exceed/ shorten

조회 수: 1 (최근 30일)
Az
Az 2017년 8월 30일
답변: Jan 2017년 8월 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?

답변 (1개)

Jan
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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by