how to code rbg colour intensity of an image?????

41 views (last 30 days)
question: how to work out rgb color intensity of an image?
i have used histogram to show this, however i need an alternative way to show which color has high/low intensity in the image used. is there way to use image pixel/mean/average of each color to code this in matlab? HELP
  1 Comment
Jan
Jan on 1 Aug 2013
The question is not clear. Neither repeated character nor a pile of dots can replace real details. What are your inputs? What are the wanted outputs? What have you tried so far and which problems are you still working on?
Please add the details by editing the question, not by adding a comment or a pseudo-answer. Thanks!

Sign in to comment.

Accepted Answer

Dishant Arora
Dishant Arora on 1 Aug 2013
you can extract all the three color planes using:
R = YourImage(:,:,1); % Red color plane
G = YourImage(:,:,2); % Green color plane
B = YourImage(:,:,3); % Blue color plane
  1 Comment
Dishant Arora
Dishant Arora on 1 Aug 2013
Yeah you can take mean of the RGB components, this is what happens in HSI color space to denote intensity/Achromatic portion of image ,
I = 1/3*(R+G+B);
also you can follow YCbCr model to get achromatic notion:
Y = 0.2126*R + 0.7152*G + 0.0722*B

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 1 Aug 2013
Edited: Image Analyst on 1 Aug 2013
It doesn't sound like you simply want to extract each color channel like the answer you accepted suggested. Indeed your comment makes me wonder why you accepted it. Instead it actually sounds like you're describing the "color frequency image". This is an image where the brightness of the image is proportional to how many pixels have that color, which is what it sounds like when you say "show which color has high/low intensity in the image used". Luckily the color frequency image code is in the File Exchange here: http://www.mathworks.com/matlabcentral/fileexchange/28164-color-frequency-image:
Description
This is a MATLAB implementation of the Color Frequency concept introduced by T. Kashiwagi & S. Oe.
With this script, you pick a color image and then it computes the color frequency image. The color frequency image is an image where the pixel intensity represents the frequency of pixels in the original image that have that same pixel color as that pixel location. For example, in the screen shot, the blue sky looks bright because there are a lot of similarly colored blue pixels in the image. Everywhere there is a blue pixel in the original image, it will have a high value in the frequency image because the frequency of blue pixels is high.

mohsin saleem
mohsin saleem on 15 Nov 2016
how i can change the green color into yellow please tell me
  1 Comment
Image Analyst
Image Analyst on 15 Nov 2016
This will do it:
% Converts RGB image to HSV colorspace, then finds the green pixels.
% Changes green pixels to yellow pixels.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Read in a standard MATLAB color demo image.
% Let's let the user select from a list of all the demo images that ship with the Image Processing Toolbox.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
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, 2, 1);
imshow(rgbImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
% Convert to hsv color space.
hsv = rgb2hsv(rgbImage);
% Display the color channels.
hueImage = hsv(:, :, 1);
saturationImage = hsv(:, :, 2);
valueImage = hsv(:, :, 3);
subplot(2, 2, 2);
imshow(hueImage, []);
title('Hue Channel', 'FontSize', fontSize);
subplot(2, 2, 3);
imshow(saturationImage, []);
title('Saturation Channel', 'FontSize', fontSize);
subplot(2, 2, 4);
imshow(valueImage, [])
title('Value Channel', 'FontSize', fontSize);
drawnow;
hp = impixelinfo(); % Show RGB while they mouse around over the image.
% Make a second figure for more results.
figure;
subplot(2, 2, 1);
% Look at the histogram of the hue channel
% so we can see where the yellow is
histObject = histogram(hueImage(:), 200, 'EdgeColor', 'none') % Use 500 bins.
grid on;
title('Histogram of Hue Channel', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
% Green looks like it's in the 0.15 to 0.52 region.
% Amplify that by increasing saturation for those pixels.
% Find yellow pixels. They have to have the right hue but not be too bright.
greenPixels = hueImage > 0.15 & hueImage < 0.52;
subplot(2, 2, 2);
imshow(greenPixels);
title('Map of Green Pixels', 'FontSize', fontSize);
% Make the green pixels have a hue of 0.11, which is yellow.
hueImage(greenPixels) = .11;
saturationImage(greenPixels) = 1;
% Shift the value channel up to comparable what the value is for yellow pixels. Yellow is brighter.
meanV = mean(valueImage(greenPixels));
stDevV = std(valueImage(greenPixels));
valueImage(greenPixels) = valueImage(greenPixels) - meanV + 1 - stDevV;
% Now display the resulting image where the yellow pixels will be yellowr.
subplot(2, 2, 3);
imshow(saturationImage);
title('New Saturation Channel', 'FontSize', fontSize);
% Combine back to form new hsv image
hsvImage = cat(3, hueImage, saturationImage, valueImage);
% Convert back to RGB color space.
rgbImage = hsv2rgb(hsvImage);
subplot(2, 2, 4);
imshow(rgbImage);
title('RGB Image with Green Made Into Yellow', 'FontSize', fontSize);
hp = impixelinfo(); % Show RGB while they mouse around over the image.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!