필터 지우기
필터 지우기

Finding the mean of a histogram

조회 수: 75 (최근 30일)
Denny Mannakulathil
Denny Mannakulathil 2020년 7월 12일
답변: Image Analyst 2020년 7월 12일
How can i find the mean of the histogram(R)?
clear;
im = imread('folders01.jpg');
figure(1); imshow(im); axis on;
[xP, yP] = ginput(4);
xP(5) = xP(1);
yP(5) = yP(1);
[x,y] = meshgrid(1:size(im,2),1:size(im,1));
xC = mean(xP); yC = mean(yP);
for i = 1:4
m = (yP(i+1) - yP(i)) / (xP(i+1) - xP(i));
b = yP(i) - xP(i) * m;
for j = 1:3
mask = im(:,:,j);
if(yC > xC * m + b)
mask(y<x*m+b) = 0;
else
mask(y>x*m+b) = 0;
end
im(:,:,j) = mask;
end
end
figure(2);
imshow(im);
R = im(:,:,1)
R = R(R ~= 0); R = R.';
figure(3);
subplot(3,1,1)
histogram(R)
xlim([0 260])
set(get(gca,'children'),'facecolor',[1 0 0])
set(get(gca,'children'),'edgecolor',[1 0 0])

답변 (2개)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 7월 12일
What do you mean by mean? The mean number of bins or the mean of the variables that the histogram represents? For the second you can just take the mean of R. For the first look at histogram properties and average the "values" property.

Image Analyst
Image Analyst 2020년 7월 12일
The mean of the histogram will not be as accurate as the mean of the image since it's quantized into bins. Here's an illustration:
grayImage = imread('cameraman.tif');
h = histogram(grayImage, 16) % 16 bins
grid on;
meanImageGL = mean2(grayImage)
grayLevels = h.BinEdges(1:end-1);
counts = h.Values;
meanBinnedGrayLevel = sum(grayLevels .* counts) / sum(counts)
xline(meanImageGL, 'Color', 'g', 'LineWidth', 2);
xline(meanBinnedGrayLevel, 'Color', 'r', 'LineWidth', 2);
% Or you could use the gray levels at the centers of the bins
centerBinGrayLevels = (h.BinEdges(1:end-1) + h.BinEdges(2:end)) / 2;
meanBinnedGrayLevel2 = sum(centerBinGrayLevels .* counts) / sum(counts)
You'll see
meanImageGL =
118.724487304688
meanBinnedGrayLevel =
110.93896484375
meanBinnedGrayLevel2 =
118.93896484375
So, which do you want?

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by