我在Python2.7中有一个numpy数组,我使用imshow()函数将其可视化。生成数组的代码如下所示:
from pylab import *
r0 = 3.0
S0 = 10.0
x = zeros((101,101))
noiseimg = zeros((101,101))
for i in range(101):
for j in range(101):
noiseimg[i,j] = noiseimg[i,j] + normal(3,1)
mean_i = randint(0,101)
mean_j = randint(0,101)
for i in range(101):
for j in range(101):
r = ((i-mean_i)**2 + (j-mean_j)**2)**0.5
x[i,j] = S0*(1+(r/r0)**2)**-1.5
x[i,j] = x[i,j] + noiseimg[i,j]
if (((i-50)**2 + (j-50)**2)**0.5 >= 40) and (((i-50)**2 + (j-50)**2)**0.5 <= 41):
x[i,j]=0
imshow(x)
show()
这样做的目的是产生一个具有一定背景噪声的图像,以及一个圆对称的源。有一个圆圈以图像为中心,半径为40像素。在
我需要知道的是如何找到该圆内最高值像素的位置。我知道如何找到圆中的最大值,但不知道它的[i,j]
位置。在
谢谢你!在
我的问题已被stackoverflow标记为potential duplicate,但这不包含我需要的位置限制。在
一种解决方案是“归零”出圆周围的所有元素,然后简单地取整个数组的最大值。你的半径是41,在(50,50)中心。在
那你就可以了
现在创造你的形象。然后找出最小值,并将其设置为边界外的每个值。如果圆外有一个像素大于圆内的最大值,则它现在设置为一个小得多的值。在
^{pr2}$所以你的形象会像
现在就拿最大值
这个解决方案很好,因为它避免了循环,这在很大程度上挫败了使用numpy的初衷。在
编辑:
很抱歉,你说你需要最大值的指数。上面的解决方案是相同的,只要把指数拆开。在
应该这么做。在
相关问题 更多 >
编程相关推荐