number of iteration

3 vues (au cours des 30 derniers jours)
samia
samia le 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 commentaires
Oleg Komarov
Oleg Komarov le 2 Mai 2011
Format the code properly and supply example inputs.
Use the profile and *preallocate*.
samia
samia le 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);

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Geometric Transformation and Image Registration dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by