Matlab - Determine the probability of an Intensity

2019-07-13 16:04发布

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条回答
小情绪 Triste *
2楼-- · 2019-07-13 16:28

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);
查看更多
登录 后发表回答