convert image matrix to row vector
22 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
DGM
2021 年 4 月 7 日
What exactly do you mean by "length of same size". Length isn't size.
You can use reshape() to reshape the array, but it will be [1 65536].
A=reshape(A',1,[]); % if you want rows
If you're expecting a [1 256] vector, then you'll have to decide how exactly you want to reduce the image conceptually (e.g. maybe you want directional mean or min or max; maybe you just want to extract a single row from the image)
回答 (2 件)
DGM
2021 年 4 月 7 日
編集済み: DGM
2021 年 4 月 7 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!