从图像中堆叠星型PSF;对齐亚像素中心 [英] Stacking star PSFs from an Image; aligning sub-pixel centers

查看:144
本文介绍了从图像中堆叠星型PSF;对齐亚像素中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个(1727,1853)大小的数组(图像),在其中确定了恒星,以对点扩散函数进行建模.数组的每个索引对应于一个图像坐标,但是,每个星星的质心由一个子像素坐标给出.我必须执行以下操作

I have an (1727,1853) size array (image), in which I have identified stars to model a point-spread function. Each index of the array corresponds to an image coordinate, however, the centroid of each star is given by a sub-pixel coordinate. I must do the following

  1. 对每颗星星进行2D切片.我已经使用numpy的数组切片完成了此操作.但是,它按索引切片,并且我具有亚像素质心坐标,因此,我进行的任何切片都会使星形偏离中心.

  1. Make a 2D slice of each star. I have done this using numpy's array slicing. However, it slices by index, and I have sub-pixel centroid coordinates, thus any kind of slice I make will place the star off-center.

对每颗恒星进行2D切片后,必须将这些阵列彼此堆叠,以构建点扩散函数模型.只要每个恒星的子像素中心对齐,这就很简单.

After I make a 2D slice of each star, I must stack these arrays on top of each other to make a model of the point-spread function. This is simple as long as the sub-pixel centers of each star are aligned.

我的问题是对齐这些子像素坐标并将每个2D切片堆叠在一起的最有效(正确)方法是什么?

My question is what is the most efficient (and correct) way of aligning these sub-pixel coordinates and stacking each 2D slice together?

我希望这很清楚.任何帮助将非常感激.下面是其中一颗恒星的2D切片(不是很好),但由于偏离索引的numpy切片,并且恒星的质心具有亚像素坐标,因此它不在中心.

I hope this was clear. Any help would be much appreciated. Below is a 2D slice of one of the stars (not a very good one), however it is off center because numpy slices by index and the stars have sub-pixel coordinates for their centroids.

推荐答案

您可以表示每个切片"中像素相对于恒星质心的中心坐标,然后计算2D加权直方图.

You could express the centre coordinates of the pixels in each 'slice' relative to the centroid of the star, then compute a weighted 2D histogram.

首先,提供一些示例数据:

First, some example data:

import numpy as np
from matplotlib import pyplot as plt

# pixel coordinates (integer)
x, y = np.mgrid[:100, :100]
# centroids (float)
cx, cy = np.random.rand(2, 9) * 100

# a Gaussian kernel to represent the PSF
def gausskern(x, y, cx, cy, sigma):
    return np.exp(-((x - cx) ** 2 + (y - cy) ** 2) / (2 * sigma ** 2))

# (nstars, ny, nx)
stars = gausskern(x[None, ...], y[None, ...],
                  cx[:, None, None], cy[:, None, None], 10)

# add some noise for extra realism
stars += np.random.randn(*stars.shape) * 0.5

fig, ax = plt.subplots(3, 3, figsize=(5, 5))
for ii in xrange(9):
    ax.flat[ii].imshow(stars[ii], cmap=plt.cm.hot)
    ax.flat[ii].set_axis_off()
fig.tight_layout()

加权2D直方图:

# (nstars, ny, nx) pixel coordinates relative to each centroid
dx = cx[:, None, None] - x[None, ...]
dy = cy[:, None, None] - y[None, ...]

# 2D weighted histogram
bins = np.linspace(-50, 50, 100)
h, xe, ye = np.histogram2d(dx.ravel(), dy.ravel(), bins=bins,
                           weights=stars.ravel())

fig, ax = plt.subplots(1, 1, subplot_kw={'aspect':'equal'})
ax.hold(True)
ax.pcolormesh(xe, ye, h, cmap=plt.cm.hot)
ax.axhline(0, ls='--', lw=2, c='w')
ax.axvline(0, ls='--', lw=2, c='w')
ax.margins(x=0, y=0)

这篇关于从图像中堆叠星型PSF;对齐亚像素中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆