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.
Assuming your intensity values are all integers, you can do what you want as
What the above code does is it checks which element of
img
equalsvalue
and returns a Boolean vector that is1
if true and0
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 bynumel(img)
, where the functionnumel
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