You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

太阳序列图像对齐出现漂移,求优化质心计算方案

太阳FITS图像对齐:解决截断盘面的圆心计算问题

我正在处理200多张连续拍摄的太阳FITS图像,目的是对齐后开展后续分析。原本以为对齐已完成,但播放序列图像合成的视频时,发现太阳出现向下漂移现象。排查后确认,问题源于部分图像中太阳完整盘面缺失,导致当前基于质心的对齐方式失效——现有质心计算逻辑仅适用于太阳盘面完整的情况,当盘面被截断时,质心会逐渐偏移,进而引发对齐偏差。

当前使用的质心计算代码:

import numpy as np

def get_centroid(data): 
    # data is extracted from a FITS file
    
    # getting data centroid
    y_index, x_index = np.where(data >= 1e4) 
    # threshold is set to only include bright circle (sun) and not background

    # calculate the centroid
    centroid_y = np.mean(y_index)
    centroid_x = np.mean(x_index)
    
    return (centroid_y, centroid_x) 

修改方案:基于圆拟合的圆心计算

太阳在图像中可近似为标准圆形,即使盘面被截断,剩余亮区像素依然属于圆弧的一部分。通过拟合这些像素点到圆的方程,就能得到太阳真实的圆心,避免质心偏移问题。

以下是修改后的函数,使用最小二乘法拟合圆:

import numpy as np
from scipy.optimize import curve_fit

def get_sun_center(data, threshold=1e4):
    # 提取亮区像素坐标
    y, x = np.where(data >= threshold)
    if len(x) == 0:
        raise ValueError("No pixels above threshold found")
    
    # 将圆方程转化为线性形式:x² + y² = 2x0x + 2y0y + (r² - x0² - y0²)
    def circle_eq(coords, A, B, C):
        x, y = coords
        return x**2 + y**2 - A*x - B*y - C
    
    # 构造拟合输入数据
    coords = np.vstack((x, y))
    target = np.zeros_like(x)
    
    # 用原质心作为拟合初始值,加快收敛速度
    init_x0, init_y0 = np.mean(x), np.mean(y)
    init_guess = [2*init_x0, 2*init_y0, init_x0**2 + init_y0**2]
    
    # 执行拟合求解圆心参数
    params, _ = curve_fit(circle_eq, coords, target, p0=init_guess)
    A, B, C = params
    
    # 计算最终圆心坐标
    x0 = A / 2
    y0 = B / 2
    
    return (y0, x0)  # 保持和原函数返回顺序一致:(y, x)

关键说明

  • 鲁棒性:即使只有部分圆弧像素,只要太阳亮区像素数量足够,就能准确拟合出真实圆心
  • 兼容性:返回值顺序与原函数完全一致,无需修改后续对齐逻辑
  • 效率:将圆方程转化为线性形式拟合,避免了非线性拟合的复杂计算,运行速度更快

内容的提问来源于stack exchange,提问作者Sev Hryn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 02:33:36