How do I piece together a 2-dim image using 3 given images, each representing R, G, B?

조회 수: 1 (최근 30일)
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.
  댓글 수: 2
Travis Albee
Travis Albee 2017년 4월 6일
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.
Travis Albee
Travis Albee 2017년 4월 6일
Alas though, I have a new question...the image is of a city (as taken from a high altitude). I have to change the color of the man-made structures to yellow and the water to bright blue. What's a good way to do this in Matlab?

댓글을 달려면 로그인하십시오.

채택된 답변

Joseph Cheng
Joseph Cheng 2017년 4월 6일
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.
  댓글 수: 1
Travis Albee
Travis Albee 2017년 4월 6일
Thanks Joseph. In regards to the last statement in your comment, apologize for not being more clear. In my code, I used I_rgb = cat(2, R, G, B). I changed the 2 to a 3 and the code mashed the images together correctly. But I do have another question, which I wrote above and am hoping you can help on.
Here is my question: The image is of a city (as taken from a high altitude...looks like a satellite image). I have to change the color of the man-made structures to yellow and the water to bright blue. What's a good way to do this in Matlab?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by