% imagehist1D % usage: imagehist1D(pic) % read a jpeg image and split into three RGB components % and show the histograms % pic is the name of a jpg file given in 'filename.jpg' format % typically the component images will be returned as matrices of byte-sized unsigned integers % allowing 256 levels for each colour, i.e., 24 bit colour % Rmap, Gmap and Bmap are colormaps for showing the R,G,B components function imagehist1D(pic,numbins); % load picture [R,G,B,Rmap,Gmap,Bmap] = jpg2rgb(pic,'nopic'); Z = zeros(size(R)); mc = double(max([R(:);G(:);B(:)])); [hR,xR] = hist(double(R(:)),numbins); [hG,xG] = hist(double(G(:)),numbins); [hB,xB] = hist(double(B(:)),numbins); mh = max([hR(:);hG(:);hB(:)]); % show images figure(1) clf imshow(cat(3,R,G,B)); pause figure(2) clf pause subplot(2,3,1) imshow(cat(3,R,Z,Z)); subplot(2,3,4) bar(xR,hR,1.0,'r'); axis([0,mc,0,mh+10]); pause subplot(2,3,2) imshow(cat(3,Z,G,Z)); subplot(2,3,5) bar(xG,hG,1.0,'g'); axis([0,mc,0,mh+10]); pause subplot(2,3,3) imshow(cat(3,Z,Z,B)); subplot(2,3,6) bar(xB,hB,1.0,'b'); axis([0,mc,0,mh+10]);