Code covered by the BSD License  

Highlights from
Color Image Histogram

2.9

2.9 | 31 ratings Rate this file 58 Downloads (last 30 days) File Size: 1.23 KB File ID: #4875
image thumbnail

Color Image Histogram

by

 

05 May 2004 (Updated )

Display a histogram showing the color balance of an image.

| Watch this File

File Information
Description

RGBHIST displays a histogram of the overall color balance of an image.

Use the 'RGB' mode to get a quick sense of which colors are present in particular highlight, shadow, and midtone regions. The 'LAB' mode is more useful for determining the actual color balance of an image, but it is slower.

This function supports UINT8, UINT16, INT8, INT16, and DOUBLE images without colormaps.

Required Products Image Processing Toolbox
MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (48)
26 May 2014 Saleha Samad

i want to extract the value that is maximum for a color pixel of an object , how can i get that ???

30 Jul 2013 Yong

I test that h(1) = stem(1:256, rHist); hold on
h(2) = stem(1:256 , gHist);
h(3) = stem(1:256 , bHist);
hold off can achieve the same result. so it need not to use h(2) = stem(1:256 + 1/3, gHist,'g');
h(3) = stem(1:256 + 2/3, bHist),'b';
and we can use this command result = (1:256)==(1:256 + 1/3) to test, and it is just the same

14 Jun 2013 shashi

How Can I read the Color of an Image with Some Pixel Values ?

I want to change the color of that particular Pixel color to another Color ?

08 Apr 2013 tamanna

hey, can anybody tel me that what '1/3' signifies in
'stem(1:256 + 1/3, gHist,'g'); '
statement

18 Jan 2013 nsit

thank u sir..it worked!

07 Dec 2012 John Diaz

solution to problem set(h, 'marker', 'none')

function varargout = rgbhist(I)
%RGBHIST Histogram of RGB values.

if (size(I, 3) ~= 3)
error('rgbhist:numberOfSamples', 'Input image must be RGB.')
end

nBins = 256;

rHist = imhist(I(:,:,1), nBins);
gHist = imhist(I(:,:,2), nBins);
bHist = imhist(I(:,:,3), nBins);

hFig = figure;
hold on
h(1) = stem(1:256, rHist,'r');
h(2) = stem(1:256 + 1/3, gHist,'g');
h(3) = stem(1:256 + 2/3, bHist),'b';

% I like more without "set" but also function whit "set"
%set(h, 'marker', 'none')
%set(h(1), 'color', [1 0 0])
%set(h(2), 'color', [0 1 0])
%set(h(3), 'color', [0 0 1])

01 Apr 2012 adam

Nice work Jess !

30 Oct 2011 Dongni Zhang

It works well with the modification of Jeff in 29 Apr 2011. Thank you!

29 Apr 2011 Jess

My modification on Jeff's initial code (including comment by Tomasz). Now input image & histogram derived are display in same figure window.

function rgbhist(I)
%RGBHIST Histogram of RGB values.

if (size(I, 3) ~= 3)
error('rgbhist:numberOfSamples', 'Input image must be RGB.')
end

nBins = 256;

rHist = imhist(I(:,:,1), nBins);
gHist = imhist(I(:,:,2), nBins);
bHist = imhist(I(:,:,3), nBins);

%hFig = figure;

figure
subplot(1,2,1);imshow(I)
subplot(1,2,2);

h(1) = stem(1:256, rHist); hold on
h(2) = stem(1:256 + 1/3, gHist);
h(3) = stem(1:256 + 2/3, bHist);
hold off

set(h, 'marker', 'none')
set(h(1), 'color', [1 0 0])
set(h(2), 'color', [0 1 0])
set(h(3), 'color', [0 0 1])
axis square

06 Dec 2010 Ronny Meza

Very nice

01 Sep 2010 Tomasz

stem(1:256, rHist,'r');hold on
stem(1:256 + 1/3, gHist,'g');
stem(1:256 + 2/3, bHist,'b');
hold off

24 Jul 2010 Muhammad Nawaz

Excellent

04 Aug 2009 muhammad ashraf

Respected Sir, ho to solve tis problem?
it gives the following error
??? Invalid handle object.

Error in ==> rgbhist at 19
set(h, 'marker', 'none'
please help me how can i make color imag histogram?
thanks

04 Aug 2009 muhammad ashraf

Respected Sir,
I am having error with your code.following is the error
??? Invalid handle object.

Error in ==> rgbhist at 19
set(h, 'marker', 'none')

Sir please tell how can i make histogram of color imag in matlab.
thanks

06 Oct 2008 Sakthi Kandan

Hello
In the above program how to get an image,is there any special syntax has to be used to get an image.
I used the syntax
I=imread('lena.jpg') ;
But it's giving me error.
Is there any special syntax to get the RGB image.

22 Jun 2008 mustafa omar

no comment

21 Mar 2008 papu champu

good

02 Mar 2008 esraa ahmed  
18 Feb 2008 keshamoni Divya  
19 Dec 2007 santosh saraf

Sir,

when u convert rgb2hsi we get an hsi component image. Sir, can i treat the h matrix as an image

Please reply

20 Nov 2007 hanan yaseen

please sir can you explain the steps of the program to me? is it an intersection of the histograms of all the colors in the image or what exactly?
i hope you can respond me or any one who understand this program can explain it to me
i will be very thankful

17 Nov 2007 kubilay i?ci

hello

24 May 2007 Joao Silva  
31 Mar 2007 Divya Seelan  
30 Mar 2007 Bruce Banner

Not working

02 Feb 2007 Mourad Oussalah  
29 Nov 2006 KAsper HAnsen

Doesn't work.

25 Nov 2006 dolly jain

??? Invalid handle object.

Error in ==> rgbhist at 19

09 Nov 2006 ayman nassar

it gives the following error
??? Invalid handle object.

Error in ==> rgbhist at 19
set(h, 'marker', 'none'

08 Nov 2006 Syed Murtaza Hussain

Good one

19 Oct 2006 angry sam

doesn't work

18 Sep 2006 Kevin Ostheimer

??? Invalid handle object.

Error in ==> rgbhist at 19
set(h, 'marker', 'none')

31 Aug 2006 muthu krishnan

good

14 Aug 2006 gabrielle tuijthof  
20 Jul 2006 Mark Hayworth

This doesn't work in R14/2006a (and I doubt it did in his version either), or at least it needs fixing. It produces a stem plot, not a plot like his screenshot shows. And the stem plot is only for the B channel because he forgot to issue a HOLD command after the line h(1) = stem(1:256, rHist); so the green blows away the red plot, and the blue blows away the green plot so that only the blue stem plot is there after all is said and done. Finally, there is nothing in this macro about different color spaces, RGB or LAB, no radio buttons to select between them, in fact, no user interface at all.

12 Jul 2006 mohammed Alnafea  
21 Jun 2006 Jong-Cheon park  
24 May 2006 eman mehrabadi

log

12 Mar 2006 Maria Gorlatova

Does not work. Error: In an assignment A(I) = B, the number of elements in B and
I must be the same.

Must be something version-dependent

11 Mar 2006 Lei sheng  
29 Nov 2005 hanif mohammadi  
17 Oct 2005 Arjan Gijsenij

Error: In an assignment A(I) = B, the number of elements in B and
I must be the same.

07 Jun 2005 Lahmar karim

??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

27 Dec 2004 visesh Jeetoo

It does seem to give the following error" In an assignment A(I) = B, the number of elements in B and I must be the same" when trying to find the histogram of a 256x256 colour image

09 Dec 2004 reza saffari  
09 Dec 2004 reza saffari  
24 Jul 2004 feng Yang

asome

07 Jul 2004 valla dafrel  
Updates
08 Nov 2010

BSD License

Contact us