[英]how to extract ARGB color for pixel
i converted image into 2D array using asarray, how to extract ARGB color value of pixel from this array and check RGB, HSV, Ycbcr values?我使用 asarray 将图像转换为二维数组,如何从该数组中提取像素的 ARGB 颜色值并检查 RGB、HSV、Ycbcr 值? i found this method on this article
我在这篇文章中找到了这个方法
It's also pretty simple to implement the rgb_to_hsv
, but colorsys
is included in the standard library.实现
rgb_to_hsv
也非常简单,但colorsys
包含在标准库中。
from PIL import Image
import numpy as np
import colorsys
def getYCrCb(r, g, b):
y = 0.299 * r + 0.287 * g + 0.11 * b
return (y, r - y, b - y)
img = np.array(Image.open('/path/to/image')) # equivalent asarray
print(img.shape) # height, width, RGB (one for each channel means 3)
r, g, b = img[200, 200] # pixel. Coordinate from top, then coordinate from left
print(r, g, b) # 73 70 39 for example
print(colorsys.rgb_to_hsv(r, g, b)) # (0.15196078022321066, 0.46575344, 73) in the same example
print(getYCrCb(r, g, b)) # (46.207, 26.793, -7.207000000000001) in the same example
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.