Standard Deviation of an histogram

조회 수: 72 (최근 30일)
Pedro Silva
Pedro Silva 2022년 12월 7일
댓글: Abdelaaziz 2023년 10월 5일
Hello,
I am trying to obtain histogram parameters from an image. I’ve also ran this image through ImageJ’s histogram function to know the correct values to expect.
I’ve transformed the image to a gray-scale image (using rgb2gray), plotted the histogram (using imshow), obtained the values for the histogram using [COUNTS,X] = imhist(Sample).
For the mean, multiplying each bin number per its frequency I am able to correctly obtain the mean value of the histogram ((bin vs frequency)/nr of pixels), but when trying to calculate the standard deviation I am unable to get the correct value.
I’ve already tried to use the bult in standard deviation of matlab, and also calculating the standard deviation manually (calculating intensity (bin vs frequency), calculating the mean, and applying the usual standard deviation formula), but the results is orders of magnitude higher than what is expected,
What function/code should I be using to obtain the standard deviation?
Any suggestions?
Example of sample attached, and also the imageJ histogram:
Thanks!
  댓글 수: 1
Abdelaaziz
Abdelaaziz 2023년 10월 5일
Hi Pedro. I have the Same Projekt. Did you finde hier to lose this Problem ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2022년 12월 7일
You don't want the standard deviation of the histogram. You want the standard deviation of the pixel intensities in the image. You can calculate that as simply as:
meanSample = mean(Sample(:));
stdSample = std(Sample(:));
You can also estimate these characteristics from the histogram:
[COUNTS,X] = imhist(Sample);
mS = sum(COUNTS.*X)/sum(COUNTS); % Identical to how you calculate the centre of mass.
stdS = sqrt(sum(COUNTS.*(X-mS).^2)/sum(COUNTS));
That would also give you an estimate of the standard deviation - you could compare this to the second moment of any distribution (or square-root of that). But here you might have lost some precision in that estimate since you have discretized the intensities - to the centres of the bins.
HTH
  댓글 수: 3
Bjorn Gustavsson
Bjorn Gustavsson 2022년 12월 8일
Good. You can also use the 'all' flag to mean and std, I forgot about that "new" capabillity...
Image Analyst
Image Analyst 2022년 12월 8일
Like @Bjorn Gustavsson says, the standard deviation of the histogram bin counts is an entirely different thing than the standard deviation of the actual individual pixel gray levels. I hope you realize that now. One is the stdev of counts while the other is stdev of gray levels - totally different.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by