Miko Kronn
Miko Kronn

Reputation: 2454

How do I re implement a color based histogram, do feature extraction based on color & measure features in an image in MATLAB?

For this picture:

  1. Draw histogram of R, G, B components of color (not using imhist)
  2. Change picture to binary so brown exoskeleton of insect is white
  3. Measure insect's exoskeleton's width and height

EDIT:

1: I did that:

a = imread('C:\a.jpg');
r = a(:,:,1);
g = a(:,:,2);
b = a(:,:,3);
rhist = zeros(1,256);
[w h] = size(a(:,:,1));
for i=1:w
    for j=1:h
        rhist(r(i,j)+1) = rhist(r(i,j)+1)+1;
    end
end

rhist(x) is count of red intensity that is equal to x-1

Now I just need a little help how to draw this data as a histogram

2: Still, have no idea :(. I'm using im2bw with different second argument but that does not help.
I'm guessing that some blur might help?
3: No idea, too.

Upvotes: 1

Views: 2556

Answers (2)

Amro
Amro

Reputation: 124563

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

Upvotes: 3

MatlabDoug
MatlabDoug

Reputation: 5714

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])

Upvotes: 0

Related Questions