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
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
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
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