Oil palm tree counting



Hi @lanzo,

you can give a try to the plugin Template Matching and Slice Alignment .

It doesn’t seem to work on RGB image but converting it to HSB you could work on the B (brightness component) and then playing with tolerence.
The Main issue is that the result would change depending of which template tree you selected.

Since, the general pattern of tree is very repetitive, you could calculate the max number of spots and use an opposite strategy to count the “brown empty space”

What is the raw format of your image ? Maybe you can get better results using tif than jpg images.



Some macro language code below

templateSide 		= 75 ; // duplicate a part of the image to use as a template
templateTolerence 	= 0.5; // 0.5 for ground template // 0.15 for tree
diameterROI 		= 75 ; // at the end add ROIs in the manager to output on the original image

title = getTitle;
run("Duplicate...", "title=HSB");
run("HSB Stack");

run("Stack to Images");

// comment And un-comment to use the image you want
// if template is :
//  - ground, use Hue
// - tree, use Brightness

// ask you to make point selection(s)
waitForUser("Please point select the center of a template ROI.\nIf multipoint, and average projection will be made");

// duplicate the selection(s) to create a template
getSelectionCoordinates(xpoints, ypoints);
for(i = 0 ; i < lengthOf(xpoints) ; i++){
	run("Duplicate...", "title=Template");

// if many selections average them
	run("Images to Stack", "method=[Copy (center)] name=Stack title=Template use");
	run("Z Project...", "projection=[Average Intensity]");

// run the plugin , you need to install every dependcy first
run("cvMatch_Template...", "image=Image method=[Normalized correlation coefficient] template=Template multiple tolerence="+templateTolerence+" threshold=0");

// create some ROIs

for(i = 0 ; i < nResults ; i++){
	x = getResult("X",i);
	y = getResult("Y",i);

roiManager("Show All without labels");


Dear romainGuiet,
The original image is tiff, I see Fiji needs to convert it, now I am going to cut in different parts with qgis the image as they are different plots then I’ll try again.
Maybe the NDVI separates better the plants from the ground, I will prepare that too.
Thank you for the precious help!
The pattern of the total area is not homogeneous, the plantation wasn’t made with good knowledge, that’s why they need to plan reform, i will show to you


Hi @lanzo,

using the Process > Find Maxima… on the Hue-channel after quick prefiltering I got the following result:

In detail I converted the image to an HSB Stack:
run("HSB Stack");

Then I filtered the Hue-Channel:
run("Gaussian Blur...", "sigma=4");

And finally I used Find Maxima, excluding the points on the border of the image.
run("Find Maxima...", "noise=0 output=Count exclude");



Wow, that is pretty good!


Dear Anna I followed your technique, I have the count number as output but the image only shows HUE channel, how I can show the RGB again with the crosses like your image sample?
Thank you very much!


Ok using the menu I was able to show the points, played with noise value i got a decent result but the error i seems too much, I attach a sample.
How about a plugin that recognize the shape of the plant wich is very characteristic?
Thank you


You might also want to play with the sigma of the Gaussian blur. It’s true that the shape is very characteristic, but I don’t really know how to take advantage of it.
By the way, if you want to save the Image with the point selection, you can do Image > Overlay > Add Selection… and then Image > Overlay > Flatten.


Dear Anna, Gaussian Blur 5 and Find Maxima noise 2 are giving a very nice result, but the latest procedure doesn’t work in my PC [quote=“aklemm, post:8, topic:3646”]
if you want to save the Image with the point selection, you can do Image > Overlay > Add Selection… and then Image > Overlay > Flatten.

Tomorrow I will try with NGB image too

Thank you


Dear Lanzo, great! About the overlay: which error do you get?


After Maxima point Selection I see 1/3 (Hue) image, black and white with all the cross, I can go to brightness to see better if the result is ok but I want it RGB and save the file with crosses.
So I apply:
Image > Overlay > Add Selection
Image > Overlay > Flatten
And it asks for Ok because it cannot be undone, click OK
it converts to RGB but it remaind black and white, if I select Image type - RGB Color appears:

(Fiji Is Just) ImageJ 2.0.0-rc-54/1.51h; Java 1.8.0_66 [64-bit]; Windows 7 6.1; 6457MB of 48938MB (13%)
java.lang.ClassCastException: [I cannot be cast to [B
	at ij.process.ImageConverter.convertHSBToRGB(ImageConverter.java:191)
	at ij.plugin.Converter.convert(Converter.java:56)
	at ij.plugin.Converter.run(Converter.java:21)
	at ij.IJ.runPlugIn(IJ.java:187)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:66)
	at java.lang.Thread.run(Thread.java:745)


Am I correct that you would like to show the crosses on top of the original RGB-image?
In this case you should do the following:

  • Use Find Maxima (Output type: Point Selection) on the Hue-image as you do.

  • Add the point selection to the ROI manager with:
    Edit > Selection > Add to Manager

  • Open your original RGB image.

  • Display the point selection ROI by clicking on it within the ROI Manager.

  • Apply Image > Overlay > Add Selection and Image > Overlay > Flatten.

This should create an overlay of the point selection over your original image.


It works!
Now I will ask the impossible:
Can I edit the Point Selections manually?
I would like to do a visual check then remove and add points where the find Maxima command made mistakes, the count the points again.

Thank you very much Anna!


Nice! Yes, you can edit them. Choose the multi-point tool in the tool bar (right-click on the point-tool), then you can add points with CONTROL+click and delete points with ALT+click.


The big difference is made with the gaussian blur, it cleans the image letting the Find Maxima value be low, I had better results with Blur 8 FM 1 then Blur 5 FM 4


Dear Anna, maybe you have some tips for me on the other thread Detecting and measuring planting gaps (precision agriculture)
Thank you


Hi, how are you ?
I hope all of you are fine and working hard.
I´m very interested in this method for plant counting.
I try several combination of values with no luck in my image.
This is a banana plantation. (very similar to oil palm trees)
My interest is to process images to map the damage made by a tropical storm to plantations

If any one of you can help me with that i will appreciatte too much.


2 posts were split to a new topic: Plant counting software


Hi @martincho68 , is your intention to count each banana tree as the previous case in this thread, or just to quantify the destroyed Area? In this case, “how much of the plantation is brown?”.


introduce my name junaedy kurniawan, i am working in maping consultant in indonesia and now i am doing the process of calculating palm automatically by using drone data. and I am interested in the image j software application to calculate palm automatically. for if I may get the software procedure manual.


Start here…