首页 > 解决方案 > Photutils 源检测不适用于小图片,适用于大图片,为什么?

问题描述

我正在尝试检测图片上的星星/天文物体。这是我可以做得很好的图片,如下所述:

像哈勃深场的照片

按照本网站上给出的建议,我有以下代码:

from astropy.stats import sigma_clipped_stats
from photutils.datasets import make_100gaussians_image
from photutils import find_peaks
import matplotlib.pyplot as plt
from astropy.visualization import simple_norm
from astropy.visualization.mpl_normalize import ImageNormalize
from photutils import CircularAperture
data = make_100gaussians_image()
mean, median, std = sigma_clipped_stats(data, sigma=3.0)
threshold = median + (5. * std)
tbl = find_peaks(data, threshold, box_size=11)
positions = (tbl['x_peak'], tbl['y_peak'])
apertures = CircularAperture(positions, r=5.)
norm = simple_norm(data, 'sqrt', percent=99.9)
plt.imshow(data, cmap='Greys_r', origin='lower', norm=norm)
apertures.plot(color='#0547f9', lw=1.5)
plt.xlim(0, data.shape[1]-1)
plt.ylim(0, data.shape[0]-1)

它工作正常,这是输出:

很多星星,有一些标记

如果我将第 10 行修改为,threshold = median + (30. * std)那么我会得到一个标记为更少星的输出,正如预期的那样。这是输出:

在此处输入图像描述

现在,我想将它用于此文件:

有两颗星的图片

为此,我运行此代码,源是从 FITS 文件加载的:

import lightkurve
tpf=lightkurve.targetpixelfile.KeplerTargetPixelFile('ktwo201103700-c102_lpd-targ.fits')
from astropy.stats import sigma_clipped_stats
from photutils.datasets import make_100gaussians_image
from photutils import find_peaks
import matplotlib.pyplot as plt
from astropy.visualization import simple_norm
from astropy.visualization.mpl_normalize import ImageNormalize
from photutils import CircularAperture
#data = make_100gaussians_image()
data = tpf.flux[100]
mean, median, std = sigma_clipped_stats(data, sigma=3.0)
threshold = median + (0.1 * std)
tbl = find_peaks(data, threshold, box_size=11)
#tbl['peak_value'].info.format = '%.8g'  # for consistent table output
#print(tbl[:10])    # print only the first 10 peaks
positions = (tbl['x_peak'], tbl['y_peak'])
apertures = CircularAperture(positions, r=1.)
norm = simple_norm(data, 'sqrt', percent=99.9)
plt.imshow(data, cmap='Greys_r', origin='lower', norm=norm)
apertures.plot(color='#0547f9', lw=1.5)
plt.xlim(0, data.shape[1]-1)
plt.ylim(0, data.shape[0]-1)

输出如下。无论我在第 13 行中给出的阈值有多小,它都只能找到一颗星,而不是两颗星,这是所希望的。

两颗星,一颗被圈起来

为什么会这样,我该如何解决?

标签: pythonimage-processingphysicsastronomyastropy

解决方案


使用box_size=4我有这个结果:3星

在jupyter notebook中运行脚本之前,我必须安装这些模块:

pip3 install jupyter lightkurve photutils

– 并使用此命令还可以查看图像结果:

plt.interactive(True)
%matplotlib

推荐阅读