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
else
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:.

@Anshu

Read this to code in macro.

https://imagej.nih.gov/ij/developer/macro/macros.html

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

@Anshu

1; for “Analyze”

https://imagej.nih.gov/ij/docs/guide/146-30.html#toc-Section-30
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.

Hi
@Anshu

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.

requires("1.52t")
setBackgroundColor(0,0,0);
setOption("BlackBackground",true);
img=getImageID();
setBatchMode(true);
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");
selectWindow("Green");
setAutoThreshold("Default dark");
//run("Threshold...");
//setThreshold(110, 255);
run("Convert to Mask");
run("Analyze Particles...", "size=1000-Infinity show=[Overlay Masks] display exclude add");
n=roiManager("Count");
if(n>0)
{
print( "Weeds present",   1);
selectWindow("1");
roiManager("Set Fill Color", "red");
roiManager("Show All without labels");
close("\\Others");
}
else
{
print(" No weeds present",         0);
selectWindow("1");
close("\\Others");
}
setBatchMode(false);
exit("It's over");

Greetings

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:

out

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

Hi
@Anshu

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