图像的MATLAB高斯分布的总和大于1 [英] Sum of MATLAB Gaussian distribution of an image is greater than 1

查看:161
本文介绍了图像的MATLAB高斯分布的总和大于1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码来计算下面给出的图像的像素强度的概率.但是,概率总和sum(sum(probOfPixelIntensities))大于1.

I am using the below code to calculate the probabilities of pixel intensities for the image given below. However, the total sum of probabilities sum(sum(probOfPixelIntensities)) is greater than 1.

我不确定错误可能在哪里.任何帮助弄清楚这一点将不胜感激.预先感谢.

I'm not sure where the mistake may be. Any help in figuring this out would be greatly appreciated. Thanks in advance.

clear all
clc
close all
I = imread('Images/cameraman.jpg');
I = rgb2gray(I);
imshow(I)
muHist = 134;
sigmaHist = 54;
Iprob = normpdf(double(I), muHist, sigmaHist);
sum(sum(Iprob))

推荐答案

您正在做的是计算图像中每个像素的PDF值. Iprob不是正态分布,但您只是在使用图像像素从已知均值和标准偏差的分布中采样.

What you are doing is computing the PDF values for every pixel in the image. Iprob is not a normal distribution but you are simply using the image pixels to sample from the distribution of a known mean and standard deviation.

基本上,您只是在进行数据转换,将图像像素强度映射到具有已知平均值和标准偏差的普通PDF上的值. 与PDF相同,这就是为什么总和不为1的原因.最重要的是,图像像素强度甚至不遵循正态分布,因此不会有任何方式分布的总和是1.

Essentially, you are just performing a data transformation where the image pixel intensities get mapped to values on a normal PDF with a known mean and standard deviation. This is not the same as a PDF and that's why the sum is not 1. On top of this, the image pixel intensities don't even follow a normal distribution itself so there wouldn't be any way that the sum of the distribution is 1.

除了normpdf的输出之外,没有什么比您期望的要多的了.您应该选择更仔细地阅读normpdf的文档: http://www.mathworks .com/help/stats/normpdf.html

Not much more to say other than the output of normpdf is not what you are expecting it to be. You should opt to read the documentation of normpdf more carefully: http://www.mathworks.com/help/stats/normpdf.html

如果您希望确定图像的实际PDF,则需要做的是找到图像的直方图,而不进行数据转换.您可以使用 imhist 做到这一点.完成此操作后,假设遇到强度是等概率的,您可以将每个直方图条目除以除以图像的总大小,然后沿所有bin求和.在这种情况下,您应该将总和设为1.

If it is your desire to determine the actual PDF of the image, what you need to do is find the histogram of the image, and not do a data transformation. You can do that with imhist. Once you do that, assuming that encountering the intensities is equiprobable, you would divide each histogram entry by the total size of the image and then sum along all bins. You should get the sum to be 1 in this case.

为了验证,我们使用您在帖子中提供的图像.我们将从StackOverflow中阅读此内容.完成后,计算PDF,然后对所有bin求和:

Just to verify, let's use the image you provided in your post. We'll read this in from StackOverflow. Once we do that, compute the PDF and then sum over all bins:

%// Load in image
im = rgb2gray(imread('http://i.stack.imgur.com/0XiU5.jpg'));

%// Compute PDF
h = imhist(im) / numel(im);

%// Sum over all bins
fprintf('Total sum over all bins is: %f\n', sum(h));

我们得到:

Total sum over all bins is: 1.000000

请务必确保您理解,这是图片的PDF.您之前所做的是执行数据转换,在该数据转换中,所有图像像素强度都以已知的均值和标准偏差转换为符合高斯分布的图像. 不会会给您总计1的期望值.

Just to be absolutely sure you understand, this is the PDF of the image. What you did before was perform a data transformation where you transformed all image pixel intensities that conforms to a Gaussian distribution with a known mean and standard deviation. This will not give you a sum of 1 as you expect.

这篇关于图像的MATLAB高斯分布的总和大于1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆