Setting RGB values for each xy coordinate for a 3D matrix

12 views (last 30 days)
I have a 3D matrix with dimensions that represent (x,y,t). Meaning for each time value, I have a 2 matrix of x and y points. lets say it is 10x10x20.
I also have 3, 3D matrices corresponding to the amount of Red, Green, and Blue for each x and y coordinate. One of the 3D matrices has the amount of red for each x,y point. So it is also 10x10x20. The same is true for green and blue.
I need to make a new 3D matrix that has all of these values combined so that I can plot each x,y plane (like :,:,1 and :,:,2 and :,:,3 etc.) and they will represent the color I had in my original matrix.
I know this is a bit confusing but any help would be much appreciated.

Accepted Answer

Image Analyst
Image Analyst on 27 Mar 2013
I can understand where you have 3 #D matrices, one for Red, one for Green, and one for Blue, where each slice in those arrays is the R, G, or B for that time point, where everything in one slice is at the same time point. That seems like it should have everything you need - basically it's a color movie, though in a non-standard format.
But what is this first array you talked about? At each time slice (any slice out of the 20 time point slices), what does that value represent? Is it some kind of monochrome representation, like you'd get from rgb2gray()?
Why can't you get the original frames back again like this
for timePoint = 1 : 20
redSlice = Red(:,:,timePoint);
greenSlice = Green(:,:,timePoint);
blueSlice = Blue(:,:,timePoint);
rgbForThisTime = cat(3, redSlice, greenSlice, blueSlice);
% Convert the image into a "movie frame" structure.
myMovie(timePoint) = im2frame(thisFrame);
end
% Play the movie in the axes.
movie(myMovie);
  2 Comments
Matthew
Matthew on 27 Mar 2013
Sorry, I don't need the original matix and I think you're code does exactly what I was looking for in a lot less steps than the direction I was heading.
Before I use the im2frame I need to plot the "rgbForThisTime", right? what function would I use to plot this? imagesc wouldn't work would it?
Does the im2frame function work the same at the getframe function?
Thanks for the help!
Image Analyst
Image Analyst on 27 Mar 2013
If you want to show it in an axes as you go from slice to slice (though with only 20 frames, it would be so fast you could hardly see it), you'd use imshow and drawnow
imshow(rgbForThisTime);
drawnow; % Force it to update screen.
getframe() extracts an image out of an axes. im2frame gives an object from an rgb image that you can use to stuff into a movie - no axes at all is even needed. So they are different things.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!