Improve image recognition: plant green pixels

366 Views Asked by At

I'm using python and simpleCV to extract the number of green pixels of an image. In the end I'm doing some calculations to get the leaf area of a plant.

My problem is that the quality of the pictures is sometimes not very high, resulting in not detected pixels.

In simpleCV the relevant settings are:

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

Changing minsaturation and minvalue doesn't help much because I get too many false pixel recognitions. So I was thinking of doing some image editing beforehand.

Can anyone think of a way to make the pixels more detectable?

Original Picture

Picture after simpleCV

2

There are 2 best solutions below

0
fmw42 On BEST ANSWER

In Imagemagick, you can selective threshold range in H, C and L colorspace. Then use connected components to remove small regions. Unix syntax.

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

These two commands can be combined into one long command.

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
0
Ttam On

For other people with the same problem, I got some nice results using imagemagick (convert) with "-level"

my batch file

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