提高图像识别能力:种植绿色像素

Improve image recognition: plant green pixels

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

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

simpleCV中相关设置为:

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

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

谁能想办法让像素更容易被检测到?

原图

simpleCV后的图片

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

我的批处理文件

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

在 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

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

这两个命令可以合并为一个长命令。

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