多个图像的时间中值图像
Temporal median image of multiple images
除了使用 np.median(array)
计算每个像素的中值外,还有其他方法可以计算多幅图像的中值图像吗?
我知道已经有 question about this,但那是 3 年前的事了,也许什么都发生了。
下面是将 3 个玩具图像放入(高度)x(宽度)x(图像数量)数组然后沿(图像数量)轴调用 numpy.median
的方法示例(其中如果图像按时间顺序排列,将是时间轴)。
In [1]: img1 = np.array([[1, 2], [3, 4]])
In [2]: img2 = np.array([[10, 6], [1, 0]])
In [3]: img3 = np.array([[8, 1], [0, 4]])
In [4]: images = np.zeros(shape=img1.shape + (3,))
In [5]: images[:,:,0] = img1
In [6]: images[:,:,1] = img2
In [7]: images[:,:,2] = img3
In [8]: images
Out[8]:
array([[[ 1., 10., 8.],
[ 2., 6., 1.]],
[[ 3., 1., 0.],
[ 4., 0., 4.]]])
In [9]: images[:,:,0]
Out[9]:
array([[ 1., 2.],
[ 3., 4.]])
In [10]: np.median(images, axis=2)
Out[10]:
array([[ 8., 2.],
[ 1., 4.]])
第 4-7 行由 numpy.dstack
函数处理。这相当于:
images = np.dstack((img1, img2, img3))
这是将二维图像读入列表或从文件中按顺序读取的常用方法,将追加数据结构以增量方式增长。虽然,预分配零块并在加载时按顺序插入数据通常效率更高。
除了使用 np.median(array)
计算每个像素的中值外,还有其他方法可以计算多幅图像的中值图像吗?
我知道已经有 question about this,但那是 3 年前的事了,也许什么都发生了。
下面是将 3 个玩具图像放入(高度)x(宽度)x(图像数量)数组然后沿(图像数量)轴调用 numpy.median
的方法示例(其中如果图像按时间顺序排列,将是时间轴)。
In [1]: img1 = np.array([[1, 2], [3, 4]])
In [2]: img2 = np.array([[10, 6], [1, 0]])
In [3]: img3 = np.array([[8, 1], [0, 4]])
In [4]: images = np.zeros(shape=img1.shape + (3,))
In [5]: images[:,:,0] = img1
In [6]: images[:,:,1] = img2
In [7]: images[:,:,2] = img3
In [8]: images
Out[8]:
array([[[ 1., 10., 8.],
[ 2., 6., 1.]],
[[ 3., 1., 0.],
[ 4., 0., 4.]]])
In [9]: images[:,:,0]
Out[9]:
array([[ 1., 2.],
[ 3., 4.]])
In [10]: np.median(images, axis=2)
Out[10]:
array([[ 8., 2.],
[ 1., 4.]])
第 4-7 行由 numpy.dstack
函数处理。这相当于:
images = np.dstack((img1, img2, img3))
这是将二维图像读入列表或从文件中按顺序读取的常用方法,将追加数据结构以增量方式增长。虽然,预分配零块并在加载时按顺序插入数据通常效率更高。