📄 main.m
字号:
%function Y_new = SPIHT_main(nFrame,filename)
%
% This function implements the 3D-SPIHT algorithm.
% input: filename: the video sequence in CIF,QCIF or SIF format
% nFrame: number of frames to read from the filename specified
% output: Y_new: the reconstructed video sequence
%
%
% Athanasopoulos Dionysios
% Postgraduate Student
% Computer Engineering and Informatics Dept.
% University of Patras, Greece
%
% reads the luminance (Y) component from the filename specified. The file must
% be of the format CIF, QCIF, SIF. It reads nFrame frames.
%nFrame=input('please input the frame numbers: ');
%filename=input('please input the filename: ','s');
clear;
nFrame=8;
filename='foreman.cif';
[Y,U,V] = myfunc_read_cif(nFrame,filename);
% 3D - SPIHT encoder
type = 'CDF 9/7'; % type of filters for the decomposition
spatial_levels = 3; % levels of decomposition
%type =input('the type of the wavelet is: ','s');
%spatial_levels=input('please input the level: ');
fprintf('\n the size of the video sequence is %d %d %d \n',size(Y));
bitrate=input('please input the bitrate,the unit is bpp:');
%---------Wavelet Decomposition-----------------
tic;
for i=1:size(Y,3)
video_seq(:,:,i) = wavelet('2D CDF 9/7',spatial_levels,Y(:,:,i));
end
% maximum bits for the 3D-SPIHT encoding
max_bits = nFrame*size(Y,1)*size(Y,2)*bitrate; % 8 frames 388*352 0.5
% max_bits = 675840; % for exaple if we have 16 frames each 240x352 and use 0.5 bits per pixel max_bits = 675840
out = func_SPIHT_Enc(video_seq, max_bits,spatial_levels);
% 3D - SPIHT decoder
in = func_SPIHT_Dec(out,size(Y));
video_seq2 = in;
%--------------Wavelet Reconstruction------------
for i=1:size(video_seq2,3)
Y_new(:,:,i) = wavelet('2D CDF 9/7', -spatial_levels,video_seq2(:,:,i));
end
MSE=zeros(1,nFrame);
psnr=zeros(1,nFram8e);
avpsnr=0;
for i=1:nFrame
Q = 255;
MSE(1,i)=sum(sum((double(Y(:,:,i))-double(Y_new(:,:,i))).^2))/288 / 352;
psnr(1,i)=10*log10(Q*Q/MSE(1,i));
avpsnr=avpsnr+psnr(1,i);
end
toc;
fprintf('The average psnr performance is %.2f dB\n',avpsnr/nFrame);
% fid=fopen('E:\foreman.dat','wb');
% for k=1:nFrame
% fwrite(fid, Y2(:,:,k),'uint8');
% end
% fclose(fid);
fid=fopen('E:\foreman.yuv','wb');
for k=1:nFrame
fwrite(fid, Y2(:,:,k),'uint8');
end
fclose(fid);
%########读取操作,可以读出存储的图像###############
fid=fopen('E:\foreman.dat','r');
c=fread(fid,'uint8');
c1=zeros(288,352,nFrame);
for k=1:nFrame
for j=1:352
for i=1:288
c1(i,j,k)=c((k-1)*288*352+(j-1)*288+i);
end
end
end
for i=1:nFrame
imshow(uint8(c1(:,:,i)));
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -