avgofmatblks.m

来自「quadtree implementation in matlab」· M 代码 · 共 32 行

M
32
字号
% % finds average of different blocks of input matrix
% % INPUT
% % i,j,w,h are vectors
% % mat : input matrix
% % i(k): beginning row index of kth block
% % j(k): beginning column index of kth block
% % w(k): width of kth block   (e.g. column 1 to colum 5 of mat)
% % h(k): height of kth block  (e.g. row 1 to row 3 of mat)
% % OUTPUT
% % avg(k): average of kth block (avg is a vector)
function avg=avgofmatblks(mat,i,j,w,h)

blkcount=length(i);
for k=1:blkcount        
    fromRow=i(k);
    toRow=i(k)+h(k)-1;
    fromCol=j(k);
    toCol=j(k)+w(k)-1;
    count=(toRow-fromRow+1).*(toCol-fromCol+1);
    avg(k)=sum(sum(mat(fromRow:toRow,fromCol:toCol)))/count; %avg/mean of block values
end

% % -------------------------------------------------------------------------
% % This program or any other program(s) supplied with it does not provide any
% % warranty direct or implied. This program is free to use/share for
% % non-commercial purpose only, for any other usage contact with author.
% % Kindly reference author.
% % Thanking you.
% % @ Copyright M Khan
% % Email: mak2000sw@yahoo.com
% %        mak2000@GameBox.net 
% % http://www.geocities.com/mak2000sw

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?