converting 2d matrix to 3d matrix

11 ビュー (過去 30 日間)
cho min-ae
cho min-ae 2015 年 11 月 17 日
回答済み: Star Strider 2015 年 11 月 17 日
I have a question.
first i read .txt file which have rgb information. 66049 * 3 (r,g,b *66049)
i want read this file and convert to 257*257 image.
how can i do this?
thx

回答 (2 件)

Stephen23
Stephen23 2015 年 11 月 17 日
編集済み: Stephen23 2015 年 11 月 17 日
Try this:
Y = reshape(X,257,257,3)
For example, a matrix with R, G and B columns, rearranged into a 2*4*3 array:
>> X = [11,12,13;21,22,23;31,32,33;41,42,43;51,52,53;61,62,63;71,72,73;81,82,83]
X =
11 12 13
21 22 23
31 32 33
41 42 43
51 52 53
61 62 63
71 72 73
81 82 83
>> reshape(X,2,4,3)
ans(:,:,1) =
11 31 51 71
21 41 61 81
ans(:,:,2) =
12 32 52 72
22 42 62 82
ans(:,:,3) =
13 33 53 73
23 43 63 83

Star Strider
Star Strider 2015 年 11 月 17 日
If you want to convert your image to a (257x257) grayscale image, use the rgb2gray function. There are also Image Processing Toolbox Image Type Conversion functions if you have access to them.

カテゴリ

Help Center および 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