Hi Eiji,
counting those trees appears not to be an easy task - even if one tries it by hand. So I guess an approximation is the best one can expect. Here is what I tried:
- I separated the trees by its color - as before;
- then I applied a
SkeletonTransform
, which I blured;
- finally
WatershedComponents
seems to do the trick.
My result looks like:
I think one can see here at least a not unreasonable separation of single trees. My code:
ClearAll["Global`*"]
img = "your original image";
greenQ[p : {r_, g_, b_}] := With[{mean = Mean[p]}, If[g > 1.05 mean, 1, 0]]
mask = Dilation[Erosion[ImageApply[greenQ, img], 6], 4];
maskData = ImageData[mask];
img0 = ImageMultiply[mask, img]
img1 = Dilation[ImageAdjust@SkeletonTransform[mask], 1]
img2 = Blur[img1, 30] // ImageAdjust
wscData = WatershedComponents@ColorNegate[img2];
colorTrees = ImageMultiply[Colorize[wscData], mask]
Manipulate[Blend[{img, colorTrees}, p], {p, 0, 1}]
What is left for you to do (in case you find this meaningful at all) is to count occurrend colors (except black) down to some minimal patch size. Maybe this might be an approach.
Regards -- Henrik