フィルターのクリア

how to find mean of a histogram?

6 ビュー (過去 30 日間)
nurul hafizah
nurul hafizah 2015 年 5 月 8 日
コメント済み: Walter Roberson 2015 年 5 月 8 日
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 Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by