Code covered by the BSD License  

Highlights from
Color Image Histogram

2.9

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

Color Image Histogram

by Jeff Mather

 

05 May 2004 (Updated 08 Nov 2010)

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  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (41)
07 Jul 2004 valla dafrel  
24 Jul 2004 feng Yang

asome

09 Dec 2004 reza saffari  
09 Dec 2004 reza saffari  
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

07 Jun 2005 Lahmar karim

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

17 Oct 2005 Arjan Gijsenij

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

29 Nov 2005 hanif mohammadi  
11 Mar 2006 Lei sheng  
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

24 May 2006 eman mehrabadi

log

21 Jun 2006 Jong-Cheon park  
12 Jul 2006 mohammed Alnafea  
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.

14 Aug 2006 gabrielle tuijthof  
31 Aug 2006 muthu krishnan

good

18 Sep 2006 Kevin Ostheimer

??? Invalid handle object.

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

19 Oct 2006 angry sam

doesn't work

08 Nov 2006 Syed Murtaza Hussain

Good one

09 Nov 2006 ayman nassar

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

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

25 Nov 2006 dolly jain

??? Invalid handle object.

Error in ==> rgbhist at 19

29 Nov 2006 KAsper HAnsen

Doesn't work.

02 Feb 2007 Mourad Oussalah  
30 Mar 2007 Bruce Banner

Not working

31 Mar 2007 Divya Seelan  
24 May 2007 Joao Silva  
17 Nov 2007 kubilay i?ci

hello

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

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

18 Feb 2008 keshamoni Divya  
02 Mar 2008 esraa ahmed  
21 Mar 2008 papu champu

good

22 Jun 2008 mustafa omar

no comment

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.

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

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

24 Jul 2010 Muhammad Nawaz

Excellent

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

06 Dec 2010 Ronny Meza

Very nice

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

30 Oct 2011 Dongni Zhang

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

Please login to add a comment or rating.
Updates
08 Nov 2010

BSD License

Tag Activity for this File
Tag Applied By Date/Time
color Jeff Mather 22 Oct 2008 07:19:04
rgbhist imhist color balance Jeff Mather 22 Oct 2008 07:19:04
rgbhist imhist color balance Abdulhakeem Othman 21 Jan 2010 02:19:46
color Abdulhakeem Othman 21 Jan 2010 02:19:46
color JIGNESH NATHANI 03 Mar 2010 00:43:18
color Muhammad Nawaz 24 Jul 2010 10:10:53
color Jipeng Xiong 01 Sep 2010 09:31:35
rgbhist imhist color balance Hussain Alamri 09 Nov 2010 17:09:07
rgbhist imhist color balance Akshay Jain 24 Nov 2010 08:03:35
color Akshay Jain 24 Nov 2010 08:03:39
invalid handle object GEC 27 Feb 2011 12:35:09
error in rgbhist at 20 GEC 27 Feb 2011 12:37:04
seth GEC 27 Feb 2011 12:37:04
marker GEC 27 Feb 2011 12:37:04
none GEC 27 Feb 2011 12:37:04
also ididnot get the different colors in a single histogrm GEC 27 Feb 2011 12:37:04
also ididnot get the different colors in a single histogrm shang yin 18 Mar 2011 03:29:11
color shang yin 18 Mar 2011 03:29:15
error in rgbhist at 20 shang yin 18 Mar 2011 03:29:18
also ididnot get the different colors in a single histogrm Valentin 01 Sep 2011 10:08:16
also ididnot get the different colors in a single histogrm navin 15 Nov 2011 13:13:04

Contact us at files@mathworks.com