R中矩阵的局部最大值

时间:2022-08-22 13:24:40

I would like to know if there is any function that will give a local maxima for matrix on a plane?

我想知道是否有任何函数可以为平面上的矩阵提供局部最大值?

I found one solution from

我发现了一个解决方案

Given a 2D numeric "height map" matrix in R, how can I find all local maxima?

给定R中的2D数字“高度图”矩阵,我如何找到所有局部最大值?

but it seems that there are some mistakes where for this line

但似乎这条线路存在一些错误

localmax <- focal(r, fun = f, pad=TRUE, padValue=NA)

localmax < - focal(r,fun = f,pad = TRUE,padValue = NA)

Error in focal(r, fun = f, pad = TRUE, padValue = NA) : argument "w" is missing

焦点错误(r,fun = f,pad = TRUE,padValue = NA):缺少参数“w”

Not sure on how to contact the person who gave the solution, so I just post it here

不确定如何联系提供解决方案的人,所以我只是在这里发布

Regards Aftar

关心Aftar

1 个解决方案

#1


1  

Personally I'd dump your matrix into imageJ to do this.
As another option, you might port this Matlab code http://www.mathworks.com/matlabcentral/fileexchange/37388-fast-2d-peak-finder . That module does some smoothing to improve the chance of finding "real" peaks in an image. IMHO local maxima only have meaning if the surface is smooth in the mathematical sense, i.e. everywhere differentiable.

我个人将你的矩阵转储到imageJ来做这件事。作为另一种选择,您可以移植此Matlab代码http://www.mathworks.com/matlabcentral/fileexchange/37388-fast-2d-peak-finder。该模块进行了一些平滑处理,以提高在图像中找到“真实”峰值的机会。如果表面在数学意义上是平滑的,即在任何地方都是可微的,则IMHO局部最大值仅具有意义。

#1


1  

Personally I'd dump your matrix into imageJ to do this.
As another option, you might port this Matlab code http://www.mathworks.com/matlabcentral/fileexchange/37388-fast-2d-peak-finder . That module does some smoothing to improve the chance of finding "real" peaks in an image. IMHO local maxima only have meaning if the surface is smooth in the mathematical sense, i.e. everywhere differentiable.

我个人将你的矩阵转储到imageJ来做这件事。作为另一种选择,您可以移植此Matlab代码http://www.mathworks.com/matlabcentral/fileexchange/37388-fast-2d-peak-finder。该模块进行了一些平滑处理,以提高在图像中找到“真实”峰值的机会。如果表面在数学意义上是平滑的,即在任何地方都是可微的,则IMHO局部最大值仅具有意义。