is this the right way to find local minima of histogram

hi, I am trying to find the local minima value of image's histogram, I am filtering image from 1*3 filter and then finding minima, waiting for your suggestions
I = imread('eight.tif');I=I(:)';I=double(I);
x=[1 1 1]/3;
f=filter2(x,I,'same');
y = sin(5*f);
idx = [false, y(3:end)>y(2:end-1) & y(2:end-1)<y(1:end-2), false];
xmin = f(idx)
plot(xmin,'o-')
thanks in Advance.

 Réponse acceptée

Walter Roberson
Walter Roberson le 8 Nov 2013

0 votes

Not so bad, but remember
  1. you might match multiple local minima
  2. you are going to plot all the local minima adjacent to each other, not their original distance apart
  3. you are going to have trouble if the pattern is \__/ instead of \_/ i.e., if the local min is more than one point wide
  4. you might want to think about using diff()
  5. local min could occur at the endpoints -- with your current code, a continually-decreasing or -increasing set of data would not register any local min.

7 commentaires

@Walter, very Precise Answer, All of the analysis upto the mark, can you suggest some solution to problem also. Because I dont have idea how i can use Diff() for this Purpose is there any example. Thanks
If you have a diff() of a numeric array, then any consecutive run of values that are non-negative is part of a descent towards a local minima, and the moment you see a positive value in the diff you are out of the local minima, So...
diff(SOMETHING) <= 0
will be true in runs towards the local minima, and false at the place the local minima ends. So look through the logical vector for the pattern [true, false]
@Walter, very kind you are, Please let me know one thing what shoud I input to the diff, for example
I=imread('a.jpg');
[count bin]=imhist(I)
plot(diff(count)<=0)
then what information it is giving to me, I think i am wrong,please give me one more chance to understand this situation. Thanks
count <= 0 will give you the logical array. Now you need to find the places in that array that have a true followed by a false: those will be the places where local minima occur. There are different ways you can locate the pattern; one of the ways is by using find()
find(L(1:end-1) & ~L(2:end))
@Walter thank you for your valueable answers.
@walter what is L here
"count <= 0 will give you the logical array" and that is what he calls L.

Connectez-vous pour commenter.

Plus de réponses (1)

Way too complicated for me. Actually I didn't even see you take the histogram, which you do with imhist(). I'm not sure what you're doing with the sine wave. Why not just use imhist() and imregionalmin()? It's much more straightforward and only 2 lines of code.
[counts, grayLevels] = imhist(I); % Get histogram into "counts"
minIndexes = imregionalmin(counts); % Find indexes of local mins in the histogram.
To get the gray levels instead of the indexes, you need to subtract 1 because index 1 is actually gray level 0.
grayLevelsAtLocalMins = minIndexes - 1;

1 commentaire

@Image Analyst, I am sorry but I did not understand, that plot(grayLevelsAtLocalMins,'-o'), give what information, because its shows a strange number of lines can you please elaborate more that how I could get regionalmin points.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by