You need to enable JavaScript to run this app. 计算图像指定坐标点各RGB通道均值的最快实现方法?
优惠活动
大模型
产品
解决方案
定价
更多

计算图像指定坐标点各RGB通道均值的最快实现方法?

我针对该需求实现了多个函数,当前运行速度最快的版本代码如下:

meanRGB[:] = sum([img[i,j,:] for i,j in args])/len(args)

但该方案处理大尺寸图像时速度仍然不够理想:在第四代老款CPU上处理4700×3100分辨率的图像需要耗时约40秒,经排查硬件性能不是核心瓶颈。

args 存储的是指定的2D x/y坐标点,格式示例如下:

[[0 0] [1 0] [2 1] ...]

更新

感谢各位提供的优秀方案,我认为joostblack提出的方案运行速度最快。以下是简化后的场景复现代码:

clusterMap = [[1,4,2],[1,2,3],[3,1,4]]
np.random.seed(2)
img = np.random.randint(low = 0, high = 255, size = (4700, 3100, 3))
segments = np.unique(clusterMap)

meanRGB = np.zeros((len(segments),3))

for k, segment in enumerate(segments.ravel()):
    args = np.argwhere(clusterMap==segment)
    meanRGB[k,:] = sum([img[i,j,:] for i,j in args])/len(args)


print(f"\n{meanRGB}")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.09 09:18:03