I have tried to shuffle the image using tinkerbell map and Henon Map and obtained the output.But I cant do the inverse shuffling processes.The code is given below
clear all
clc
g=imread('cameraman.tif');
% g=double(g)/255;
subplot(231)
imshow(g)
original=g;
[m,n]=size(g);
mo=m;
num = 12;
K=10.^10;
% K=19;
%....................Shuffling.......................
disp('........................Started Shuffling.....................')
%Tinkerbell shuffling
a=0.3;b=0.6000;c=2.0;d=0.27;
for k= 1:num
for i=1:m
for j=1:n
r = mod([round(abs((i^2)-(j^2)+(a*i)+(b*j))),round(abs((2*i*j)+(c*i)+(d*j)))], [m,n]);
% r = mod([(i+j),(j+K*sin(((i+1)*n)/2*pi))],mo);
% r = [((i-1)+(K*sin(j-1))),((j-1)+i)];
% r = uint8(r);
ggg(i,j)=g(r(1)+1,r(2)+1);
% ggg(i,j)=g(r(1),r(2));
end
end
g=ggg;
end
subplot(232)
x=ggg;
imshow(ggg,[]);
title('Tinkerbell shuffled')
%henon Shuffling
[m,n]=size(x);
a = 1.4;b=0.3;
% num_iter=input('Enter the round for Arnold shuffling');
num_iter = 5;
% a=1.4;
% b=0.3;
for k=1:num_iter
for i=1:m
for j=1:m
r = mod([round(abs(1-(a*(i^2))+j)),round(abs(b*i))],[m n]);
xxx(i,j)=x(r(1)+1,r(2)+1);
end
end
x=xxx;
end
subplot(233)
imshow(xxx);
title('henon Shuffled Image')
save xxx x
disp('........................Shuffling process completed succesfully.....................')
%...................Inverse Shufling.............................
disp('........................Started Inverse Shuffling.....................')
%Henon Inverse Shuffling
for k=1:num_iter
for i=1:m
for j=1:n
r = mod([round(abs(1-(a*(i^2))+j)),round(abs(b*i))],[m n]);
x1(r(1)+1,r(2)+1)=xxx(i,j);
end
end
xxx=x1;
end
subplot(234)
imshow(x1);
title('henon Inverse Shuffled')
%Tinkerbell inverse shuffling
a=0.3;b=0.6000;c=2.0;d=0.27;
for k=1:num
for i=1:m
for j=1:n
r = mod([round(abs((i^2)-(j^2)+(a*i)+(b*j))),round(abs((2*i*j)+(c*i)+(d*j)))], [m,n]);
g1(r(1)+1,r(2)+1)=x1(i,j);
end
end
xxx=g1;
end
subplot(224)
imshow(g1)
title('Tinkerbell_inverse_shuffled')
disp('........................Inverse Shuffling process completed succesfully.....................')
psnr = psnr(g1,original)
ssim=ssim(g1,original)

1 commentaire

marie lasz
marie lasz le 17 Sep 2020
May I know that why you shuffled the image two times , I mean with two methods?

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 5 Fév 2017
Modifié(e) : Walter Roberson le 5 Fév 2017
Suppose your shuffled image is S. Then
temp = reshape(1:numel(S), size(S));
temp will be an array of linear indices -- temp(k) will be k.
Now apply your forward shuffling routine to temp, generating temp_mapped . Each value in temp_mapped will appear only once, and the location temp_mapped == k is the place that the shuffle maps pixel #k to. So you can undo it:
unshuffled = zeros(size(S), class(S));
unshuffled(temp_map) = S;
and you can cross-check by shuffling this and checking that you get out S.
By the way, once you have temp_mapped, you can use it to do all future shuffling,
S1 = unsuffled(temp_map);
S2 = S1(temp_map);
S3 = S2(temp_map);
and S3 would be unsuffled shuffled 3 times, without having to do any further computation of indices.

9 commentaires

Renjith V Ravi
Renjith V Ravi le 5 Fév 2017
Modifié(e) : Renjith V Ravi le 5 Fév 2017
Sorry, I am get confused regarding your reply.Please clarify
Replace
g=imread('cameraman.tif');
with
G = imread('cameraman.tif');
g = reshape( 1:numel(G), size(G) );
Then go through your shuffle code, producing ggg and xxx, but ignoring what is displayed.
After that,
GGG = G(ggg);
XXX = G(xxx);
are your two shuffled images, and you can imshow() those.
To unshuffle,
unshuffled_ggg = zeros(size(G), class(G));
unshuffled_ggg(ggg) = GGG;
unshuffled_xxx = zeros(size(G), class(G));
unshuffled_xxx(xxx) = XXX;
and now unshuffled_g and unshuffled_xxx are the result of undoing the shuffling of GGG and XXX
Renjith V Ravi
Renjith V Ravi le 5 Fév 2017
Modifié(e) : Renjith V Ravi le 5 Fév 2017
Anyway, I went for single shuffling,instead of double for easiness.But,I couldn't get the original image after unshuffling.The code is given below
clear all
close all
clc
num=1;
G = imread('cameraman.tif');
[m,n]=size(G);
g = reshape( 1:numel(G), size(G) );
a=0.3;b=0.6000;c=2.0;d=0.27;
%Tinkerbell shuffling
for k= 1:num
for i=1:m
for j=1:n
r = mod([round(abs((i^2)-(j^2)+(a*i)+(b*j))),round(abs((2*i*j)+(c*i)+(d*j)))], [m,n]);
ggg(i,j)=g(r(1)+1,r(2)+1);
end
end
g=ggg;
end
GGG = G(ggg);
disp('shuffling completed')
%inverse shuffling
% unshuffled_ggg = zeros(size(G), class(G));
% unshuffled_ggg(ggg) = GGG;
a=0.3;b=0.6000;c=2.0;d=0.27;
for k=1:num
for i=1:m
for j=1:n
r = mod([round(abs((i^2)-(j^2)+(a*i)+(b*j))),round(abs((2*i*j)+(c*i)+(d*j)))], [m,n]);
g1(r(1)+1,r(2)+1)=GGG(i,j);
end
end
unshuffled_ggg=g1;
end
unshuffled_ggg = zeros(size(G), class(G));
unshuffled_ggg(ggg) = GGG;
imshowpair(G,unshuffled_ggg, 'montage'); %better that subplot
You should remove
g=ggg;
but that will not affect the problem (the line just makes things harder later)
numel(unique(ggg)) is less than numel(ggg) which means that your code is mapping multiple locations to the same destination. The location (67,70) is reached in 8 different ways:
191 107
91 130
35 153
229 174
35 204
6 255
17 255
128 255
If you explore [6, 255] and [17, 255] then you can substitute in 255 for j in both cases, giving you
[ mod(round(abs(i^2 + (3*i)/10 - 64872)), 256), mod(round(abs(512*i + 1377/20)), 256)]
when you check round(abs(i^2 + (3*i)/10 - 64872) at i = 6 and i = 17 you will find that they are they generate two different values that are the same mod 256.
Because your mapping send multiple inputs to the same output location, there is no way to unshuffle it: you are losing information as you go. If you iterate enough times you would probably lose quite a lot.
Walter Roberson
Walter Roberson le 6 Fév 2017
Your henon map is even worse, giving only 19843 unique results of the mapping. It is so bad that with a 256 x 256 image, none of the values in column 79 and afterwards make it into the final image!
Walter Roberson
Walter Roberson le 6 Fév 2017
Let me put it another way:
Try starting with an all-white GGG and initialize g1 to all zero. Then apply your henon shuffling. If the shuffling works correctly, then every white input location will be moved to a unique corresponding location in g1, and the result in g1 would be all white as well. But try it and you will see that the result in g1 would be mostly black, indicating that nothing was moved into most locations.
VINAY KUMAR SHARMA
VINAY KUMAR SHARMA le 19 Déc 2017
what can be done for unique henon map code, its values are repeating??
RAVI  KUMAR
RAVI KUMAR le 15 Mar 2018
Are you able to get the correct inverse shuffling?
am not getting the inverse
its showing error
Index exceeds matrix dimensions.
Error in rough (line 62)
x1(r(1)+1,r(2)+1)=xxx(i,j);
pleae help me to resolve

Connectez-vous pour commenter.

Plus de réponses (1)

Hyelda Kefas
Hyelda Kefas le 7 Mai 2018
Modifié(e) : Walter Roberson le 7 Mai 2018
I was able to do the INVERSE SHUFFLE for the Henon map. I don't know whether it is perfectly correct or not. Let's rub minds and get the perfect solution for you. Thanks
clear all
clc
g=imread('cameraman.tif');
g = imresize(g, [256 256]);
g=g(:,:,1);
subplot(2,2,1)
imshow(g,[])
title('Original Image')
%HENON SHUFFLING
[m,n]=size(g);
a = 3;
b = 3;
num_iter = 1;
for k=1:num_iter
for i=1:m
for j=1:n
r = mod([round(abs(1-(a*(i^2))+j)),round(abs(b*i))],[m n]);
x(i,j)=g(r(1)+1,r(2)+1);
end
end
g=x;
end
subplot(2,2,2)
imshow(x,[]);
title('Henon Shuffled Image')
%HENON INVERSE SHUFFLING
[m,n]=size(x);
a = 3;
b = 3;
num_iter = 1;
for k=1:num_iter
for i=1:m
for j=1:n
r1 = mod([round(abs(1-(a*(i^2))+j)),round(abs(b*i))],[m n]);
x1(r1(1)+1,r1(2)+1)=x(i,j);
%x(i,j)=x1(r(1)+1,r(2)+1);
end
end
x=x1;
end
subplot(2,2,3)
imshow(x1,[]);
title('Henon Inverse Shuffled')
set(gcf,'units','normalized','outerposition',[0 0 1 1]);

Community Treasure Hunt

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

Start Hunting!

Translated by