How can I make an image out of 3D matrices?
조회 수: 1 (최근 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.
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!