필터 지우기
필터 지우기

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 CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by