for ii=1025:4096
if(isempty(sig_coeff) | sum([sig_coeff==ii])==0) % Added new count=0;
if(seq(ii)~=inf & seq(ii)~=0), for kk=1:4
if(seq(indices(ii,kk))==0),count=count+1;end end
elseif seq(ii)==0 & seq(ii)~=inf, for kk=1:4
if(seq(indices(ii,kk))==0),count=count+1;end end
if count==4 & seq(ii)==0, ztr=[ztr ii]; for kk=1:4
seq(indices(ii,kk))=inf; end end end end end
%--------------------------------------------------------------------------------------- % Start of encoding for ii=1:128*128
if(isempty(sig_coeff) | sum([sig_coeff==ii])==0), if (seq(ii)>0 & seq(ii)~=inf),sym=[sym 'p']; elseif (seq(ii)<0 & seq(ii)~=inf),sym=[sym 'n']; elseif seq(ii)==0
if(ii<4097 & ~isempty(find(ztr==ii) & seq(ii)~=inf)) sym=[sym 'r'];
elseif(ii<4097 & seq(ii) ~= inf & isempty(find(ztr==ii))) sym=[sym 'z']; % This Was i earlier elseif(ii>4096 & seq(ii)~=inf) sym=[sym 'z']; end
end end end
% Encoding ends for one dominant pass
zero_tree_roots_positions=ztr; % Well just for debugging % Prepare for further passes
sig_coeff=[sig_coeff find(seq~=0 & seq~=inf)] ; % Index of where significant coeff occur
% Perform the Subordinate / Refinement pass
ref=dec2bin(abs(round(seqt(sig_coeff))),length(dec2bin(round(max(max(abs(seqt))))))); % Try not calculating the calculated % Change this,this takes long time
ref=ref(:,2:end); kp=find(sym~='z');
sym=sym(1:kp(length(kp))); % Remove predictably insignificant if kkk sym=[sym (ref(:,kkk))']; % This is also a problem check end seq=seqt; % Copy back the original sequence T=T/2 seq=seq.*[abs(seq)>=T==1]; seq(sig_coeff)=0; % Only those coefficients not yet found to be significant are scanned & % coefficients previously found to be significant are made zero num_of_passes=num_of_passes+1 drawnow ztr=[]; % Check out end % End of while symlen=[sym 0]; save symlen %finalexamd (3)EZW解码程序 clc format long load indices load lena orig=x(50:50+127,50:50+127); clear x enc=symlen; T=512; xm=mapping_128; xm=xm(:); x=xm; dec(128*128)=0; kk=1; ii=1; c=enc(ii); root_indices=[0]; sig_ele=[0]; req=[]; aaa=0; while T>=2 % Check Dominant pass first root_indices=[0]; sig_ele=[0]; kk=1; while (c~='0' & c~='1' & ii if(sum([root_indices==kk])==0 & sum([find(dec~=0)==kk])==0) c=enc(ii); if c=='p' dec(kk)=mean([T 2*T]); sig_ele=[sig_ele kk]; kk=kk+1; elseif c=='n' dec(kk)=-1*mean([T 2*T]); sig_ele=[sig_ele kk]; kk=kk+1; elseif c=='z' Tc(kk)=0; kk=kk+1; elseif c=='r' if kk>512 & kk<1025 temp=indices(indices(kk,1:end),1:end); root_indices=[root_indices indices(kk,1:end) (temp(:))']; kk=kk+1; elseif kk>1024 & kk<4097 root_indices=[root_indices indices(kk,1:end)]; kk=kk+1; end end ii=ii+1; else kk=kk+1; end end req=[req sig_ele(2:end)]; % Req contains all the coefficient indices in order which are found significant if(ii if enc(ii-1)=='1' dec(req(rr))=abs(dec(req(rr)))+T/4; elseif enc(ii-1)=='0' dec(req(rr))=abs(dec(req(rr)))-T/4; end if s==0,dec(req(rr))=-dec(req(rr));end ii=ii+1; end end ii=ii-1; disp('-------------------------------------------------------'); T rec=round(reshape(dec(xm(:)),128,128)); xr=synth2d(rec,3,3); figure,imshow(mat2gray(xr)) PSNR(xr,orig),ii aaa=aaa+length(sig_ele) disp('-------------------------------------------------------'); T=T/2; drawnow c=enc(ii); end 实验六 JPEG编解码 一、实验题目: JPEG编解码器 二、实验目的: 熟悉JPEG基本系统的图像编解码方法。 三、实验内容: 编程实现近似的JPEG基本系统压缩编、解码。 四、预备知识: (1)熟悉图像预测编码原理。 (2)熟悉图像DCT变换编码原理。 (3)熟悉熵编码原理。 (4)熟悉在MATLAB环境下对图像文件的I/O操作。 五、实验原理: