How to resolve the "Index exceeds matrix dimensions" error ?
Show older comments
Hi, I did some coding for lossless image compression and I want to calculate the entropy value. the error "Index exceeds matrix dimensions" keeps appearing at line _FreqPixInt(PixPos(x,y)+1)=FreqPixInt(PixPos(x,y)+1)+1. I don't know how to solve. Please help me. Below are my coding ;
clc
clear
x1= imread('barbara.bmp');
im=double(x1);
En1 = entropy(x1);
% 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);
[cAint,cHint,cVint,cDint] = lwt2(im,lsnewInt);
x2=double(cAint);
[cAint2,cHint2,cVint2,cDint2] = lwt2(x2,lsnewInt);
test=[cAint2,cHint2;cVint2,cDint2];
xRecInt2 = ilwt2(cAint2,cHint2,cVint2,cDint2,lsnewInt);
errInt2 = max(max(abs(x2-xRecInt2)))
one(1:128,1:128)=int8(cAint2);
one(129:256,1:128)=int8(cHint2);
one(1:128,129:256)=int8(cVint2);
one(129:256,129:256)=int8(cDint2);
level2=[cAint2,cHint2;cVint2,cDint2];
two=[level2,cHint;cVint,cDint];
test1=[level2,cHint;cVint,cDint];
figure(3);
imshow(int8(two));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%entropy%%%%%%%%%%%%%%%%%%%%%%%%%%
%convert to positive integer - kalau tak convert tak boleh kira
for y=1:512;
for x=1:512;
if test1(x,y)==0;
PixPos(x,y)=1;
else if test1(x,y)>0;
PixPos(x,y)=(test1(x,y)*2)+1;
else
PixPos(x,y)=abs(test1(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)
2 Comments
Bob Thompson
on 26 Feb 2018
FreqPixInt is a 1x512 array, but when you call PixPos(x,y)+1 at x = 512 or y = 512 you're trying to look at the 513 element of FreqPixInt.
nur aqila
on 28 Feb 2018
Accepted Answer
More Answers (0)
Categories
Find more on Neighborhood and Block Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!