Plant detection on ground using image processing

Iam doing a very simple project for the detection of plants on the ground using image processing . I was able to do that using imagej software. But now I need that detection as a output from the software in order to actuate a cutting mechanism. The output should be in the form of 0 or 1 i.e 0 if there’s no plant and 1 if there’s a plant.
How can that be done in image j ?
If not on imagej then how can I do that with MATLAB or any other coding language?

The image shows the work I’ve done so far. I eliminated background noise i.e ground. I was able to find plant.

1 Like

This completes my previous answer:
Area analysis:
Then a loop
if the number of ROI is > 0
print 1
print 0

Regards to you Mathew.
But me having no knowledge of coding is going to be a problem implemting the solution given by you :sweat_smile:.


Read this to code in macro.

Thanks a lot , I’ll try my best to execute this .


1; for “Analyze”
read 30.2

2; for count
n= roiManager(“count”);

  1. Then the loop

Hey Matthew , I tried the methods suggested by you , but due to my lack in coding skills I was not able to execute the steps described by you.
I would be grateful if you could help me with the code.
What I need is that I’ll be taking images from ground. Those image will be saved in folder . These images have to be analysed by image j automatically. And if there is a plan on the ground , image j should give output as 1 . This output will be used for running a cutter combined with Arduino microcontroller.
If image processing doesn’t work , then I’ll have to go for ultrasonic sensor and use height criteria to detect plants.
Do help if u can.


ImageJ can perform a detection.
Below ImageJ detects the weeds which are in the center of the image and which do not touch the edges.

run("Duplicate...", "title=1");
run("Duplicate...", "title=2");
run("Set Measurements...", "area display add redirect=None decimal=2");
run("RGB Stack");
run("Stack to Images");
setAutoThreshold("Default dark");
//setThreshold(110, 255);
run("Convert to Mask");
run("Analyze Particles...", "size=1000-Infinity show=[Overlay Masks] display exclude add");
print( "Weeds present",   1);
roiManager("Set Fill Color", "red");
roiManager("Show All without labels");
print(" No weeds present",         0);
exit("It's over");


Hi mathew , it was very grateful of you for the code that you sent .
i tried that with some images . it showed good results . But then i tested it for an image without any plants . it was displaying weed present there also . what should i do now .
if possible can i have your email so i can contact you :sweat_smile:


Please deposit the unprocessed image.
You can use the PM integrated in the forum.

This macro is not universal but adapted to the image deposited first. (It is based on each of the RGB colors) and detects the G. Your second image must therefore also contain G! You could also test the RGB -> CMYK plugin.

Thx again Mathew . I’ll check the plugin u suggested.

This image is simply of a floor .
I’ll reduce the problem statement more . What if I only have to detect the green colour or simply a plant on ground . Is that possible with image j ??

1 Like


Test the RGB to CMYK plugin on each of the images.