改善图像识别:植物绿色像素

时间:2018-01-18 03:16:06

标签: python image pixels image-recognition simplecv

我正在使用python和simpleCV来提取图像的绿色像素数。最后,我正在做一些计算以获得植物的叶面积。

我的问题是图片的质量有时不是很高,导致没有检测到像素。

在simpleCV中,相关设置为:

green = plant.hueDistance(color=Color.GREEN, minsaturation=55, minvalue=55).binarize(70).invert()

更改minsaturation和minvalue没有多大帮助,因为我得到了太多的错误像素识别。所以我想事先做一些图像编辑。

有人能想出一种让像素更容易检测到的方法吗?

原始图片

simpleCV之后的图片

2 个答案:

答案 0 :(得分:0)

对于遇到同样问题的其他人,使用imagemagick(转换)和“-level”获得了一些不错的结果

我的批处理文件

for %%f in (*.JPG) do ( convert.exe %%f -level 0,25%% "%%~nf.png" )

答案 1 :(得分:0)

在Imagemagick中,您可以在H,C和L颜色空间中选择性阈值范围。然后使用连接的组件删除小区域。 Unix语法。

convert green.jpg -colorspace HCL -separate \
\( -clone 0 -fuzz 7% -fill white -opaque "gray(66)" \
   -fill black +opaque white \) \
\( -clone 1 -fuzz 10% -fill white -opaque "gray(46)" \
   -fill black +opaque white \) \
\( -clone 2 -fuzz 7% -fill white -opaque "gray(87)" \
   -fill black +opaque white \) \
-delete 0-2 -compose multiply -composite tmp1.png

enter image description here

convert tmp1.png \
-define connected-components:verbose=true \
-define connected-components:area-threshold=5160 \
-define connected-components:mean-color=true \
-connected-components 4 \
result.png

enter image description here

这两个命令可以组合成一个长命令。

convert green.jpg -colorspace HCL -separate \
\( -clone 0 -fuzz 7% -fill white -opaque "gray(66)" \
   -fill black +opaque white \) \
\( -clone 1 -fuzz 10% -fill white -opaque "gray(46)" \
   -fill black +opaque white \) \
\( -clone 2 -fuzz 7% -fill white -opaque "gray(87)" \
   -fill black +opaque white \) \
-delete 0-2 -compose multiply -composite \
-define connected-components:verbose=true \
-define connected-components:area-threshold=5160 \
-define connected-components:mean-color=true \
-connected-components 4 \
result.png
相关问题