4D Matrix Local Maxima

10 visualizzazioni (ultimi 30 giorni)
Ethan Turk
Ethan Turk il 24 Ott 2014
Modificato: Ethan Turk il 24 Ott 2014
Hi All,
Here is my question. I have a 4D matrix with values. I.e. grids = zeros (10, 10, 100, 100). For each of the coordinates of this matrix we have values. I.e. grids(1,4,30,40) == 1223.3. Now I want to find the local maximas for this matrix. I used imregionalmax function but the function uses a connectivity which assumes all dimensions have the same length (for 2D it uses 8 pixel connectivity). Thus although it returns the true local maximas, it also returns many redundant values as well. My question is that is there any way to find the local maxima for matrices. Thanks.
Here is how I used the imregionalmax:
  • localMaxima = imregionalmax(grids);
  • linInd = find (localMaxima);
  • LRvals = grids (linInd);
  • [indx, indy, inz, int] = ind2sub(size(localMaxima), find(localMaxima));
  • indicesLR = [indx, indy, inz, int];
  • finalResult = [indicesLR, LRvals];
Here is and example of the output: The first two dimensions of my matrix represents a location and the other two represents the distance. My result set is like below but I don't want to see the redundant ones. I only want the number 2,4 in the list below.
Local Maxima Result List
  1. [5,5,23,28] = 10233
  2. [5,5,24,27] = 12111
  3. [5,5,22,29] = 9989
  4. [5,5,31,44] = 14242
  5. [5,5,37,43] = 13288

Risposte (2)

Image Analyst
Image Analyst il 24 Ott 2014
imregionalmax() does not find local max everywhere , it only finds pixels that ARE the local max. If you don't understand the difference, let me know. To find the local max for every location, you need imdilate().

Ethan Turk
Ethan Turk il 24 Ott 2014
Modificato: Ethan Turk il 24 Ott 2014
I know the difference but in this case imregionalmax returns these lines because they are not imdilate neighbors. I checked immediate before but it is limited to a two dimensional image and I don't think it will give the results I need. The funny thing is when I change my matrix size to zeros(100,100,100,100) it works without any problem but it takes so much time (my matrix is much larger than the example here). As you can see from the result I wrote, the only reason these two
  1. [5,5,23,28] = 10233
  2. [5,5,24,27] = 12111
comes is that they are not immediate neighbors.

Community Treasure Hunt

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

Start Hunting!

Translated by