MATLAB Answers

convert image matrix to row vector

16 views (last 30 days)
Samaa Yasser
Samaa Yasser on 7 Apr 2021 at 12:09
Commented: Samaa Yasser on 8 Apr 2021 at 10:46
i have an image size 256x256 and i want to Convert the image matrix to a row vector with length same size , how i can got it please?
  2 Comments
Samaa Yasser
Samaa Yasser on 7 Apr 2021 at 13:17
first thank you for your help..
i want to generate a row vector from image pixel.
so i want to calculate the total number of the original image pixels first, then Convert the image matrix of size MN for example to a row vector with length NM , inorder to get random permutation of this row vector, so can you help

Sign in to comment.

Answers (2)

David Hill
David Hill on 7 Apr 2021 at 13:20
yourMatrix(:)';

DGM
DGM on 7 Apr 2021 at 20:07
Edited: DGM on 7 Apr 2021 at 20:09
Consider a 3x3 test image:
A=repmat(1:3,[3 1])
A =
1 2 3
1 2 3
1 2 3
The line I suggested:
A=reshape(A',1,[]); % if you want to sample from rows
will take the rows of A and end-concatenate them into one long row vector of size 1x9. No need to calculate numel(A).
A =
1 2 3 1 2 3 1 2 3
If instead you were to do
A=reshape(A,1,[]); % if you want to sample from cols
or
A=A(:)'; % David's suggestion
you would still get the same output size, but you would be sampling columnwise instead.
ans =
1 1 1 2 2 2 3 3 3
If the ordering of the pixels doesn't matter, you could do it either way.
  1 Comment
Samaa Yasser
Samaa Yasser on 8 Apr 2021 at 10:46
thaaank you sooo much i really apperciate =)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by