Mesuring the surface of leaves threshold balance



Hi, I am new to image J, and I need to use it to treat scans of leaves to make them go from colored to black and white (black on the surface of the leaf and white on the background) so I can then calculate their surface on winfolia (it counts the number of black pixels and gives the surface).
For this I use the threshold menu but I haven’t found the right balance with the curseurs to accurately represent the leaf (there’s either part of the leaves that don’t appear or too much black pixels). I have made some research and tried to use bandpass filter but it doesn’t work and an error message “no memory available” appears.
I’ve also tried to compare the autothresholds available but the result isn’t that good.
So I don’t really know how to do it now, given that i don’t really know what the thresholder options represents on top of that.
Thank you for your help in advance :slight_smile:


Try to use the color threshold (where you also can apply samples):

Another method is to use a classification plugin like the Trainable Segmentation plugin:

To count the area you don’t need another software. Just measure the area in ImageJ:

You will find tons of resources on YouTube,in this forum or the ImageJ mailing list archives, too:


To address the memory issue, use Edit > Options > Memory & Threads... to increase the amount of RAM ImageJ is allowed to use. I generally stop at 95% of my computer’s RAM just to make sure other programs have enough to work with.


Thanks to you both! I am currently trying to use the trainable weka but this message appears “Loading Weka properties…
Warning: at least one dimension of the image is larger than 1024 pixels.
Feature stack creation and classifier training might take some time depending on your computer.” and i don’t know what to do … given that the image is a basic scan.


See one answer of @iarganda here:


okay thank you! Do you know at wich moment I should run this macro? I tied to limit the numbers of features to 2 but it doesn’t work.


No need to use the cited macro.

Which size have you images? Do you have any example images to post here? Which OS are you using.
Simply copy the information you find here:

Maybe it helps if you increase your default java memory:

Edit > Options > Memory & Threads… (as @Andrew_Shum answered already)


I’ve increased the memory to 2900MB (the memory of my computer is 4Go 1067 MHz)… i use the OS X 10.9.5 and here is an example of what i need to analyse (i want to find a way to calculate the surface of each leaf automatically or as automatically as possible). (in this example there is only one leaf on the scan but most of the time there is more)


Or maybe not a way to automatically give the surface but at least to have the leaves selected automatically on each picture
I also get this message “Warning: ImageScience library unavailable. Some training features will be disabled.” when i select the training features in the segmentation settings


Your images for classification are big so the default randomForest classification consumes a lot of Java memory. It might be favorable to select another classifier. A good choice is the naives bayes as described here (the plugin uses the weka library for classification):

The warning simply means that the ImageScience library is not available in you installation so you can’t use some features for classification. You have to:

…it requires enabling the ImageScience update site in the updater)…

which is noted in the documentation here (section: Training features (3D)):

However apart from the plugin in your case you can also use the Color Threshold plugin. For instance segment the white background to get the total area of the leaves:

Here a result of the color threshold (using the actions 1. Sample and 2. Select of the plugin) followed by step 3-5 to measure the leaves as particles:

  1. Color Threshold plugin: Sample a selection (image background)
  2. Color Threshold plugin: Select
  3. Process->Binary Make Binary
  4. Edit->Invert (to get the leave area in the measurements)
  5. Analyze->Analyze Particles (exclude particles of certain size to exclude dirt)

This procedure can be recorded with ImageJ and applied on a folder of images.

There are of course other methods to segment the image. In my application I can also apply supervised and unsupervised classifiers from R (written in C) which perform well on hughe images (e.g. clara as good performing unsupervised algorithm).