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

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

What have you done so far?
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

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)

I am not sure I understand your question but is
imagesc(A)
what you are looking for?

1 Comment

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.

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

I'am very new in this business I only work with matlab since february(2011) and I don´t know the right term to design the functions and the technical language , I think I'm made mistakes sorry for that.
I tried to use the gradient and then I plot a quiver graph, it's was clearly visible the "valleys"(min) or "montains"(max) in my 2D surface but after that i stucked.
You sad in one of my questions to use the isocut, but when you have peaks very close to each other they compute as only one, and then i lost precious information. In one of my cases, I got a region of 10x10 points that has a 5 max but 3 of them is really close to each other. I can do it by hand but i have almos 500 surfaces to do that.....so..its impossible done by hand...
Anyway i appreciate the attention and kindness
Best regards
I suggested isosurface as a possibility in the situation where all the peaks were the same height, not in the situation where the peaks are different heights.
I think you should post a couple of images, one of them with the raw values, and the other of them marked to show where you consider the peaks to be; the sample image should include examples of the noise you mentioned and the marked-up image should show an example of a peak that should be ignored or moved because it is considered to be noise or artificially enhanced by noise.
How i can post images here?
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!