Can you use islocalmax2 for a nxnxn grid where the values of that grid correspond to peaks in data density?

1 view (last 30 days)
I am trying to pickout peaks of data density. I fit my data to a kernel density estimation using the mvksdensity function.
I then get a matrix, Z, the size of my grid where the values correspond to the density of the data in the 3D variable space.
My question is, can I use islocalmax2 to pick out peaks in this nxnxn matrix Z, or does it only work in 2 dimensional arrays.
The documentation lists the input data can be a multidimensional array, though I'm not sure if it works with a page size greater than 1.
My goal is to calculate the prominence of of these peaks as well so if anyone has any resources related to that in more than 2 dimensions, that would be very helpful.
I've also used the imregional max function from the image processing toolbox, but the user doesn't have control over any parameters for the peaks.

Answers (1)

Milan Bansal
Milan Bansal on 2 May 2024
Edited: Milan Bansal on 2 May 2024
Hi Poison Idea fan,
The function islocalmax2 is compatible with multidimensional arrays, that means you can use it to get the peaks in the n x n x n matrix "Z" as well. The function will return the output as a 3 dimensional "logical" array with same size as that of "Z". The function will find local maximas for each 2-D layer (n x n) in "Z".
A = rand(100, 100, 100); % create a random 3D matrix of size 100 x 100 x 100
TF = islocalmax2(A);
size(TF)
ans = 1x3
100 100 100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
You can also calculate the "prominence" using the same function as shown below.
[TF, P] = islocalmax2(A); % P is the prominence
Please refer to the following documentation link to learn more about islocalmax2 function.
Hope this helps!
  1 Comment
Poison Idea fan
Poison Idea fan on 2 May 2024
Hi Milan,
The issue for me is that it's finding the LM for each layer and not considering the relative values in the Z direction. Unless you have a way to suggest taking the maxima of each 2D layer and comparing them somehow, I am still stuck.
PIF

Sign in to comment.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!