Nevermind everyone. I got it to work. I set the Dim = 3 and concatenated the image properly. I must of had old data loaded and once I used clear all it worked.
How do I piece together a 2-dim image using 3 given images, each representing R, G, B?
1 view (last 30 days)
Show older comments
I was given 3 images, all are 2-dim arrays. One represents R (red), G (green), and B (blue). Each of these are of the same image but representing RGB. I am supposed to create a composite image using those three that are given. What is the best way to do this in Matlab? I read in each image, then I did this:
R = red; %changing variable name G = green;
B = blue;
I_rgb = cat(2,R,G,B);
imagesc(I_rgb)
I tried setting the dim = 3 but Matlab didn't like it because, I assume, the images are all 2-dim. The way I have it, instead of getting back one image, I get back the 3 images side by side.
Accepted Answer
Joseph Cheng
on 6 Apr 2017
you should be using cat(3,red,green,blue) because you want to stack in the 3rd dimension.
x = randi(3,3,3)
x =
3 3 3
1 1 2
3 3 2
cat(3,x,x,x)
your statement "I tried setting the dim = 3 but Matlab didn't like it" doesn't tell us much on why matlab didn't like it. my suspicion is that all 3 are not the same size.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!