how to find mean of a histogram?

6 次查看(过去 30 天)
first I want to ask whether it is same between the mean of histogram and mean of matrix.
i want to find mean of histogram which of this coding is correct?
coding 1
R=rgb1(:,:,1);
I2=histeq(R);
pixel_values_R=single(I2);
mean_r=mean(pixel_values_R(:))
coding 2
[counts_R,binsLocation_R]= imhist(R);
image_mean_R=sum(counts_R.*binsLocation_R)/sum(counts_R)
thank you in advance
  1 个评论
Walter Roberson
Walter Roberson 2015-5-8
What is the data type of the image? Is it uint8() or is it a different integer type or is it double precision?

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2015-5-8
The mean of the matrix will of course be the most accurate. If you take the mean of the histogram, it will assume that all elements in that bin have the value of the bin center, which is, of course, not true in general.
  3 个评论
Image Analyst
Image Analyst 2015-5-8
True. Of course with his code, he's not even taking the histogram of the same thing! In "coding 1" he's taking the histogram of the histogram equalized image I2 whereas in "coding 2" he's taking the histogram of the original image. So, while the bins will have the same height (counts), they are shifted to a new gray level location and so the mean will change.
As a side note, there is a function mean2() that the poster may want to know about so you don't have to do (:), though that probably doesn't add much time.
Side note 2: histogram equalization is rarely needed and often produces unnatural-looking images. They can be a lot worse than just doing a simple linear stretch with imadjust() or mat2gray(). I've never needed to use a global histogram equalization in almost 4 decades of developing image analysis algorithms.
Walter Roberson
Walter Roberson 2015-5-8
I wasn't going to try to explain the evils of taking the mean of the histogram equalized image until the poster put a bit more effort into the question.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by