如何得到灰度像素频率分布的平均值和标准差?

时间:2018-04-11 07:31:43

标签: matlab frequency-distribution

我想在matlab中有关频率分布的帮助,如何获得灰度像素的频率分布的平均值和标准差,如何在matlab中做到这一点...请任何想法来帮助我

1 个答案:

答案 0 :(得分:0)

你的问题有些令人困惑 - 也许这会有所帮助。我创建了一个示例图像,找到了唯一的"像素"在该图像中的值,找到每个唯一值的频率(即,在图像中出现该值的次数),计算平均像素值,并找到像素频率的标准偏差。

img = randi(20, 20); % example grayscale image
uniq = unique(img); % all the unique pixel values in the image

for i = 1:length(uniq)
    freq(i) = length(find(img == uniq(i))); % find the frequency of the unique pixels in the image
end

printf("Value\tFrequency\n");
for i = 1:length(uniq)
    printf("%d\t%d\n", uniq(i), freq(i));
end

average = sum(freq)/length(freq) % average pixel frequency
stddev = std(freq) % standard deviation of pixel frequency

输出:

Value   Frequency
1       24
2       17
3       19
4       15
5       19
6       23
7       21
8       21
9       16
10      16
11      15
12      20
13      21
14      16
15      23
16      29
17      20
18      29
19      21
20      15
average =  20 
stddev =  4.1927