number of iteration

5 Ansichten (letzte 30 Tage)
samia
samia am 2 Mai 2011
I want to determine the number of iterations needed for the matrix its original state if a pixel is rotated according to a rule. for example to make the rotation I build this function:
%%%%%%%%%%%%%%
function nv_vect=catmap(N,a,b)
A=[1 a; b a*b+1];
nv_vect=zeros(2,N*N);
c=1;
for i=0:N-1
for j=0:N-1
nv_vect(:,c)=mod(A*[i j]',N);
c=c+1;
end
end
nv_vect=uint8(nv_vect+1);
%%%%%%%%%%%%%%%%
to construct the matrix I use this function:
function J=consruct_imag(I,nv_vect,N)
c=1;
for i=1:N
for j=1:N
J(i,j)=I(nv_vect(1,c),nv_vect(2,c));
c=c+1;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
now I will use the number of iteration to return the original image:
%%%%%%%%%%%%%%%%%%%%%%%%%
function J=cat_k_fois(I,N,a,b,k)
for g=1:k
nv_vect=catmap(N,a,b);
J=consruct_imag(I,nv_vect,N);
I=J;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I try to implement a function that allows me to determine the period T necessary to rebuild the image:
%%%%%%%%%%%%%%
function T=rech_k(I)
N=length(I);
a=1;k=1;k=1;
for(b=1:N-2)
while(k<=3*N)
K=cat_k_fois(I,N,a,b,k);
if(K==I)
T=k;break
else
k=k+1;
end
end
end
T;
%%%%%%%%%%%%%%%%%%%%%%
the problem is that the execution is very very slow, why??
  2 Kommentare
Oleg Komarov
Oleg Komarov am 2 Mai 2011
Format the code properly and supply example inputs.
Use the profile and *preallocate*.
samia
samia am 4 Mai 2011
if I understood you: my example is an image, I want to determine the period T if I change the image size; ie the main program is:
I=imread('image');
%% size(I)=N*N
T= rech_k(I);

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by