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

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Image Analyst
Image Analyst il 19 Feb 2016
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.

Più risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by