我有一个fits
图像,我试图在我的图像中找到局部最大值的坐标,但到目前为止我还不能让它工作。我的图片可以在这里找到。到目前为止我所拥有的是
import numpy as np
import scipy.nimage as ndimage
from astropy.wcs import WCS
from astropy import units as u
from astropy import coordinates as coord
from astropy.io import fits
import scipy.ndimage.filters as filters
from scipy.ndimage.filters import maximum_filter
hdulist=fits.open("MapSNR.fits")
#reading a two dimensional array from fits file
d=hdulist[0].data
w=WCS("MapSNR.fits")
idx,idy=np.where(d==np.max(d))
rr,dd=w.all_pix2word(idx,idy,o)
c=coord.SkyCoord(ra=rr*u.degree, dec=dd*u.degree)
#The sky coordinate of the image maximum
print c.ra
print c.dec
这就是我如何找到图像的全局最大值,但我想获得具有大于 3 意义的局部最大值的坐标。
我通过在网上查找发现以下答案在我的情况下无法正常工作。 更新:我用过这个功能
def detect_peaks(data, threshold=1.5, neighborhood_size=5):
data_max = filters.maximum_filter(data, neighborhood_size)
maxima = (data == data_max)
data_min = filters.minimum_filter(data, neighborhood_size)
diff = ((data_max - data_min) > threshold)
maxima[diff == 0] = 0 # sets values <= threshold as background
labeled, num_objects = ndimage.label(maxima)
slices = ndimage.find_objects(labeled)
x,y=[],[]
for dy,dx in slices:
x_center = (dx.start + dx.stop - 1)/2
y_center = (dy.start + dy.stop - 1)/2
x.append(x_center)
y.append(y_center)
return x,y
我想找到一种使用更好方法的方法,例如数组中的导数或分治法。我将寻求更好的推荐解决方案。