【发布时间】:2018-06-15 02:48:12
【问题描述】:
我的目标是读取植物的图像,然后输出仅显示绿色部分而没有任何其他背景颜色的图片。本质上,我只想从图片中提取叶子部分,而不是土壤或其他任何东西。到目前为止,我已经能够阅读我的图像并将它们更改为绿色,但是我的目标是实际提取绿色而不是更改整个绿色。关于我可能做错什么的任何想法?
这是我的代码
import matplotlib.pyplot as plt
import numpy as np
# Read and display picture
originalImage = plt.imread("C:/Users/user/Desktop/Image for detection1.jpg")
imgplot = plt.imshow(originalImage)
# Copy 1st picture and turn into an array
edittedImage = originalImage.copy()
arr = np.asarray(originalImage) # create array for image
lowerGreen = np.array([130,137,10]) # define lower values for green
upperGreen = np.array([220,235,130]) # define higher values for green
for color in arr: # loop through pixels to find the color green
if color >= lowerGreen and <= upperGreen:
print (color) # print the image showing only the green sections
imgplot = plt.imshow(edittedImage)
错误信息: 文件“C:/Users/user/.spyder-py3/extract green.py”,第 28 行,在 如果颜色 >= lowerGreen 和颜色
ValueError:具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()
【问题讨论】:
-
欢迎来到 StackOverflow。请按照您创建此帐户时的建议阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布 MCVE 代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您描述的问题。
-
@Prune 好的,我将获取我的 MCVE 代码并编辑帖子。谢谢
标签: python image-processing spyder