Find a local max and local min of a surface with noise

8 views (last 30 days)
I got the matrix above How can I find de MAXIMUM & MINIMUM locals and put the X,Y coodinate into a vector X and a vector Y and when i plot X vs Y o got the dots representating the maximum and minumum values with different color for max and min ps. remember to consider the noise
A=[0.5000 -0.2668 -0.4606 -0.0866 -0.1433 -0.2063 0.0020 -0.0684 0.0824 0.0618; -0.0700 -0.1001 -0.6211 -2.0000 -0.6901 -0.5352 -0.5370 0.6527 -0.4742 -0.2398; -0.0159 0.1090 0.0902 -0.3513 -0.5579 -0.2559 -0.1088 0.2090 -0.1592 0.0290; 0.3378 0.3437 0.4101 0.4995 0.3286 0.1963 0.0434 0.1998 0.2853 0.3430; 0.3673 0.3320 0.2836 0.3189 0.3596 0.1729 0.0493 0.2758 0.2314 0.3171; -0.7621 -0.5151 -0.3759 -0.1816 0.1758 0.0306 -0.4316 0.1782 -3.0051 -1.9493; -0.0107 -0.1784 -0.0642 -0.1268 -0.0137 0.0840 -0.1945 0.0944 -0.1449 -0.0296; 0.2212 0.1060 0.0321 3.0020 0.1965 -0.0060 0.0472 0.1958 0.1850 0.3266; 0.1410 0.2704 0.1225 0.2163 0.0337 0.1676 0.1012 0.1511 0.1105 0.3585; 0.1301 0.2741 0.0495 0.0251 0.1299 0.2433 0.0284 0.0727 0.1462 0.1443 ;]
  2 Comments
Rafael Freire
Rafael Freire on 21 Apr 2011
I'm not doing the right way.
i made a isocut in the max an min values using this function that 1 create
function [modecut1,modecut_1]=modecut(X,i);
tic;
modecut1 = X;
modecut_1 = X;
modeX = mode ( mode(X) );
modecut_1 (modecut_1 >= modeX * i & modecut_1 <= -modeX * i ) = 0;
modecut_1 (modecut_1 > 0 ) = 256;
modecut_1 (modecut_1 < 0 ) = -256;
Than i use bwlabel an calculate the centroids of the points.
but one problem of that is when i have 2 max nearby for this way i will consider one max only, so i'm loosing important information.

Sign in to comment.

Accepted Answer

Rafael Freire
Rafael Freire on 29 Apr 2011
I use a function extrema2 to do that and works here is the link http://www.mathworks.com/matlabcentral/fileexchange/12275-extrema-m-extrema2-m/content/extrema/extrema2.m and the code I use
z=crop;
[zmax,imax,zmin,imin] = extrema2(z,1);
[m,n]=size(crop);
y=1:m;
x=1:n;
[x,y]=meshgrid(x,y);
crop(crop<=10)=nan
figure
hold on
plot3(x(imax),y(imax),zmax,'bo',x(imin),y(imin),zmin,'ro')
for i = 1:length(zmax)
text(x(imax(i)),y(imax(i)),zmax(i),[' ' num2str(zmax(i))])
end
for i = 1:length(zmin)
text(x(imin(i)),y(imin(i)),zmin(i),[' ' num2str(zmin(i))])
end
hold off
hold on
surf(crop)

More Answers (2)

bym
bym on 21 Apr 2011
I am not sure I understand your question but is
imagesc(A)
what you are looking for?
  1 Comment
Rafael Freire
Rafael Freire on 24 Apr 2011
I'm looking for a values (linear indexing) of the points where is the max of the curves, but I have a lot of maximuns and minimuns in my surface...
This function that you pass helps me in another part of my work.
Thanks anyway

Sign in to comment.


Walter Roberson
Walter Roberson on 22 Apr 2011
On a discrete surface, every point is both a local max and local min -- at least until you define your neighborhood. If you want noise to be taken in to account, you also have to define either a noise detection function (if you want to ignore points with noise) or a smoothing function.
You also need to define the behaviour you want for saddle-points, that are local min in one direction but local max in another.
You might want to use gradient() perhaps.
  4 Comments
Walter Roberson
Walter Roberson on 25 Apr 2011
Post the images on a service such as tinypic or imageshack and post the URL here.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!