Azzera filtri
Azzera filtri

number of iteration

5 visualizzazioni (ultimi 30 giorni)
samia
samia il 2 Mag 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 Commenti
Oleg Komarov
Oleg Komarov il 2 Mag 2011
Format the code properly and supply example inputs.
Use the profile and *preallocate*.
samia
samia il 4 Mag 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);

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by