how to get rid of the error for predictive coding ?

1 Ansicht (letzte 30 Tage)
nur aqila
nur aqila am 24 Feb. 2018
hi, I want to perform hybrid lossless image compression where I combine dpcm and iwt for predictive coding. I already did combining iwt followed by dpcm and it works. but when I combine dpcm followed by iwt it doesn't work. this error keeps appearing " _ _Index exceeds matrix dimensions.Error in DPCM7IWT1 (line 103)FreqPixInt(PixPos(x,y)+1)=FreqPixInt(PixPos(x,y)+1)+1;" what should i do ? below are my coding
A1=imread('lena.bmp');
Im=double(A1); %Convert to double precision.
PixErr(1,1)=0;
En1 = entropy(Im)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%encode DPCM%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%DPCM encode
%DPCM for the first column
for x=2:512; y=1;
PixErr(x,y)=Im(x,y)-Im(x-1,y);
end
%DPCM for first row
for y=2:512;x=1;
PixErr(x,y)=Im(x,y)-Im(x,y-1);
end
%other
k1=0.2;k2=0.2;k3=0.6; %constant value
for x=2:512;y=2:512;
PixErr(x,y)=round(Im(x,y)-(k1*Im(x-1,y)+k2*Im(x-1,y-1)+k3*Im(x,y-1))); %k1=c,k2=b,k3=a
end
%convert pixel error to integer
PixErr(1,1)=0;
for y=1:512;
for x=1:512;
if PixErr(x,y)==0;
PixPos(x,y)=1;
else if PixErr(x,y)>0;
PixPos(x,y)=(PixErr(x,y)*2)+1;
else
PixPos(x,y)=abs(PixErr(x,y))*2;
end
end
end
end
%calculate frequency occurence of symbols
FreqPixInt(1:512)=0;
for y=1:512 %all pixel values in rows
for x=1:512 %all pixel values in columns
FreqPixInt(PixPos(x,y)+1)=FreqPixInt(PixPos(x,y)+1)+1;
end
end
FreqPixInt;
%calculate entropy of symbols(positive integer)
En2=0;% initialize value entropy to 0
for i=1:512 % all pixels value in first rows
if FreqPixInt(i)==0
En2=En2; %dummy
else
En2=En2+(FreqPixInt(i)/262144)*log2(FreqPixInt(i)/262144); %512x512=262144 total pixels
end
end
En2=En2*(-1)
%image obtained after change to positive integer
for y=1:512;
for x=1:512;
if PixErr(x,y)<0;
E1(x,y)=abs(PixErr(x,y)*2);
else
E1(x,y)=PixErr(x,y)*2+1;
end
end
end
E1=double(E1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%encode IWT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5%%
% Start from the Haar wavelet and get the
% corresponding lifting scheme.
lshaar = liftwave('haar');
% Add a primal ELS to the lifting scheme.
els = {'p',[-0.125 0.125],0};
lshaarInt = liftwave('haar','int2int');
lsnewInt = addlift(lshaarInt,els);
%%%%%%%%%%%%%%%%%%%%%%%%Perform LWT %%%%%%%%%%%%%%%%%%%%%%%%%%%%
[cAint,cHint,cVint,cDint] = lwt2(E1,lsnewInt);
test=[cAint,cHint;cVint,cDint];
matA=512;
matB=512;
%calculate entropy
%convert to positive integer
for y=1:matA;
for x=1:matB;
if test(x,y)==0;
PixPos(x,y)=1;
else if test(x,y)>0;
PixPos(x,y)=(test(x,y)*2)+1;
else
PixPos(x,y)=abs(test(x,y))*2;
end
end
end
end
%calculate frequency occurence of symbols
FreqPixInt(1:512)=0;
for y=1:matA %all pixel values in rows
for x=1:matB %all pixel values in columns
FreqPixInt(PixPos(x,y)+1)=FreqPixInt(PixPos(x,y)+1)+1;
end
end
FreqPixInt;
%calculate entropy of symbols(positive integer)
En3=0;% initialize value entropy to 0
for i=1:matA % all pixels value in first rows
if FreqPixInt(i)==0
En3=En3; %dummy
else
totalpix=matA*matB;
En3=En3+(FreqPixInt(i)/totalpix)*log2(FreqPixInt(i)/totalpix); %512x512=262144 total pixels
end
end
En3=En3*(-1)
%%%%%%%%%%%%%%%%%%%%%%%%Perform invert LWT %%%%%%%%%%%%%%%%%%%%%%%%%%%%
xRecInt = ilwt2(cAint,cHint,cVint,cDint,lsnewInt);
errInt = max(max(abs(E1-xRecInt)))
level1=[cAint,cHint;cVint,cDint];
cAintk=int8(cAint);
one=[cAintk,cHint;cVint,cDint]; %int8
%decode pixel integer converter
for y=1:512
for x=1:512;
if E1(x,y)==1;
E2(x,y)=0;
else if mod(E1(x,y),2)==0;
E2(x,y)=((E1(x,y)/2)*(-1));
else
E2(x,y)=((E1(x,y)-1)/2);
end
end
end
end
X(1,1)=168;
%decoding DPCM
%first column
for x=2:512;y=1;
X(x,y)=E2(x,y)+Im(x-1,y);
end
%first row
for y=2:512;x=1;
X(x,y)=E2(x,y)+Im(x,y-1);
end
%others
for y=2:512;x=2:512;
X(x,y)=E2(x,y)+round((k1*Im(x-1,y)+k2*Im(x-1,y-1)+k3*Im(x,y-1)));
end
X=uint8(X);%Convert to unsigned 8-bit integer
PixErr=double(PixErr);
I=(A1)-(X);
I2=(PixErr)-(E2);
figure(2);
imshow(one);
title('leve1 1 suband');

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by