What is number of iterations deciding factor in the following code?

clc;
clearvars;
close all;
workspace;
fontSize = 33;
grayImage = imread('cameraman.tif');
subplot(1,2,1);
imshow(grayImage);
[rows, columns, numberOfColorChannels] = size(grayImage);
N=rows;
T=1.4938*N+40.8689;
disp(T);
t=0;
T2=ceil(T);
disp(T2);
c = T
iscram= grayImage;
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)=iscram(r,c);
end
end
t=t+1;
fprintf('t = %f, T2 = %f\n', t, T2);
end
subplot(1,2,2);
imshow(imscram);
(1) why should we use linear approximation of arnolds cat map, T=1.4938N+40.8689?
(2) which denotes the number of iterations in the above code?
(3) Even if i change t<700 or t<4, the output i got is the same..and also there is no change/improvement in NPCR and UACI value...

 Accepted Answer

After your fprintf() you need to add
iscram = imscram;
Otherwise you are just repeating the same work over and over again instead of doing multiple iterations of the transform.

More Answers (1)

That code is from someone else's post and it's wrong. I redid that code and a "fixed" version is attached. I don't use that T number he computed. It doesn't seem needed at all.
From Wikipedia, it seems that the code only works on square images. I tried to generalize it for rectangular images and always got the image wrapped around vertically. It never reconstituted itself. So maybe you'll have to use other scrambling methods.

5 Comments

but I got some errors...its not working.
Well my code works. Perhaps you modified my code, or else you're still talking about the wrong code you got from the other post. Like I said, I started with that post but there were so many errors that it's essentially been rewritten and is all new code. One problem was in the way he computed "c", adding 1 inside the mod(). Another problem was using the original iscram each time instead of recursively using imscram.
Just copy and paste my code and it should work. I've tried it on numerous images. If it doesn't work for you then attach your code with the paper clip icon and tell me which demo image you picked.
After running the arnoald cat map, I have the following
Saved image file Arnold Cat Iteration 67.png to disk.
Arnolds Cat Map, Iteration #68
Saved image file Arnold Cat Iteration 68.png to disk.
Back to Original after 68 Iterations.
How can I find "image file Arnold Cat Iteration 67.png " ? I mean where it is saved. I want the image of 67th iteration.
Make sure the imwrite() is not commented out like I had it in the demo:
% Save the image, if desired.
filename = sprintf('Arnold Cat Iteration %d.png', iteration);
% imwrite(currentScrambledImage, filename); % Uncomment this if you want to save the images.
fprintf('Saved image file %s to disk.\n', filename);
So take away the % and you should see Arnold Cat Iteration 67.png

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!