How do we change the positions of the elements of t matrix ?
3 次查看(过去 30 天)
显示 更早的评论
I need to use S as index to change positions of mateix A
S=[1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7]
C = 1:numel(ِِA);
S = unique(S,'stable');
S = [S C(~ismember(C,S))]
A =[111 222 30 4;
50 65 70 83;
10 27 39 40 ;
54 67 72 81 ]
I need to permutate positions of elements of matrix by bellow subistitute:
Substitute A(S(i) ) with A (S(M×N)−i+1).,where M and N is rows and cols of matrix
Here i = 1, 2,..., M × N/2
Note: this way for permutation from this paper:A novel plaintext-related image encryption scheme using hyper-chaotic system
I attached the part of permutation from algorithim in img
step1: I reshap matrix to vector
[row,col]=size(A);
len=row*col;
B=reshape(A,1,len);
A=B;
step2: Substitute A(S(i) ) with A (S(M×N)−i+1).,where M and N is rows and cols of matrix
Here i = 1, 2,..., M × N/2
for i =1:len/2
A(S(i))=A(S(len-i+1));
end
Ab=reshape(A,row,col);
AA=reshape(Ab,1,len);
I get this result after permutation A by S:
Ab =
81 222 30 222
50 30 70 50
67 40 72 40
70 67 72 81
Then i need to make reverse operation to get back the original matrix.
for i =1:len/2
AA(S(len-i+1))=AA(S(i));
end
Abb=reshape(AA,row,col);
I get this result
Abb =
81 222 30 222
50 30 70 50
67 40 72 40
70 67 72 81
but I couldn't get the original matrix "A"
A= 111 222 30 4
50 65 70 83
10 27 39 40
54 67 72 81
What should I do to get original matrix from permutated matrix?
Note: it is immportant to me use this method to permutate matrix: "Substitute A(S(i )) with A (S(M×N)−i+1)."
I get this result instead of original matrix A:
Abb =
81 222 30 222
50 30 70 50
67 40 72 40
70 67 72 81
--------------------------------------------my code-----------------------------
A =[111 222 30 4;50 65 70 83; 10 27 39 40 ; 54 67 72 81 ];% original matrix we need to permutate
S=[1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7];% index used to permutate matrix A
%{
Remove the repeated elements from matrix index S, and
then put the absent numbers at the end to generate a new sequence X.
%}
C = 1:numel(A);
S = unique(S,'stable');
S = [S C(~ismember(C,S))]
% start permutation
[row,col]=size(A);
len=row*col;
B=reshape(A,1,len);
A=B;
for i =1:8
A(S(i))=A(S(len-i+1));
end
Ab=reshape(A,row,col);
% To get original matrix
AA=reshape(Ab,1,len);
for i =1:8
%encrimg1(m1)=im1_reshap(ind1(m1));%permutation
AA(S(len-i+1))=AA(S(i));
end
Abb=reshape(AA,row,col);
5 个评论
DGM
2022-1-1
编辑:DGM
2022-1-1
Well okay, that's one step, but I don't see how this is supposed to be reversible.
A = [111 222 30 4; 50 65 70 83; 10 27 39 40; 54 67 72 81];
S = [1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7];
n = numel(A);
C = 1:n;
S = unique(S,'stable');
X = [S C(~ismember(C,S))];
% forward transformation
% vectorization/loops aren't necessary here
k = 1:n/2; % assumes n is even
Ab = A;
Ab(X(k)) = Ab(X(n-k+1))
% the mapping from A to Ab retains only half of the members of A
% making the process irreversible
numel(unique(A))
numel(unique(Ab))
% for clarity, these are the map indices of the subsets:
k
n-k+1
I don't know what the rest of the book/paper suggests beforehand or afterward, but I don't see how this is supposed to be reversible unless we're both making incorrect assumptions about the process. What's the rest of the book say?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!