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

조회 수: 3 (최근 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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by