MATLAB: Is this the right way to find local minima of histogram

finding minimum value peakshistogramimage histogram local minimaImage Processing Toolboxlocal minima

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.

Best Answer

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.