Combining channels to get rgb image (color adjustment)
Show older comments
Hi all, I current have multiple images (>3), and am attempting to combining into channels and get an rgb image. I know how to do the basic operations. I'm having the problem of not getting the desired color when combined. For example, I want high values of the first image to show up as red. But after combining all 4 images that I have, the high values of the first image shows up as other colors. I'm just wondering if there is any "smart" way of adjusting colors rather than trial and error. Thanks!
Answers (2)
Image Analyst
on 14 Jun 2013
rgbImage = cat(3, redChannelImage, greenChannelImage, blueChannelImage);
Just put whatever images you want in the proper order according to the above.
4 Comments
Image Analyst
on 14 Jun 2013
I have no idea what your "Answer" below means. You just create your red channel however you want. If you want just 0 and 255 in there for the pixels, then go ahead and do that. If you want to scale the channels to apply weights to each one, then go ahead and do that. Feel free to upload an image to enhance your question and explain what you'd like. Try http://snag/gy
Image Analyst
on 14 Jun 2013
OK. Then just try this code:
% Demo code to find where the red channel is bright,
% and to set those pixels to pure red in the output RGB image.
%
clc;
close all;
workspace;
fontSize = 16;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 3, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gca, 'FontSize', 12);
% Display the image.
subplot(2, 3, 2);
imshow(redChannel);
title('Red Channel', 'FontSize', fontSize);
subplot(2, 3, 3);
imshow(greenChannel);
title('Green Channel', 'FontSize', fontSize);
subplot(2, 3, 4);
imshow(blueChannel);
title('Blue Channel', 'FontSize', fontSize);
% Threshold the red channel
binaryImage = redChannel > 160;
% Make those pixels pure red by setting the red channel to 255
% at those pixels and setting the green and blue pixels to 0.
redChannel(binaryImage) = 255;
greenChannel(binaryImage) = 0;
blueChannel(binaryImage) = 0;
% Recombine separate color channels into a single, true color RGB image.
rgbImage2 = cat(3, redChannel, greenChannel, blueChannel);
subplot(2, 3, 5);
imshow(rgbImage2);
title('Output Image', 'FontSize', fontSize);
nur liyana zamri
on 14 May 2017
why is the red,green and blue channel images in grey image?
Image Analyst
on 14 May 2017
Edited: Image Analyst
on 14 May 2017
Not sure what that means - the grammar is not right. So here are some facts. Pick the one that might answer your question.
Gray images have no red, green, and blue channels.
True color RGB images can look gray and they will have red, green, and blue channels that are all exactly the same.
Once extracted from a true color RGB 3-D image, you have 3 2-D images, one for red, one for green, and one for blue. Since they have only intensity of that channel, and not color, when you display them they will be in gray scale, unless you apply a colormap to them and then they can look like any color or combination of colors. For example, you can apply a colormap to make the red channel image appear red instead of gray if you want, but it's inherently gray - you're just changing the color of how it's displayed, not the pixel values of the underlying image.
If you want 3 true color images where the red channel is in the red channel (and the green channel and blue channel are black so that the image looks only red), then see this https://www.mathworks.com/matlabcentral/answers/111104-how-to-separate-an-image-to-rgb#comment_453709
Htet
on 14 Jun 2013
0 votes
Categories
Find more on Blue 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!