How can I convert 1D array into 2D array ?

Hi, I have 512x512 image size and I want to convert the pixel to 1D matric. How can I convert from 2D into 1D without changing the pixel value? I use this command,
input=reshape(x2.',1,[])
but the pixel value is changing. Please help me

 採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 20 日

0 投票

You should avoid naming a variable input, as that is the name of a key MATLAB function to request input from the user.

reshape() can never change the pixel values. The particular way you use reshape would result in the pixel values being listed across rows first, all of first row, then all of second row, and so on.

3 件のコメント

nur aqila
nur aqila 2018 年 4 月 20 日
may I know what is the purpose of putting .' after x2? because the resulted pixel seems to change compared to x2 by itself
Stephen23
Stephen23 2018 年 4 月 20 日

.' is a shorthand operator for array transpose:

https://www.mathworks.com/help/matlab/ref/transpose.html

Walter Roberson
Walter Roberson 2018 年 4 月 20 日
Without the .' operator, the order of the pixels in the vector would be going down the columns, all of column 1 then all of column 2 and so on.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by