python - 多幅图像的时间中值图像

标签 python opencv numpy

除了使用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))

and 是将 2D 图像读入列表或从文件中顺序读取的常用方法,以增量方式增长数据结构。不过,通常情况下,预先分配零 block 并在加载时按顺序插入数据会更有效。

关于python - 多幅图像的时间中值图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28682985/

相关文章:

python - 无法在 Python (Windows) 中使用 OpenCV 更改网络摄像头分辨率

c++ - 如果没有窗口,opencv cv::addText 异常

python - 快速搜索大型结构化 numpy 数组

python - 如何让自定义日志记录在 CherryPy 中工作?

Python __index__ 和评估顺序

java - 如何获得至少一定大小的列表分组的所有组合?

python - Seaborn 情节未显示

python - OpenCV内存不足错误

python - 矢量化misc.imresize()时出现广播错误

python - 重复 numpy 数组行,其中重复次数不同