Local maxima in a matrix

7 Ansichten (letzte 30 Tage)
Ryan
Ryan am 29 Nov. 2014
Beantwortet: Image Analyst am 29 Nov. 2014
I need to locate the peaks and valleys of numbers given in a large matrix. I need to compare a value in the matrix with the 8 surrounding values to determine if it is either a peak (maximum) or a valley (minimum). The matrix that I am using is 100X100 and the coordinates of the value will then need to be displayed in a table. For example: [3 6 2 5; 4 9 1 5; 7 3 5 4] has a peak of 9 at (2,2) and a valley of 1 at (3,2). Any ideas would be greatly appreciated.

Akzeptierte Antwort

Image Analyst
Image Analyst am 29 Nov. 2014
If you have the IMage Processing Toolbox, you are really in luck because there are two functions meant for exactly this situation: imregionalmax() and imregionalmin(). Here is how to use them:
grayImage = [3 6 2 5; 4 9 1 5; 7 3 5 4]
regionalMaxima = imregionalmax(grayImage)
regionalMinima = imregionalmin(grayImage)
In the command window, observe the results:
grayImage =
3 6 2 5
4 9 1 5
7 3 5 4
regionalMaxima =
0 0 0 0
0 1 0 0
0 0 0 0
regionalMinima =
1 0 0 0
0 0 1 0
0 0 0 0
If you want rows and columns of the max or mins, just use find():
[rows, columns] = find(regionalMaxima)
rows =
2
columns =
2

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 29 Nov. 2014
Bearbeitet: Azzi Abdelmalek am 29 Nov. 2014
a=[3 6 2 5; 4 9 1 5; 7 3 5 4]
n=size(a);
[mina,idx1]=min(a(:))
[ii1,jj1]=ind2sub(n,idx1)
[maxa,idx2]=max(a(:))
[ii2,jj2]=ind2sub(n,idx2)
  1 Kommentar
Mohammad Abouali
Mohammad Abouali am 29 Nov. 2014
Bearbeitet: Mohammad Abouali am 29 Nov. 2014
This is not the answer. This gives the global min/max. He is asking for local one.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by