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

2 次查看(过去 30 天)
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by