How to get the value fo the two peaks of a histogram

How to get the value of the two peaks of a histogram
I have a program which do some calculations on an image by getting the membership value of pixels using fuzzy logic
this is not the part I'm asking about
the program is calculating this between (what it said ) the two peaks after getting the Image histogram
and for the cameraman Image it concidered the two peaks are 20 & 160 from the look at the histogram it seems that it's the value of the two obvious peaks there
what i need to know is how to get the two peaks using matlab ??
the two peaks of a Histogram ? if my interpretation is correct

 Accepted Answer

Look here http://fiji.sc/wiki/index.php/Auto_Threshold for a wide variety of autothresholding methods. There is no one single method that will be best for any and all types of histograms, that's why there are so many. Pick the one that works best for your types of images.

7 Comments

Thank you for the useful link
but i don't want other methods to threshold my Image I have a method using fuzzy logic, but my problem is that this method calculates the memebrship of the pixel between what it commented over it by "the two peaks of histogram" and for the cameraman method it was 20 & 160
and i said when i took the hist(CamramanImag) i found two obvious beaks of the bins at values 20 & 160 but i dont know how to get them using matlab code?
and so this is my question
It didnt make any process of the image, just hist(I) then got the two peaks value from it. how to do that?
Use the max() function on your histogram
[pixelCounts grayLevels] = imhist(grayImage);
[peakValue1 peakIndex1] = max(pixelCounts(1:thresholdValue));
[peakValue2 peakIndex2] = max(pixelCounts(thresholdValue:end));
Can't you just add this code to the end of your program?
[peakValue1 peakIndex1] = max(div_vec(1:p))
peakX1 = xval1(peakIndex1)
[peakValue2 peakIndex2] = max(div_vec(p+1:end))
peakX2 = xval1(peakIndex2 + p)
Image Analyst thank you for keeping up with me ... but the main point here what is the value of "p" ?? this is got through the two peaks, what i understood is that it concider that from the min: p is the background and from : max is the foreground
counting between the two peaks 20:160 how to get those two values from an image??? this is still not answered, this is just what i want, hoe to get the two peaks of any image to be able to run this program, if we want this for the popular "lena" image for example?
Well when I referred you to a bunch of auto threshold routines that you could try (to pick a value of p automatically), you acted like I didn't understand you because I was directing you to autothresholding methods when you really wanted the location of the peaks. So I gave you code to find the peaks, assuming you already had a thresholding method. So now I've given you both, but I'm still not sure why neither of those meets your needs.
Maybe my lack of knowledge to some concepts, I thank you Image Analyst & I'm testing the solutions you gave to me

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!