1

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

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ttam
  • 63
  • 1
  • 7

2 Answers2

0

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" )
Ttam
  • 63
  • 1
  • 7
0

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
fmw42
  • 46,825
  • 10
  • 62
  • 80