www.gusucode.com > GUI界面设计范例和ppt资料电信课程设计 > GUI界面设计范例和ppt资料电信课程设计/GUI界面设计范例/电信课程设计/5.compression/compression_decompression.m

    function [img_de]=compression_decompression(img,mask)

T=dctmtx(8);            
fun=@(x)(T*x*T');       
ifun=@(x)(T'*x*T);      
fmask=@(x)(x.*mask);    
img=im2double(img);    

  dim=length(size(img));
if(dim==3)          
    
    %DCT transformation to 8*8 block
        red=blkproc(img(:,:,1),[8 8],fun);
        green=blkproc(img(:,:,2),[8 8],fun);
        blue=blkproc(img(:,:,3),[8 8],fun);

    %Mask to 8*8 block
        mred=blkproc(red,[8 8],fmask);
        mgreen=blkproc(green,[8 8],fmask);
        mblue=blkproc(blue,[8 8],fmask);

    %IDCT transformation to 8*8 block
        ired=blkproc(mred,[8 8],ifun);
        igreen=blkproc(mgreen,[8 8],ifun);
        iblue=blkproc(mblue,[8 8],ifun);


    % Decoded image
   img_de(:,:,1)=ired;   
   img_de(:,:,2)=igreen;
   img_de(:,:,3)=iblue;
   
elseif(dim==2)       
        
    t_img=blkproc(img,[8 8],fun);
    m_img=blkproc(t_img,[8 8],fmask);
    img_de=blkproc(m_img,[8 8],ifun);
    
end


end