islocalmax2: problems understanding 'MinProminence'
Afficher commentaires plus anciens
I want to find local maxima in a 2D intensity image ("cell1.mat") and used the following strategy:
% load data
load('cell1.mat')
% edge preserving smoothing
ds = imbilatfilt(d, .01*(max(d(:))-min(d(:)))^2,10);
% find local max
[TF,P] = islocalmax2(ds,'MinProminence',2000,'MinSeparation',1,'ProminenceWindow',10);
myList = find(TF);
[row,col] = ind2sub(size(ds),myList);
The result can be visualized by
figure,
surf(dsz,'EdgeColor','none','FaceColor','interp');
colormap('jet')
hold on
for np=1:length(myList);
plot3(col(np),row(np),dsz(row(np),col(np)),'o','MarkerEdgeColor','b','MarkerFaceColor','none', 'MarkerSize',12);
end
axis tight
Now I wonder why islocalmax2 found so many small peaks unless I set the 'MinProminence' option to 2000.
Réponses (2)
Mathieu NOE
le 21 Mar 2025
hello
just fyi I tried with this fex submission (and no smoothing )
result : (6 peaks)

code :
load('cell1.mat')
d = double(d);
contourf(d)
colorbar
hold on
[pks,locs_y,locs_x]=peaks2(d,'MinPeakHeight',max(d(:))*0.75,'Threshold',max(d(:))*0.02);
for k = 1:numel(pks)
plot(locs_x(k),locs_y(k),'r+','markersize',15);
end
1 commentaire
another basic alternative , extracting contour lines x,y coordinates and plotting the centroids
load('cell1.mat')
d = double(d);
contourf(d,8)
colorbar
hold on
% extract isoclines
level = max(d(:))*0.75;
[C,h] = contour(d,level*[1 1]);
[m,n] = size(C);
ind = find(C(1,:)==level); % index of beginning of each isocline data in C
ind = [ind n+1]; % add end (+1)
for k = 1:numel(ind)-1
xc = C(1,ind(k)+1:ind(k+1)-1);
yc = C(2,ind(k)+1:ind(k+1)-1);
plot(xc,yc,'m');
% centroid
Xce = mean(xc);
Yce = mean(yc);
plot(Xce,Yce,'+r','markersize',15);
end
hold off
Andre Zeug
le 21 Mar 2025
0 votes
7 commentaires
As I run an older release (R2020b) I wasn't even aware that this function existed. It's nice to have functions with so many options but sometimes I just prefer simpler approaches (who said I am lazzy ?)
I aggree with you the right choice of parameters doesn't seem that easy to get the desired result (hence my remark above)
here for example, I would not have expected to get these 3 peaks ...
% load data
load('cell1.mat')
% edge preserving smoothing
ds = imbilatfilt(d, .01*(max(d(:))-min(d(:)))^2,10);
% find local max
[TF,P] = islocalmax2(ds,'MinProminence',2300,'MinSeparation',3,'ProminenceWindow',10);
maxP = sort(unique(P(:)),"descend")
myList = find(TF);
[row,col] = ind2sub(size(ds),myList);
figure,
% surf(ds,'EdgeColor','none','FaceColor','interp');
contourf(ds)
colormap('parula')
hold on
for np=1:length(myList);
plot(col(np),row(np),'+','MarkerEdgeColor','r', 'MarkerSize',15);
end
axis tight
so maybe with parameters "MaxNumExtrema" it's going to get easier :
well, no indeed :(
results are also very different if you choose ProminenceWindow = 10 or 100 (full size)
my conclusion : ok maybe one day I will use islocalmax2, but for the time being I am not 100% convinced...
% load data
load('cell1.mat')
% edge preserving smoothing
ds = imbilatfilt(d, .01*(max(d(:))-min(d(:)))^2,10);
% find local max
[TF,P] = islocalmax2(ds,'MaxNumExtrema',6,'MinSeparation',3,'ProminenceWindow',100);
myList = find(TF);
[row,col] = ind2sub(size(ds),myList);
figure,
% surf(ds,'EdgeColor','none','FaceColor','interp');
contourf(ds)
colormap('parula')
hold on
for np=1:length(myList);
plot(col(np),row(np),'+','MarkerEdgeColor','r', 'MarkerSize',15);
end
axis tight
Mathieu NOE
le 24 Mar 2025
Mathieu NOE
le 24 Mar 2025
and this : simple fast and effective . It ticks all my boxes

load('cell1.mat')
d = double(d);
contourf(d,8)
colorbar
hold on
[zmax,imax,~,~] = extrema2(d); % NB : maxima points in descending order (the bigger first and so on)
[yp,xp] = ind2sub(size(d),imax);
% select N peaks (descending order)
N = 6;
for k = 1:N
plot(xp(k),yp(k),'r+','markersize',15);
end
hold off
Mathieu NOE
le 2 Avr 2025
hello again
problem solved ?
Andre Zeug
le 13 Avr 2025
Mathieu NOE
le 14 Avr 2025
and what about using the other alternatives ?
Catégories
En savoir plus sur Multirate Signal Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


