Error ' index exceeds matrix dimensions'? i had done arnold transform(48 iterations) and took DWT for each iteration. Here i need iterations from 19 to 29 only. but i got the error. what is the problem in my code. Help me resolve the problem. thank u
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
SIBI SIVA
am 3 Okt. 2016
Bearbeitet: Guillaume
am 3 Okt. 2016
imag1 = imread('peppers.png');imag2=rgb2gray(imag1);
imag3= imresize(imag2, [64, 64]);
subplot(1,2,1);
imshow(imag3);
k=1;
for i=1:48
[rows, columns] = size(imag3);
N=rows;
T=1.4938*N+40.8689;
disp(T);
t=0;
T2=ceil(T);
disp(T2);
c = T;
iscram= imag3;
while t< T2
for i= 1 : rows
for j= 1 : columns
r = mod(i+j,N)+1;
c = mod(i+(2*j)+1,N)+1;
imscram(i,j,k)=iscram(r,c);
%subplot(8,8,i);
imshow(imscram(:,:,k));
end
end
t=t+1;
k=k+1;
%fprintf('t = %f, T2 = %f\n', t, T2);
end
%subplot(1,2,2);
%figure
end
k1=1;
for i=19:29
imag4=imscram(:,:,i);
subplot(7,7,i);
imshow(imag4);
[lllo,lhlo,hllo,hhlo]=dwt2(double(imag4),'haar');
llw(:,:,k1)=lllo(:,:);
lhw(:,:,k1)=lhlo(:,:);
hlw(:,:,k1)=hllo(:,:);
hhw(:,:,k1)=hhlo(:,:);
k1=k1+1;
end
1 Kommentar
Akzeptierte Antwort
Guillaume
am 3 Okt. 2016
It's not clear where the error comes from in your code. In theory, there's no indexing that exceeds any matrix dimension, unless any of imscram, llw, lhw, hlw or hhw already exists is not 64x64x? prior to running your script.
However, there are several issues with your code.
First,
for i = 1:48
%bunch of code that does not depend on i and should be before the loop
for i = 1 : rows
You're using the same variable for two different loops. While that works (in matlab, in some other languages, it'll go very wrong), it's really not a good idea. Within the inner loop, you don't have access to the i of the outer loop. Don't do that.
Secondly, I'll point out you're not doing 48 iterations. You're doing 48 times the same iteration, each time discarding the result of the previous one. It may be because you've mistyped imscram as iscram in
imscram(i,j,k)=iscram(r,c);
Finally, you actually don't need the inner i and j loops. The following will be much faster:
[i, j] = ndgrid(1:rows, 1:columns);
r = mod(i+j,N)+1;
c = mod(i+(2*j)+1,N)+1;
imscram(:, :, k) = iscram(sub2ind(size(iscram), r, c));
Note however that if iscram is meant to be imscram, the above won't work if sub2ind(size(iscram), r, c) is not a permutation of 1:4096. It appears to be a permutation with the modulo operation that you have, so it's not an issue.
2 Kommentare
Guillaume
am 3 Okt. 2016
Bearbeitet: Guillaume
am 3 Okt. 2016
There's not much point investigating what is wrong with the second loop (which I assume you mean the for i = 19:29, which is actually the fourth loop), until you've fixed the problems in the first one.
Once, it's sorted, what is
size(imscram)
size(llw)
size(lhw)
size(hlw)
size(hhw)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Discrete Multiresolution Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!