问题
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