ffttyy
ffttyy

Reputation: 864

Finding gray level which most of pixels have

enter image description here

Hi, I have a histogram is shown above. I used imhist(I) function to get this histogram. I want to find the gray level which most of pixels have. Is it possible to find this value?

Upvotes: 0

Views: 1028

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112749

You can use the two outputs of imhist to obtain gray levels and count of each level. Use then the second output of max to obtain the index of the level whose count is maximum. Finally, the result is the level with that index.

[count levels] = imhist(I); %// get levels and count of each level
[~, v] = max(count); %// v is the index corresponding to maximum count
result = levels(v); %// the result is the level that has that index

Upvotes: 3

Related Questions