中值组合适合python中的图像 [英] Median combining fits images in python

查看:62
本文介绍了中值组合适合python中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个numpy数组形式的三张拟合图像.我想对它们进行中值合并,即生成一个输出数组,其中每个像素是三个输入数组中相同像素的中值.使用imcombine在IRAF上可以轻松完成此操作.有没有一种方法可以在Python上做到这一点,而无需遍历整个数组并获取每个像素的中值?

I have three fits images in the form of 2D numpy arrays. I want to median combine them, that is, generate an output array in which each pixel is the median of the same pixel in the three input arrays. This can be done easily on IRAF using imcombine. Is there a way to do this on Python without looping through the entire array and taking the median of each pixel?

推荐答案

最简单的方法是:

  • 堆叠2d阵列以形成3d阵列
  • 使用 numpy.median 来计算中位数axis=0可以沿着堆叠的维度进行计算.
  • Stack the 2d arrays to form a 3d array
  • Compute the median using numpy.median passing axis=0 to compute along the dimension of stacking.

您实质上是在计算元素级中位数.这是我会做的一个简单示例:

You're essentially computing an element-wise median. Here's a simple example of what I would do:

>>> import numpy
>>> a = numpy.array([[1,2,3],[4,5,6]])
>>> b = numpy.array([[3,4,5],[6,7,8]])
>>> c = numpy.array([[9,10,11],[12,1,2]])
>>> d = numpy.array([a,b,c])
>>> d
array([[[ 1,  2,  3],
        [ 4,  5,  6]],

       [[ 3,  4,  5],
        [ 6,  7,  8]],

       [[ 9, 10, 11],
        [12,  1,  2]]])
>>> d.shape
(3, 2, 3)

>>> numpy.median(d, axis=0)
array([[ 3.,  4.,  5.],
       [ 6.,  5.,  6.]])

这篇关于中值组合适合python中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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