gpt4 book ai didi

python - 如何计算每行每列的颜色像素值

转载 作者:行者123 更新时间:2023-12-01 00:10:01 24 4
gpt4 key购买 nike

我正在使用一个示例,说明如何使用 Python 使用以下公式计算每行和每列中每个像素的值。

公式为 enter image description here

其中M表示图像矩阵维度N表示总数像素个数,P(i,j)为第i行第j列的颜色像素值

最佳答案

像素 channel 的平均值计算起来相当简单,但不一定非常有意义 - 根据用例,找到主色更具说明性。 This answer演示了一种寻找主色的方法。

这是一个使用图像查找图像像素的 channel 平均值的玩具示例

enter image description here

import cv2
import numpy as np

im = cv2.imread('opencvtest.png')

# Find the average of each channel across the image
mean = [np.mean(im[:,:,i]) for i in range(im.shape[2])]

print(mean)
[132.6709785196566, 92.74899063496903, 81.57176387455432]

所以找到的代码的平均颜色是

这与我对测试图像的预期一致。

关于python - 如何计算每行每列的颜色像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59694027/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com