【发布时间】:2016-07-18 19:08:35
【问题描述】:
我正在使用 opencv 和 numpy 来处理一些卫星图像。
我需要区分什么是“土地”和什么是“绿色”(作物和植被)。
我的问题是:如何确定 RGB 格式中哪些值接近绿色?
到目前为止,我正在做的是:
img = cv2.imread('image1.jpg',1)
mat = np.asarray(img)
for elemento in mat:
for pixel in elemento:
if pixel[1] > 200: # If the level of green is higher than 200, I change it to black
pixel[0] = 0
pixel[1] = 0
pixel[2] = 0
else: # If the level of G is lower than 200 I change it to white.
pixel[0] = 255
pixel[1] = 255
pixel[2] = 255
此代码有效,但并不是真正有用。我需要一种更精确的方式来确定哪些 RGB 值对应于绿色,哪些不对应。
我怎样才能做到这一点?
【问题讨论】:
-
一个轻微的皱纹 r=255 g=200 b=255 是浅紫色。考虑改用 g>64 和 g>r+b
-
这可能会对您有所帮助:color distance.
-
通常你会想要做一个监督分类,它也可能使用红外线波段和其他因素,如纹理以及地面实况和准确性分析。尝试单独使用 RGB 可能会取得有限的成功。
-
将颜色改为 HSV 会很有用
标签: python opencv image-processing colors rgb