How can I make an image out of 3D matrices?

4 ビュー (過去 30 日間)
Janell Lopez
Janell Lopez 2016 年 2 月 19 日
コメント済み: Janell Lopez 2016 年 2 月 20 日
I have a homework assignment that I just need help understanding. We are to make a 4x6x3 matrix, where each column of the image is a single color, in rainbow order (Red, Orange, Yellow, Green, Blue, Purple), but we must use for loops.
I can see that the 3rd dimension is the RGB layer (I think), the columns are each color, and the rows are depth(?). I have the appropriate color values I need for each color, but I just don't understand how to write this with for loops. I'm very new and this is our first time dealing with for loops. I was thinking I could build a matrix for each Red, Green, and Blue set of values, and then make it 3D at the end, but I'm so lost I don't even know how I would start that... I just need some guidance, not answers. Thanks so much.

採用された回答

Image Analyst
Image Analyst 2016 年 2 月 19 日
Preallocate the array with zeros(rows, columns, 3, 'uint8'). Then define a list of colors, 6 rows by 3 columns where each column is the RGB value of that color (0-255). For example if row 1 = red, then row 1 = [255,0,0]. Then have a loop over columns. For each column, set all the rows to the color for that color. For example
rainbowImage(:, col, 1) = myColorMap(col, 1); % Assign red value to column "col".
Same for assigning the green and blue values from myColorMap to planes 2 and 3. So inside the for loop you will have 3 lines like that. If you don't like :, then you can have an inner loop over rows also. Give it a shot and come back with your code if you need help.
  1 件のコメント
Janell Lopez
Janell Lopez 2016 年 2 月 20 日
Thank you so much! That helped a ton.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by