A: 

For 1:

i = imread('fabric.png');

r = sum(sum(i(:,:,1)))
g = sum(sum(i(:,:,2)))
b = sum(sum(i(:,:,3)))

bar([r g b])
MatlabDoug
This is not a histogram that I wanted. I want to write code that works like imhist.
Miko Kronn
+3  A: 

Here is my version of IMHIST:

I = imread('pic.jpg');
II = double(I);
clr = 'rgb'; clrTxt = {'Red' 'Green' 'Blue'};
for i=1:3
    h = subplot(3,1,i);
    c = histc(reshape(II(:,:,i),[],1), 0:255);
    bar(0:255, c./max(c), 'histc')
    set(gca, 'XLim', [0 255], 'YLim',[0 1])
    set(findobj(h,'Type','patch'), 'FaceColor',clr(i), 'EdgeColor','none')
    ylabel(clrTxt{i})
end
xlabel('Intensity')

alt text

Amro

related questions