PERFORMANCE EVALUATION OF WAVELET BASED IMAGE COMPRESSION USING EZW & SPIHT ALGORITHMS
1 MAIN MODULE CODE (main.m)
GParm.figure = figure('Color',[1 1 1], ...% white color
'MenuBar','none', ...
'Colormap',gray(256), ...
'Name','EZW & SPIHT WAVELET INTERFACE', ... % figure window name
'Visible','on', 'Resize','off', ... % initially not drawn
'NumberTitle','off', ...
'ShareColor','off', ...
'RendererMode','manual','Renderer','painters', ...
'Units','pixels', ...
'Position',[130 115 800 580], ... % window position
'WindowStyle','normal', ...
'Pointer','arrow');
%%% CLOSE BUTTON
posbox = [130 300 550 75] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.5 .6 .8], ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','WAVELET BASED IMAGE COMPRESSION USING EZW & SPIHT ALGORITHM', ...
'Position',posbox,....
'Callback','cont' ...
);
posbox = [150 110 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','CONTINUE', ...
'Position',posbox, ...
'Callback','menu' ...
);
posbox = [500 110 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','CLOSE', ...
'Position',posbox, ...
'Callback','close1' ...
);
2 SUB MODULE CODE (cont.m)
function cont
figure;imshow('info.bmp');
SUB MODULE CODE (menu.m)
function menu
GParm.figure = figure('Color',[1 1 1], ...% white color
'MenuBar','none', ...
'Colormap',gray(256), ...
'Name','EMBEDDED ZERO-TREE WAVELET INTERFACE', ...% figure window name
'Visible','on', 'Resize','off', ... % initially not drawn
'NumberTitle','off', ...
'ShareColor','off', ...
'RendererMode','manual','Renderer','painters', ...
'Units','pixels', ...
'Position',[130 115 800 580], ... % window position
'WindowStyle','normal', ...
'Pointer','arrow');
%%% CLOSE BUTTON
posbox = [630 100 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','CLOSE', ...
'Position',posbox, ...
'Callback','close1' ...
);
posbox = [30 100 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','READ INPUT', ...
'Position',posbox, ...
'Callback','read' ...
) ;
posbox = [230 100 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','EZW IMPLEMENTATION', ...
'Position',posbox, ...
'Callback','menu1(f,map);' ...
);
posbox = [430 100 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','SPIHT IMPLEMENTATION', ...
'Position',posbox, ...
'Callback','menu2(f,map);' ...
);
SUB MODULE CODE (close.m)
function close1
close all;
SUB MODULE CODE (read.m)
function read
GParm.figure=figure('color',[1 1 1], ...%black color
'MenuBar','none', ...
'Colormap',gray(256), ...
'Name','READ INPUT IMAGE OF ANY FORMAT', ... %figure window name
'Visible','on','Resize','off', ... %initially not drawn
'NumberTitle','off', ...
'Units','pixels', ...
'Position',[130 115 795 580], ... % window position
'WindowStyle','normal', ...
'Pointer','arrow');
%FORMAT BUTTONS
posbox=[290 137 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of bmp format', ...
'Position',posbox, ....
'callback','close;[f,map]=bmp;' ...
);
posbox=[40 175 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of jpg format', ...
'Position',posbox, ....
'callback','close;[f,map]=jpg;' ...
);
posbox=[540 175 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of tif format', ...
'Position',posbox, ....
'callback','close;[f,map]=tif;' ...
);
posbox=[40 100 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of gif format', ...
'Position',posbox, ....
'callback','close;[f,map]=gif;' ...
);
posbox=[540 100 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of png format', ...
'Position',posbox, ....
'callback','close;[f,map]=png;' ...
);
SUB MODULE CODE (read.m)
function read
GParm.figure=figure('color',[1 1 1], ...%black color
'MenuBar','none', ...
'Colormap',gray(256), ...
'Name','READ INPUT IMAGE OF ANY FORMAT', ... %figure window name
'Visible','on','Resize','off', ... %initially not drawn
'NumberTitle','off', ...
'Units','pixels', ...
'Position',[130 115 795 580], ... % window position
'WindowStyle','normal', ...
'Pointer','arrow');
%FORMAT BUTTONS
posbox=[290 137 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of bmp format', ...
'Position',posbox, ....
'callback','close;[f,map]=bmp;' ...
);
posbox=[40 175 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of jpg format', ...
'Position',posbox, ....
'callback','close;[f,map]=jpg;' ...
);
posbox=[540 175 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of tif format', ...
'Position',posbox, ....
'callback','close;[f,map]=tif;' ...
);
posbox=[40 100 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of gif format', ...
'Position',posbox, ....
'callback','close;[f,map]=gif;' ...
);
posbox=[540 100 200 40];
GParm.close=uicontrol( ...
'parent',GParm.figure, ...
'Style','Pushbutton', ...
'Background',[.9 .7 .7], ...
'BusyAction','queue', ...%'Interruptible','0ff',
'Units','pixel', ...
'String','Figure of png format', ...
'Position',posbox, ....
'callback','close;[f,map]=png;' ...
);
SUB MODULE CODE (menu1m)
function menu1(s,map);
K=[];
GParm.figure = figure('Color',[1 1 1], ...% black color
'MenuBar','none', ...
'Colormap',gray(256), ...
'Name','EZW WAVELET INTERFACE', ... % figure window name
'Visible','on', 'Resize','off', ... % initially not drawn
'NumberTitle','off', ...
'ShareColor','off', ...
'RendererMode','manual','Renderer','painters', ...
'Units','pixels', ...
'Position',[130 115 800 580], ... % window position
'WindowStyle','normal', ...
'Pointer','arrow');
%%% CLOSE BUTTON
posbox = [630 100 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','CLOSE', ...
'Position',posbox, ...
'Callback','close1' ...
);
posbox = [30 100 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','BLACK & WHITE PROCESS', ...
'Position',posbox, ...
'Callback','mat=ezw(f,map);' ...
);
posbox = [315 100 180 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','PSNR vs COMPRESSION RATIO', ...
'Position',posbox, ...
'Callback','analysis(mat)' ...
);
7 SUB MODULE CODE (menu2.m)
function menu2(s,map);
K=[];
GParm.figure = figure('Color',[1 1 1], ...% black color
'MenuBar','none', ...
'Colormap',gray(256), ...
'Name','SPIHT WAVELET INTERFACE', ... % figure window name
'Visible','on', 'Resize','off', ... % initially not drawn
'NumberTitle','off', ...
'ShareColor','off', ...
'RendererMode','manual','Renderer','painters', ...
'Units','pixels', ...
'Position',[130 115 800 580], ... % window position
'WindowStyle','normal', ...
'Pointer','arrow');
%%% CLOSE BUTTON
posbox = [630 100 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','CLOSE', ...
'Position',posbox, ...
'Callback','close1' ...
);
posbox = [30 100 150 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','BLACK & WHITE PROCESS', ...
'Position',posbox, ...
'Callback','mat=spiht(f,map);' ...
);
posbox = [315 100 180 30] ;
GParm.close = uicontrol( ...
'Parent',GParm.figure, ...
'Style','Pushbutton', ...
'BusyAction','queue','Interruptible','off', ...
'Units','pixel', ...
'String','PSNR vs COMPRESSION RATIO', ...
'Position',posbox, ...
'Callback','analysis(mat)' ...
);
SUB MODULE CODE (jpg.m)
function [f,map]=jpg;
[fname,path,findex] = uigetfile('*.jpg','Open a image file :',100,100) ;
[f,map]=imread(fname);
figure('position',[350 370 280 100]);
imshow(f,map);
title('ORIGNAL IMAGE');
return
SUB MODULE CODE (gif.m)
function [f,map]=gif;
[fname,path,findex] = uigetfile('*.gif','Open a image file :',100,100) ;
[f,map]=imread(fname);
figure('position',[350 370 280 100]);
imshow(f,map);
title('ORIGNAL IMAGE');
return
SUB MODULE CODE (gif.m)
function [f,map]=gif;
[fname,path,findex] = uigetfile('*.gif','Open a image file :',100,100) ;
[f,map]=imread(fname);
figure('position',[350 370 280 100]);
imshow(f,map);
title('ORIGNAL IMAGE');
return
SUB MODULE CODE (bmp.m)
function [f,map]=bmp;
[fname,path,findex] = uigetfile('*.bmp','Open a image file :',100,100) ;
[f,map]=imread(fname);
figure('position',[350 370 280 100]);
imshow(f,map);
title('ORIGNAL IMAGE');
return
SUB MODULE CODE (tif.m)
function [f,map]=tif;
[fname,path,findex] = uigetfile('*.tif','Open a image file :',100,100) ;
[f,map]=imread(fname);
figure('position',[350 370 280 100]);
imshow(f,map);
title('ORIGNAL IMAGE');
return
SUB MODULE CODE (png.m)
function [f,map]=png;
[fname,path,findex] = uigetfile('*.png','Open a image file :',100,100) ;
[f,map]=imread(fname);
figure('position',[350 370 280 100]);
imshow(f,map);
title('ORIGNAL IMAGE');
return
SUB MODULE CODE (ezw.m)
function mat=ezw(f,map);
%Conversion RGB type of image to gray scale image
if ndims(f)==3
s=rgb2gray(f);
f=s;
else
s=f;
end
[m n]=size(s); %Resolution of intesity image
%Conversion of any Resolution of image to 128 X 128 resolution image
while m>225 | n>225
if m>225 & n>225
s=dyaddown(s,1,'m'); %Down sampling of an image
elseif m>225
s=dyaddown(s,1,'r');
else
s=dyaddown(s,1,'c');
end
[m n]=size(s);
end
[m n]=size(s);
if m>128 & n>128
if m>153 & n>153
s=s(25:25+127,25:25+127); %To extract required part of image to get required resolution
elseif m>153
s=s(25:25+127,1:128);
elseif n>153
s=s(1:128,25:25+127);
else
s=s(1:128,1:128);
end
%Zero padding to the image matrix to get required resolution
elseif m<128>
m1=128-m;
n1=128-n;
for i=1:m1
for j=1:n
s(m+i,j)=0;
end
end
for i=1:128
for j=1:n1
s(i,n+j)=0;
end
end
else
if m<128
m1=128-m;
for i=1:m1
for j=1:n
s(m+i,j)=0;
end
end
else
n1=128-n;
for i=1:m
for j=1:n1
s(i,n+j)=0;
end
end
end
s=s(1:128,1:128);
end
f1=double(s);
%Conversion of any data class of image matrix to double data class
%Showing Original image of 128 X 128 resolution
figure('position',[100 500 200 70]);
imshow(mat2gray(f1)); %To convert image to Gray scale image
title('ORIGINAL IMAGE');
rr=0.05;
rrs=waitbar(0,'PROCESSING EZW CODING...........');
waitbar(.05);
%Applying Discrete Wavelet Transform upto 7 levels using mother wavelet Haar
[a1,h1,v1,d1]=dwt2(s,'haar');
n=256;
ch1=wcodemat(h1,n); %To quantize the image matrix to n(means 128) levels
cv1=wcodemat(v1,n);
cd1=wcodemat(d1,n);
[a2,h2,v2,d2]=dwt2(a1,'haar');
ch2=wcodemat(h2,n);
cv2=wcodemat(v2,n);
cd2=wcodemat(d2,n);
[a3,h3,v3,d3]=dwt2(a2,'haar');
ch3=wcodemat(h3,n);
cv3=wcodemat(v3,n);
cd3=wcodemat(d3,n);
ca3=wcodemat(a3,n);
s1=[ca3,ch3;cv3,cd3];
s2=[s1,ch2;cv2,cd2];
s3=[s2,ch1;cv1,cd1];
%Showing 3-Level decomposition image
figure('position',[400 500 200 70]);
imshow(uint8(s3));
title('3-LEVEL DECOMPOSITION IMAGE');
[a4,h4,v4,d4]=dwt2(a3,'haar');
[a5,h5,v5,d5]=dwt2(a4,'haar');
[a6,h6,v6,d6]=dwt2(a5,'haar');
[a7,h7,v7,d7]=dwt2(a6,'haar');
s1=[a7,h7;v7,d7];
s2=[s1,h6;v6,d6];
s3=[s2,h5;v5,d5];
s4=[s3,h4;v4,d4];
s5=[s4,h3;v3,d3];
s6=[s5,h2;v2,d2];
X=[s6,h1;v1,d1]; %7-Level Decomposition matrix
figure('position',[400 500 200 70]);
imshow(X);
title('7-LEVEL DECOMPOSITION IMAGE');
mag=abs(X);
mag=uint16(mag);
maximum=max(max(mag));
maximum=double(maximum);
U=log2(maximum);
V=ceil(U);
R=V;
sublist=[];
[xx,yy]=size(X);
global N
A=mapping(xx);
[m,n]=size(A);
k=1;
N=[];
for k=1:m*n;
flag=0;
for i=1:m;
if flag==1;
break;
end
for j=1:n;
if A(i,j)==k;
N=[N;i,j];
flag=1;
break;
end
end
end
end
order=1;
bb=[];
zz=0;
global N;
[m,n]=size(N);
XX=zeros(128);
sublists=[];
for I=1:V
threshold=(2^(V-I));
%Dominant Pass
[D,X,sublist] = dominantpass(X,threshold,sublist);
DD{order}=D;
%Subordinate pass
S= subordinatepass(sublist,threshold);
SS{order}=S;
order=order+1;
if threshold ==1,
break;
end
%%decoding
RR=zeros(128); % reference matrix RR;
[a,b]=size(DD{I});
% dominant pass
i=1; j=1;
while i<=m;
if j>b; % b is the length of dominant pass vector
break;
end
if RR(N(i,1),N(i,2))==1;
i=i+1;
else
if DD{I}(j)=='p';
XX(N(i,1),N(i,2))=threshold;
RR(N(i,1),N(i,2))=1; %reference matrix =1;
sublists=[sublists;N(i,1),N(i,2)];
end
if DD{I}(j)=='n';
XX(N(i,1),N(i,2))=-threshold;
RR(N(i,1),N(i,2))=1; %reference matrix =1;
sublists=[sublists;N(i,1),N(i,2)];
end
if DD{I}(j)=='z';
RR(N(i,1),N(i,2))=1; %reference matrix =1;
end
if DD{I}(j)=='t';
RR(N(i,1),N(i,2))=1; %reference matrix =1;
RR=checkchildren(i,RR);% all zerotree's descendants are set to 1.
end
i=i+1;j=j+1;
end
end
[xx,yy]=size(sublists);
threshold=threshold/2;
for i=1:xx;
if I==V-1 |threshold==1;
break;
end
if SS{I}(i)==1;
if XX(sublists(i,1),sublists(i,2))>0;
XX(sublists(i,1),sublists(i,2))= XX(sublists(i,1),sublists(i,2))+ threshold;
else
XX(sublists(i,1),sublists(i,2))= XX(sublists(i,1),sublists(i,2))-threshold;
end
end
end
rec=[];
rec=XX;
ra7=rec(1,1);
rh7=rec(1,2);
rv7=rec(2,1);
rd7=rec(2,2);
rh6=rec(1:2,3:4);
rv6=rec(3:4,1:2);
rd6=rec(3:4,3:4);
rh5=rec(1:4,5:8);
rv5=rec(5:8,1:4);
rd5=rec(5:8,5:8);
rh4=rec(1:8,9:16);
rv4=rec(9:16,1:8);
rd4=rec(9:16,9:16);
rh3=rec(1:16,17:32);
rv3=rec(17:32,1:16);
rd3=rec(17:32,17:32);
rh2=rec(1:32,33:64);
rv2=rec(33:64,1:32);
rd2=rec(33:64,33:64);
rh1=rec(1:64,65:128);
rv1=rec(65:128,1:64);
rd1=rec(65:128,65:128);
rs7=idwt2(ra7,rh7,rv7,rd7,'haar');
rs6=idwt2(rs7,rh6,rv6,rd6,'haar');
rs5=idwt2(rs6,rh5,rv5,rd5,'haar');
rs4=idwt2(rs5,rh4,rv4,rd4,'haar');
rs3=idwt2(rs4,rh3,rv3,rd3,'haar');
rs2=idwt2(rs3,rh2,rv2,rd2,'haar');
rs1=idwt2(rs2,rh1,rv1,rd1,'haar');
rs1=fix(rs1);
figure('position',[700 500 200 70]);
imshow(mat2gray(rs1))
title('COMPRESSED IMAGE');
OrigSize=131072;
qq=(size(S,2));
aa=((qq/8)+(size(D,2)));
bb=[bb aa];
cc=size(bb,2);
if cc==1
zz=bb(1);
else
for W=1:cc-1
zz=zz+bb(W);
end
end
RecSize=zz;
RecSize=fix(RecSize);
CompRatio=OrigSize/RecSize;
err=0;
S=logical(S);
for i=1:128
for j=1:128
diff=(rs1(i,j)-f1(i,j))^2;
err=err+diff;
end
end
mse=err/(128*128);
psnr=10*log10(255*255/mse);
mat=[];
mat=[mat;psnr,CompRatio];
sprintf('\t%d\t\t%f:%d',psnr,CompRatio,1)
rr=rr+0.05;
waitbar(rr);
end
waitbar(1);
close(rrs);
return
SUB MODULE CODE (mapping.m)
function A = mapping(n)
% To create a Morton Scan order matrix
if n == 2
A = [1 2; 3 4];
else
B = mapping(n/2);
A = [B B+(n/2)^2; B+(n/2)^2*2 B+(n/2)^2*3];
end
SUB MODULE CODE (dominantpass.m)
function [D,X,sublist] = dominantpass(X,threshold,sublist)
% Dominant pass function
D=[];
global N
[m,n]=size(X);
% X is the coefficients matrix
R=zeros(m); % matrix R is a reference matrix, same size as X; '0' means
%this coefficient is not a descendant from zerotree root;
[a,b]=size(N);
if abs(X(1,1))>=threshold; % X(1,1) is DC coefficient
sublist=[sublist, abs(X(1,1))];
if X(1,1)>0;
D=[D,'p'];
else D=[D,'n'];
end
X(1,1)=0;
else D=[D,'z'];
end
for k=2:4
if abs(X(N(k,1),N(k,2)))>=threshold,
sublist=[sublist, abs(X(N(k,1),N(k,2)))];
% append this significant coefficient to the subordinate list;
if X(N(k,1),N(k,2))>0, % determine the sign
D=[D,'p']; % >0,assign a "p"
else
D=[D,'n'];% <0,assign>
end
X(N(k,1),N(k,2))=0;
% the significent coefficients is replaced by a '0' in the coefficients matrix
else
% 2,3,4 has no parents,just check its descendants.
result = checkdescendants1( k,X,threshold,0);
if result==1,
D=[D,'z'];
else
D=[D,'t'];
R(N(k,1),N(k,2))=1;
end
end
end
for k=5:a;
if abs(X(N(k,1),N(k,2)))>=threshold,
sublist=[sublist, abs(X(N(k,1),N(k,2)))];
if X(N(k,1),N(k,2))>0, % determine the sign
D=[D,'p']; % >0,assign a "p"
else D=[D,'n'];% <0,assign>
end
X(N(k,1),N(k,2))=0;
% else zerotree = checkancestors( k,R,0);
else zerotree = checkancestors1( k,R,0);
% check coefficient is descended from zerotree root?
if zerotree==0, % Not descends from zerotree root
result = checkdescendants1( k,X,threshold,0);
% Check its has significant descendants?
if result==1,
D=[D,'z']; % isolated zero
else D=[D,'t'];% zerotree
R(N(k,1),N(k,2))=1;
% if zerotree, reference matrix coefficient=1
end
end
end
end
SUB MODULE CODE (checkancestors1.m)
function zerotree = checkancestors1(j,R,zerotree)
% zerotree=1 means coefficient is descended from zerotree root
% initial set zerotree=0
global N
i = floor((j+3)/4 );
while i>1,
if R(N(i,1),N(i,2))==1;
zerotree=1;
break;
end;
i = floor((i+3)/4 );
end
SUB MODULE CODE (checkdescendants.m)
function result = checkdescendants1(j,X,threshold,result)
% initial set result=0
% if the result=1, means that a coefficient has at least
% 1 significant descendant.
global N
[m,n]=size(N);
for i=(4*j-3):4*j;
if result==1 | i>m,
break;
end
if abs(X(N(i,1),N(i,2)))>=threshold
result=1;
break;
else
result=checkdescendants1(i,X,threshold,result);
end;
end;
SUB MODULE CODE (checkchildren.m)
function [RR]=checkchildren(j,RR)
% if a symbol 't' is encounted, then make all its descendants in reference
% matrix RR's components equal 1---ZEROTREES
global N
[m,n]=size(N);
for i=(4*j-3):4*j;
if i<=m,
RR(N(i,1),N(i,2))=1;
[RR]=checkchildren(i,RR);
end
end;
SUB MODULE CODE (subordinatepass.m)
function S = subordinatepass(sublist,threshold)
S=[];
[m,n]=size(sublist);
for i=1:n;
if sublist(1,i)>=threshold
%if sublist(1,i)>=threshold,
S=[S,1];
sublist(1,i)=sublist(1,i)-threshold;
else
S=[S,0];
end
end
SUB MODULE CODE (spiht.m)
function mat=spiht(f,map);
%Conversion RGB type of image to gray scale image
if ndims(f)==3
s=rgb2gray(f);
f=s;
else
s=f;
end
[m n]=size(s); %Resolution of intesity image
%Conversion of any Resolution of image to 128 X 128 resolution image
while m>225 | n>225
if m>225 & n>225
s=dyaddown(s,1,'m'); %Down sampling of an image
elseif m>225
s=dyaddown(s,1,'r');
else
s=dyaddown(s,1,'c');
end
[m n]=size(s);
end
[m n]=size(s);
if m>128 & n>128
if m>153 & n>153
s=s(25:25+127,25:25+127); %To extract required part of image to get required resolution
elseif m>153
s=s(25:25+127,1:128);
elseif n>153
s=s(1:128,25:25+127);
else
s=s(1:128,1:128);
end
%Zero padding to the image matrix to get required resolution
elseif m<128>
m1=128-m;
n1=128-n;
for i=1:m1
for j=1:n
s(m+i,j)=0;
end
end
for i=1:128
for j=1:n1
s(i,n+j)=0;
end
end
else
if m<128
m1=128-m;
for i=1:m1
for j=1:n
s(m+i,j)=0;
end
end
else
n1=128-n;
for i=1:m
for j=1:n1
s(i,n+j)=0;
end
end
end
s=s(1:128,1:128);
end
f1=double(s);
%Conversion of any data class of image matrix to double data class
%Showing Original image of 128 X 128 resolution
figure('position',[100 500 200 70]);
imshow(mat2gray(f1)); %To convert image to Gray scale image
title('ORIGINAL IMAGE');
wm=0.2;
wc=waitbar(0,'PROCESSING SPIHT CODING...........');
waitbar(.2);
%Applying Discrete Wavelet Transform upto 7 levels using mother wavelet Haar
[a1,h1,v1,d1]=dwt2(s,'haar');
n=256;
ch1=wcodemat(h1,n); %To quantize the image matrix to n(means 128) levels
cv1=wcodemat(v1,n);
cd1=wcodemat(d1,n);
[a2,h2,v2,d2]=dwt2(a1,'haar');
ch2=wcodemat(h2,n);
cv2=wcodemat(v2,n);
cd2=wcodemat(d2,n);
[a3,h3,v3,d3]=dwt2(a2,'haar');
ch3=wcodemat(h3,n);
cv3=wcodemat(v3,n);
cd3=wcodemat(d3,n);
ca3=wcodemat(a3,n);
s1=[ca3,ch3;cv3,cd3];
s2=[s1,ch2;cv2,cd2];
s3=[s2,ch1;cv1,cd1];
%Showing 3-Level decomposition image
figure('position',[400 500 200 70]);
imshow(uint8(s3));
title('3-LEVEL DECOMPOSITION IMAGE');
[a4,h4,v4,d4]=dwt2(a3,'haar');
[a5,h5,v5,d5]=dwt2(a4,'haar');
[a6,h6,v6,d6]=dwt2(a5,'haar');
[a7,h7,v7,d7]=dwt2(a6,'haar');
s1=[a7,h7;v7,d7];
s2=[s1,h6;v6,d6];
s3=[s2,h5;v5,d5];
s4=[s3,h4;v4,d4];
s5=[s4,h3;v3,d3];
s6=[s5,h2;v2,d2];
dec=[s6,h1;v1,d1]; %7-Level Decomposition matrix
figure('position',[400 500 200 70]);
imshow(dec);
%SPIHT algorithm implementation
%To know Threshold value
mag=abs(dec);
mag=uint16(mag);
maximum=max(max(mag));
maximum=double(maximum);
n=log2(maximum);
n=floor(n);
n1=n;
LSP=[]; %List of Significant Pixels
LIP=[]; %List of Insignificant Pixels
LIS=[]; %List of Insignificant sets
LIP1=[];
rec=zeros(128,128); %Reconstruction matrix
a=[]; %Transmission Bit Stream
mat=[]; %To store PSNR & Compression ratio
sprintf('\t%s\t\t%s','PSNR','Compression Ratio')
for i=1:n1
threshold=2^(n-i+1);
%Refinement pass
if i~=1
x=size(LSP,1);
for j=1:x
m=LSP(j,:);
p=m(1);
q=m(2);
v=abs(dec(p,q));
b1=dec2bin(v); %To convert decimal number to binary number
n2=size(b1,2);
n3=n-i+1;
n4=n2-n3;
b2=b1(n4);
b2=uint8(b2);
%To find Nth MSB bit
if b2==48
b3=0;
else
b3=1;
end
a=[a b3];
if rec(p,q)>=0
rec(p,q)=rec(p,q)+b3*2^(n-i+1);
else
rec(p,q)=rec(p,q)-b3*2^(n-i+1);
end
end
end
%Sorting pass
%Initialization of LIP & LIS
if i==1
LIP=[1,1;1,2;2,1;2,2];
LIS=[1,2,1;2,1,1;2,2,1;0,0,0];
end
x=size(LIP,1);
LIP1=LIP;
k=0;
for j=1:x
k=k+1;
m=LIP(j,:);
p=m(1);
q=m(2);
v=dec(p,q);
ab=abs(v);
if ab
a=[a 0];
else
a=[a 1];
x1=size(LIP1,1);
LIP1=[LIP1(1:k-1,:);LIP1(k+1:x1,:)];
k=k-1;
LSP=[LSP;p,q];
add=2^(n-i+1);
if v<0
a=[a 1];
add=-add;
else
a=[a 0];
end
rec(p,q)=add;
end
end
LIP=LIP1;
j=1;
while max(LIS(j,:))~=0
m=LIS(j,:);
p=m(1);
q=m(2);
t=m(3);
D=[2*p-1,2*q-1;2*p,2*q-1;2*p-1,2*q;2*p,2*q]; %Descedents or Children
D1=[];
for k=1:4
m1=D(k,:);
p1=m1(1);
q1=m1(2);
v=dec(p1,q1);
D1=[D1;v];
end
if t==2
L=[];
L1=[];
for k=1:4
m1=D(k,:);
p1=m1(1);
q1=m1(2);
L=[L;2*p1-1,2*q1-1;2*p1,2*q1-1;2*p1-1,2*q1;2*p1,2*q1]; %Grand children
end
for k=1:16
m1=L(k,:);
p1=m1(1);
q1=m1(2);
v=dec(p1,q1);
L1=[L1;v];
end
if max(abs(L1))
a=[a 0];
else
a=[a 1];
x=size(LIS,1);
LIS=[LIS(1:j-1,:);LIS(j+1:x,:)];
j=j-1;
LIS=LIS(1:x-2,:);
for k=1:4
m1=D(k,:);
p1=m1(1);
q1=m1(2);
LIS=[LIS;p1,q1,1];
end
x=size(LIS,1);
LIS=[LIS;0,0,0];
end
else
if max(abs(D1))
a=[a 0];
else
a=[a 1];
x=size(LIS,1);
LIS=[LIS(1:j-1,:);LIS(j+1:x,:)];
j=j-1;
if p<33>
LIS(x-1,:)=[p,q,2];
LIS(x,:)=[0,0,0];
end
for k=1:4
v=D1(k);
m1=D(k,:);
p1=m1(1);
q1=m1(2);
if abs(v)
a=[a 0];
LIP=[LIP;p1,q1];
else
a=[a 1];
LSP=[LSP;p1,q1];
add=2^(n-i+1);
if v<0
a=[a 1];
add=-add;
else
a=[a 0];
end
rec(p1,q1)=add;
end
end
end
end
j=j+1;
end
ra7=rec(1,1);
rh7=rec(1,2);
rv7=rec(2,1);
rd7=rec(2,2);
rh6=rec(1:2,3:4);
rv6=rec(3:4,1:2);
rd6=rec(3:4,3:4);
rh5=rec(1:4,5:8);
rv5=rec(5:8,1:4);
rd5=rec(5:8,5:8);
rh4=rec(1:8,9:16);
rv4=rec(9:16,1:8);
rd4=rec(9:16,9:16);
rh3=rec(1:16,17:32);
rv3=rec(17:32,1:16);
rd3=rec(17:32,17:32);
rh2=rec(1:32,33:64);
rv2=rec(33:64,1:32);
rd2=rec(33:64,33:64);
rh1=rec(1:64,65:128);
rv1=rec(65:128,1:64);
rd1=rec(65:128,65:128);
rs7=idwt2(ra7,rh7,rv7,rd7,'haar');
rs6=idwt2(rs7,rh6,rv6,rd6,'haar');
rs5=idwt2(rs6,rh5,rv5,rd5,'haar');
rs4=idwt2(rs5,rh4,rv4,rd4,'haar');
rs3=idwt2(rs4,rh3,rv3,rd3,'haar');
rs2=idwt2(rs3,rh2,rv2,rd2,'haar');
rs1=idwt2(rs2,rh1,rv1,rd1,'haar');
rs1=fix(rs1);
figure('position',[700 500 200 70]);
imshow(mat2gray(rs1));
title('COMPRESSED IMAGE');
OrigSize=131072;
RecSize=size(a,2);
RecSize=RecSize/8;
RecSize=fix(RecSize);
CompRatio=OrigSize/RecSize;
CompRatio=ceil(CompRatio);
err=0;
a=logical(a);
for i=1:128
for j=1:128
diff=(rs1(i,j)-f1(i,j))^2;
err=err+diff;
end
end
mse=err/(128*128);
psnr=10*log10(255*255/mse);
mat=[mat;psnr,CompRatio];
sprintf('\t%d\t\t%d:%d',psnr,CompRatio,1)
wm=wm+0.05;
waitbar(wm);
end
waitbar(1);
close(wc);
return
4.21 SUB MODULE CODE (analysis.m)
function analysis(mat)
psnr=mat(:,1);
cnr=mat(:,2);
x=size(psnr,1);
psnr=reshape(psnr,1,x);
cnr=reshape(cnr,1,x);
figure;plot(cnr,psnr);
xlabel('Compression Ratio');
ylabel('PSNR(in dB)');
2 comments:
I run this code but i keep getting an error message, as in :: (??? Error using ==> figure
Invalid property found.
Object Name : figure
Property Name : 'ShareColor'.
Error in ==> main at 1
GParm.figure = figure('Color',[1 1 1], ...% white color)
Please help me out. Thanks
I run this code but i keep getting an error response, as in:: (??? Error using ==> figure
Invalid property found.
Object Name : figure
Property Name : 'ShareColor'.
Error in ==> main at 1
GParm.figure = figure('Color',[1 1 1], ...% white color)
Please help me out with the errors. You can send it to my E-mail (necs.mobolaji@gmail.com) Thanks
Post a Comment