How to perform reverse permute to an already permuted matrix?

6 次查看(过去 30 天)
Hello, I have taken a color image as input and separated out the R G and B components. And then I converted the three planes into 1 D vectors. Consider a 4x4x3 matrix.The planes are interleaved as follows
V=[r1g1b1....r6]
W=[g6b6r7...g11]
X=[b11r12...b16]
The following is the code that I used to permute the three planes.
A=imread('C:\Users\Desktop\lena.jpg');
R = A(:, :, 1);
G = A(:, :, 2);
B = A(:, :, 3);
R1 = reshape(R.',1,[]);
G1 = reshape(G.',1,[]);
B1 = reshape(B.',1,[]);
H = permute(A, [3 1 2]);
N = numel(A)/3;
V = H(1 : N);
W = H(N + 1 : 2*N);
X = H(2*N + 1 : end);
Now I need to reverse this function ie; de-interleave the vectors and separate out the three planes and then combine them to get the original image. I dont know how to perform the inverse. I used ipermute function as follows, but i'm not able to obtain a proper result.I have obtained S,T and U which are equal to V,W and X. Dimg is equal to H.
C = ipermute(Dimg, [3 1 2])
Please help.Thanks in advance.
  2 个评论
Vivek Chaudhary
Vivek Chaudhary 2019-3-12
clc;
%% this program can permute any length vector (row vector)
A=[1 2 3 4 5 6 7 8 9]
M=length(A);
index=randperm(M); %% index
%% permutation
for i=1:M
B(:,i)=A(:,index(i));
z(:,index(i))=i; %% inverse mapping index
end
%% inverse mapping
for j=1:M
A_hat(:,j)=B(:,z(j));
end
A_hat

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by