combining RGB to get a full image

image_RGB = cat(2,final_red,final_green,final_blue)
imshow(image_RGB);
can anyone suggest me that this code is correct for combining RGB components for getting full image
as soon as possible

 Accepted Answer

IMPORTANT NOTE: MATLAB is case sensitive. redchannel is different than redChannel.
It looks like you've taken code I've posted many times and tried to adapt it:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Recombine separate color channels into an RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
I call them "channels" because that is the terminology Photoshop uses. You have to change the name of the arrays from redChannel to what yours are called. After you split apart your color channels and reprocessed them you have final_red. This, NOT redChannel, is what you need to use. You also need to not change from dimension 3 (which I had) to dimension 2. So the final code would be
% Recombine separate color channels into an RGB image.
rgbImage = cat(3, final_red,final_green,final_blue);

8 Comments

thanks sir ,
i gonna try this..
rgbImage = cat(3, final_red,final_green,final_blue);
What will happen if I write 2/1/4/something else in place of 3. I mean:
rgbImage = cat(1, final_red,final_green,final_blue);
It will most likely fail: the 3 is denoting the 3rd dimension. For RGB images: 1. and 2. dimension give the size in pixels, the 3. dimension is the color.
Sir, I have RGB values. Now I want a color image (single color) to display. Please let me know how to do it.
Actually, I have several RGB values in the form of two-dimensional matrix, so I want to represent all of them in single plot. Please help me with the required snippet.
@surendra gupta,
Please don't spam the forum. You've already asked that question. Until you give better explanations of what you want to achieve and what you start with, you'll only be given similar answers to use imshow, image, imagesc or pcolor.
It's a 3D image if you are layering the R G B images on top of each other -
imgRGB = cat(3, R, G, B)
imshow (imgRGB)
Is there any way to transform the grayscale image to rgb image?

Sign in to comment.

More Answers (2)

Hi, You don't want to concatenate along the column dimension. An RGB image has 3 dimensions. You want to concatenate along the 3rd dimension.
imdata = imread('ngc6543a.jpg');
RC = imdata(:,:,1);
GC = imdata(:,:,2);
BC = imdata(:,:,3);
im = cat(3,RC,GC,BC);
isequal(imdata,im)
imshow(im)

5 Comments

sir i find some errors on my matlab 2008 but on matlab 2010 it doesnt show any error can u suggest me something..
for example this sir
redChannel = noisy_picture(:, :, 1);
greenChannel = noisy_picture(:, :, 2);
blueChannel = noisy_picture(:, :, 3);
it shows undefined symbol when i try imshow function for each
please post the exact error message
??? Undefined function or variable 'redchannel'.
this error occured for all 3 above functions ....
imshow(redchannel);.....
plss rply fast..

Sign in to comment.

tablo tofiq
tablo tofiq on 6 May 2016
Edited: Stephen23 on 6 May 2016
display image in three color red&green&blue
a=imread('autumn.tif');
a1=a;
a1(:,:,2)=0;
a1(:,:,3)=0;
subplot(3,1,1)
imshow(a1)
a2=a;
a2(:,:,1)=0;
a2(:,:,3)=0;
subplot(3,1,2)
imshow(a2)
a3=a;
a3(:,:,1)=0;
a3(:,:,2)=0;
subplot(3,1,3)
imshow(a3)

1 Comment

Without three intermediate variables:
b = imread('autumn.tif');
b(:,:,4) = 0;
subplot(3,1,1)
imshow(b(:,:,[1,4,4]))
subplot(3,1,2)
imshow(b(:,:,[4,2,4]))
subplot(3,1,3)
imshow(b(:,:,[4,4,3]))

Sign in to comment.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!