【问题标题】:Please tell how to get rgb value of whole image. I have printed rgb value of each pixel请告诉如何获取整个图像的 rgb 值。我已经打印了每个像素的 rgb 值
【发布时间】:2021-11-01 15:18:03
【问题描述】:

请告诉如何获取整个图像的 rgb 值。我已经打印了每个像素的 rgb 值

import cv2
# LOAD AN IMAGE USING 'IMREAD'
img = cv2.imread("tiger.jpg")
# DISPLAYg
cv2.imshow("Tiger", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
print(img.shape)
[x,y,z]=img.shape


count=0
for i in range(1,x-1):
    for j in range(1,y-1):
        print(img[i,j]) 
        count=count+1
        print(count)

【问题讨论】:

  • 解释“整个图像的 RGB 值”。您是否尝试计算图像中红色的总量/百分比 (RGB)?
  • 平均?中位数?最低限度?最大?
  • 我正在尝试为图像提取单一 rgb 颜色。简而言之,我必须添加图像中所有像素的 rgb 值,我必须混合所有颜色。请帮忙。
  • 你所做的可以优雅地获得here,但你要找的是here或者你可以使用this
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python opencv computer-vision cv2


【解决方案1】:

你已经有了像素。当您阅读图像时使用

img = cv2.imread('tiger.jpg')

img 包含图像的像素,您无需使用循环来获取它们。你可以通过打印来检查它。

print(img)

#it gives you something like

[[[182 194 166]
  [182 194 166]
  [182 194 166]
  ...
  [255 176 109]
  [255 176 109]
  [255 176 109]]

 [[182 194 166]
  [182 194 166]
  [182 194 166]
  ...
  [255 176 109]
  [255 176 109]
  [255 176 109]]

 [[182 194 166]
  [182 194 166]
  [182 194 166]
  ...
  [255 176 109]
  [255 176 109]
  [255 176 109]]
  ...
  [132 171 210]
  [135 174 213]
  [137 176 215]]]

img 是 numpy 数组的类型 (numpy.ndarray) 您可以通过以下方式进行检查:

print(type(img))

【讨论】:

  • 对于这个程序: import cv2 img = cv2.imread("house.jpg") print(img) print(type(img)) output is None Please clearify.
  • 如果你得到“NoneType”这意味着图像没有打开,可能它不在那个地方,或者名称或扩展名不正确。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-05
  • 1970-01-01
  • 1970-01-01
  • 2013-04-10
  • 2010-09-13
  • 2013-11-19
相关资源
最近更新 更多