1

画像があり、画像内の極大値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

配列の導関数や分割統治法など、より良いアプローチを使用した方法を見つけたいと思います。私はより良い推奨ソリューションを適切に扱います。

4

2 に答える 2

4

だから私は、スキイメージの適応しきい値を使用して、これを持っています。それが役に立てば幸い:

オリジナル ここに画像の説明を入力

コード

from skimage.filters import threshold_adaptive
import matplotlib.pyplot as plt
from scipy import misc, ndimage
import numpy as np

im = misc.imread('\Desktop\MapSNR.jpg')

# Apply a threshold
binary_adaptive = threshold_adaptive(im, block_size=40, offset=-20).astype(np.int)
# Label regions and find center of mass
lbl = ndimage.label(binary_adaptive)
points = ndimage.measurements.center_of_mass(binary_adaptive, lbl[0], [i+1 for i in range(lbl[1])])

for i in points:
    p = [int(j) for j in i]
    binary_adaptive[i] += 5

plt.figure()
plt.imshow(im, interpolation='nearest', cmap='gray')
plt.show()

plt.figure()
plt.imshow(binary_adaptive, interpolation='nearest', cmap='gray')
plt.show()

出力

ここに画像の説明を入力

しきい値のパラメーターを変更すると、極大値が検出される場所と検出される最大値の数に大きな影響があります。

于 2015-08-16T21:06:59.597 に答える
3

photutils の検出方法の 1 つであるphotutils.detection.find_peaks関数を使用できます。

photutils.detection.find_peaks の実装を見ると、 scipy.ndimage.maximum_filterを使用して最大画像 (デフォルトでは 3x3 ボックス サイズのフットプリント) を計算し、元の画像が最大値に等しいピクセルを見つけていることがわかります。画像。

関数の残りの部分は、主に、あなたが興味を持つかもしれない 2 つのことのためのものです。

  1. オブジェクトを渡すと、wcsピクセル座標だけでなく、空の座標も取得できます。
  2. サブピクセル精度の座標を取得するオプションがあります。
于 2015-08-17T21:03:00.107 に答える