Finding a 2d block with highest average inside a 2d window

Consider a matrix A(52,34) How to find out which 2d block size(3,3) has the highest average in it

 채택된 답변

Walter Roberson
Walter Roberson 2018년 3월 1일
[~, idx] = max(conv2(A, ones(3,3),'same'))
[r, c] = ind2sub(size(A), idx);
r and c is now the index of the center of the block that had the highest average.

댓글 수: 2

MSP
MSP 2018년 3월 2일
편집: MSP 2018년 3월 2일
r and c is supposed to be single values ,isnt it.If I run with A=magic(7) then it does'nt return single values.
[~, idx] = max( reshape(conv2(A, ones(3,3),'same'), [], 1) );
[r, c] = ind2sub(size(A), idx);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

MSP
2018년 3월 1일

댓글:

2018년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by