No BSD License  

Highlights from
Scalable MPEG compression based on DCT coefficients

Scalable MPEG compression based on DCT coefficients

by

 

15 Nov 2006 (Updated )

This application makes 2 layers base Layer and enhancement layer from quantized coefficients

main44.m
clear all
close all
clc
tic
%colors = max(max(Im));
%Im = Im - ceil(colors/2);
Qp = [16 16 16 16 16 16 16 16;
     16 16 16 16 16 16 16 16;
     16 16 16 16 16 16 16 16;
     16 16 16 16 16 16 16 16;
     16 16 16 16 16 16 16 16;
     16 16 16 16 16 16 16 16;
     16 16 16 16 16 16 16 16;
     16 16 16 16 16 16 16 16];
aviobj = avifile('1.avi','fps',30,'COMPRESSION','None');
GOPindex=0;
motionVect=zeros(2,256);
fid=fopen('Qtable2.txt','r');
array=fscanf(fid,'%e',[8,inf]);
%array=2*array;
array=array;
blocksize=8;
i = 0;
flag=2;
XX=[];
BB=[];
EE=[];
secCounter=0;
sCounter=0;
sHatArray=[];
mov=aviread('foreman.avi');
movinfo=aviinfo('foreman.avi');
noframe=movinfo.NumFrames;
mbSize = 16;
p = 7;
w=0;
global I1d P4d P7d I10d B2d B3d B5d B6d B8d B9d
framedata=aviread('foreman.avi',1);
I1=frame2im(framedata);
I1=imresize(I1,[128 128]);
%I1=rgb2gray(I1);

I1=double(I1);
JQ=forwardDCT(I1,array);
bufferI1 = inverseDCT(JQ,array);
[X,B,E]= makeLayers(JQ);
XX(1)=length(X);
BB(1)=length(B);
EE(1)=length(E);

%%calling decoder
identifier=1;
decoder(X,B,E,motionVect,identifier,flag);

for i=1:10:321
    i
    if i~=1
        j=i-round(i/10);
        [B2,B3,P4,B5,B6,P7,B8,B9,I10]=GOP(j);
    elseif i==1
        j=i;
        [B2,B3,P4,B5,B6,P7,B8,B9,I10]=GOP(j);
    end
        %processing on P4 frame
        [bufferP4,streamP4,motionVect]=compensatedFrame(P4,bufferI1,mbSize,p,array); 
        [X,B,E]= makeLayers(streamP4);
        XX(4)=length(X);
        BB(4)=length(B);
        EE(4)=length(E);
        
        %calling decoder
        identifier=4;
        %decoder(diffDC,valVectorBase,lenVectorBase,valVectorEnhan,lenVectorEnhan,identifier,flag,motionVect);
        decoder(X,B,E,motionVect,identifier,flag);



% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
        
        %for B2    
        [B2t ,motionVect, flag] = bFrameProc(B2,bufferI1,bufferP4,1.4*array,mbSize,p);
        [X,B,E]= makeLayers(B2t);
        XX(2)=length(X);
        BB(2)=length(B);
        EE(2)=length(E);
        
        %calling decoder
        identifier=2;
        decoder(X,B,E,motionVect,identifier,flag);
        
        %for B3    
        [B3t ,motionVect ,flag] = bFrameProc(B3,bufferI1,bufferP4,1.4*array,mbSize,p);
        [X,B,E]= makeLayers(B3t);
        XX(3)=length(X);
        BB(3)=length(B);
        EE(3)=length(E);
        
        %calling decoder
        identifier=3;
        decoder(X,B,E,motionVect,identifier,flag);
 
        %predicting p7 from p4
        [bufferP7,streamP7,motionVect]=compensatedFrame(P7,bufferP4,mbSize,p,array);
        [X,B,E]= makeLayers(streamP7);
        XX(7)=length(X);
        BB(7)=length(B);
        EE(7)=length(E);
        
        %calling decoder
        identifier=7;
        decoder(X,B,E,motionVect,identifier,flag);
%          
        %for B5    
        [B5t motionVect flag] = bFrameProc(B5,bufferP4,bufferP7,1.4*array,mbSize,p);
        [X,B,E]= makeLayers(B5t);
        XX(5)=length(X);
        BB(5)=length(B);
        EE(5)=length(E);
        
        %calling decoder
        identifier=5;
        decoder(X,B,E,motionVect,identifier,flag);
   
        %for B6    
        [B6t motionVect flag] = bFrameProc(B6,bufferP4,bufferP7,1.4*array,mbSize,p);
        [X,B,E]= makeLayers(B6t);
        XX(6)=length(X);
        BB(6)=length(B);
        EE(6)=length(E);
        
        %calling decoder
        identifier=6;
        decoder(X,B,E,motionVect,identifier,flag);
 
        %processing on I10 frame
        streamI10=forwardDCT(I10,array);
        bufferI10 = inverseDCT(streamI10,array);
        [X,B,E]= makeLayers(streamI10);
        XX(10)=length(X);
        BB(10)=length(B);
        EE(10)=length(E);
        
        %%calling decoder
        identifier=10;
        decoder(X,B,E,motionVect,identifier,flag);
%         
        %for B8    
        [B8t motionVect flag] = bFrameProc(B8,bufferP7,bufferI10,1.4*array,mbSize,p);
        [X,B,E]= makeLayers(B8t);
        XX(8)=length(X);
        BB(8)=length(B);
        EE(8)=length(E);
        
        %calling decoder
        identifier=8;
        decoder(X,B,E,motionVect,identifier,flag);

        %for B9    
        [B9t motionVect flag] = bFrameProc(B9,bufferP7,bufferI10,1.4*array,mbSize,p);
        [X,B,E]= makeLayers(B9t);
        XX(9)=length(X);
        BB(9)=length(B);
        EE(9)=length(E);
        
        %calling decoder
        identifier=9;
        decoder(X,B,E,motionVect,identifier,flag);
    
%         
%         
        
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% end

         if j==1
               
                aviobj = addframe(aviobj,im2frame(uint8(I1d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B2d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B3d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(P4d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B5d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B6d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(P7d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B8d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B9d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(I10d),gray(256))); 
           
            else
                                aviobj = addframe(aviobj,im2frame(uint8(B2d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B3d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(P4d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B5d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B6d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(P7d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B8d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(B9d),gray(256)));
                aviobj = addframe(aviobj,im2frame(uint8(I10d),gray(256))); 
            end
            GOPindex=GOPindex+1;
    if i==1
        for ii=1:10

            compressionratioWOE(GOPindex,ii)=(XX(ii)+BB(ii))/(128*128*8);
        end
    else 
        for ii=2:10

            compressionratioWOE(GOPindex,ii-1)=(XX(ii)+BB(ii))/(128*128*8);
        end
    end
    
%end
        
    
%toc
% 			w=w+1;
% 			[originalSI(w),decodedSI(w),originalTI(w),decodedTI(w)]=shat1(B2,B2d,I1,I1d);
% 			w=w+1;
% 			[originalSI(w),decodedSI(w),originalTI(w),decodedTI(w)]=shat1(B3,B3d,B2,B2d); 
% 			w=w+1;
% 			[originalSI(w),decodedSI(w),originalTI(w),decodedTI(w)]=shat1(P4,P4d,B3,B3d); 
% 			w=w+1;
% 			[originalSI(w),decodedSI(w),originalTI(w),decodedTI(w)]=shat1(B5,B5d,P4,P4d); 
% 			w=w+1;
% 			[originalSI(w),decodedSI(w),originalTI(w),decodedTI(w)]=shat1(B6,B6d,B5,B5d);  
% 			w=w+1;
% 			[originalSI(w),decodedSI(w),originalTI(w),decodedTI(w)]=shat1(P7,P7d,B6,B6d);
% 			w=w+1;
% 			[originalSI(w),decodedSI(w),originalTI(w),decodedTI(w)]=shat1(B8,B8d,P7,P7d); 
% 			w=w+1;
% 			[originalSI(w),decodedSI(w),originalTI(w),decodedTI(w)]=shat1(B9,B9d,B8,B8d); 
% 			w=w+1;
% 			[originalSI(w),decodedSI(w),originalTI(w),decodedTI(w)]=shat1(I10,I10d,B9,B9d); 
% 
%             secCounter=secCounter+1;
%             if secCounter==3
%                 sCounter=sCounter+1;
%                 result(sCounter) = shat(originalSI,decodedSI,originalTI,decodedTI);
%                 secCounter=0;
%                 w=0;
%             end
            I1=I10;
            bufferI1=bufferI10;
            I1d=I10d;
% figure;imshow(uint8(B2d))
% figure;imshow(uint8(B3d))
end
toc
% imshow(uint8(I1d))
% figure;imshow(uint8(B2d))
% figure;imshow(uint8(B3d))
% figure;imshow(uint8(P4d))
% figure;imshow(uint8(B5d))
% figure;imshow(uint8(B6d))
% figure;imshow(uint8(P7d))
% figure;imshow(uint8(B8d))
% figure;imshow(uint8(B9d))
% figure;imshow(uint8(I10d))
% for i=1:10
% %compressionratio(i)=(XX(i)+BB(i)+EE(i))/(256*256*8);
% compressionratio(i)=(XX(i)+BB(i))/(256*256*8);
% end
aviobj = close(aviobj);

Contact us