Matlab - Determine the probability of an Intensity Value

此生再无相见时 提交于 2019-12-24 03:04:40

问题


How do you determine the probability that an intensity value appears in an image in Matlab or is there some other way to determine it? The mathematical equation is

Pr = Nk / M*N

Where Pr is the probability, Nk is number of times that a Kth intensity appears in the image. M*N represents the MxN image.


回答1:


Assuming your intensity values are all integers, you can do what you want as

Pr=nnz(img(:)==value)/numel(img);      %# here img is your image, value is the intensity

What the above code does is it checks which element of img equals value and returns a Boolean vector that is 1 if true and 0 if false. nnz is a function that returns the number of non-zero elements (in this case, instances where the condition is true). This is then divided by numel(img), where the function numel gives the number of elements in the image.

However, if your values are not integers, then you will have to implement the equality check within a certain tolerance limit, tol, as

Pr=nnz(img(:)<=value+tol & img(:)>=value-tol)/numel(img);


来源:https://stackoverflow.com/questions/5985395/matlab-determine-the-probability-of-an-intensity-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!