Phụ lục
306
% if input image size is not a multiple of block size image is resized
modx=mod(dx,bx);
mody=mod(dy,by);
dvalue=dvalue(1:dx-modx,1:dy-mody);
% the new input image dimensions (pixels)
dx=dx-modx;
dy=dy-mody;
% number of non overlapping blocks required to cover
% the entire input image
nbx=size(dvalue,1)/bx;
nby=size(dvalue,2)/by;
% the output compressed image
matrice=zeros(bx,by);
% the compressed data
m_u=zeros(nbx,nby);
m_l=zeros(nbx,nby);
mat_log=logical(zeros(bx,by));
posbx=1;
for ii=1:bx:dx
posby=1;
for jj=1:by:dy
% the current block
blocco=dvalue(ii:ii+bx-1,jj:jj+by-1);
% the average gray level of the current block
m=mean(mean(blocco));
% the logical matrix correspoending to the current block
blocco_binario=(blocco>=m);
% the number of pixel (of the current block) whose gray level
% is greater than the average gray level of the current block
K=sum(sum(double(blocco_binario)));
% the average gray level of pixels whose level is GREATER than
% the block average gray level
mu=sum(sum(double(blocco_binario).*blocco))/K;
% the average gray level of pixels whose level is SMALLER than
% the block average gray level
if K==bx*by
ml=0;
else
ml=sum(sum(double(~blocco_binario).*blocco))/(bx*by-K);
end