Guide

How to use stalkless

Once you've got stalkless installed, and you know how to run it (see the 'install' section), give it the arguments -input FOLDER_NAME to show it a folder containing nothing but images to be processed, and -output FOLDER_NAME to specify where your output should be saved.

Try these example files out - on my computer, I type: python stalkless -input /home/will/demoInput -output /home/will/demoOutput. NOTE: all paths are absolute; that means they have to start with a '/' on Mac and Linux computers, and something like 'C:\' on a Windows computer.

If you get confused, run the program with only the argument --help to get... help.

All output is in terms of PIXELS. You can convert this to cm, mm, etc., by knowing the resolution at which each image was scanned.

To run Fourier analyses on your leaf scans, open up the file 'fourier_script.R' that will appear in your output directory once the script has run.

The file 'statistics.txt' in your output will contain a few statistics about leaf shape that you might find useful. You can also calculate the perimeter length of all your scans (...perhaps not calculated in the smartest of ways, take a look at it...) inside the 'fourier_script.R' script.

There are some arguments you might want to know about:

-noObjects

Specify how many objects (leaves) are in each image. Tends to improve image detection.

-exactObjects

The number of objects in each file on each line (nothing else). Must match the alphabetical order of files given with -input or the order of files in -files or strange errors will occur!

-maxObjects

At most (there may be fewer), there are this number of objects (leaves) in each image. Tends to improve image detection.

-exclusion

A comma-separate list (no spaces) of how many pixels to ignore when loading files. In the example, I use this to cut out the information about what the leaves are. This makes it much easier to detect the leaves!

-analyseNow

Attempt to run the R script the program generates immediately. This will likely crash the program - unless the image segmentation went perfectly, you'll likely have one or two images that are no really leaves. Check you image files, then run the R script.

-fill

Use a convex hull algorithm to fill in holes within the leaf. This isn't the best way of doing this; this will cause weird alterations to leaf shape in leaves with intricate edges. Check your output!

-files

Instead of analysing everything in a certain folder, analyse only these files. Each must contain the full, absolute path to that file!

  1. Load images, make them black and white. Trim off exclusion zones.
  2. Thresholds the image - sets anything more intense (dark) than the mean intensity of the image + one standard deviation black, makes the rest white.
  3. There are a number of unconnected regions of black in the image. Count them, and count how many pixels each one is.
  4. Ignoring the background, select all regions larger than the mean region size + two standard deviations. These are the leaves. Alternatively, pick the largest X regions as the leaves.
  5. Count the number of pixels in each leaf. Trim off all white-space surrounding the leaves, then save them out.
  6. Write out an R script, which contains code to for the Fourier analysis of the leaves and counts the edge length of each leaf.
  7. Done.

Essentially, the whole code assumes you'll have bimodal image data - that the leaves are much larger and brighter than anything else in the image. If you have extremely small, or extremely faint, leaves, this may not be the case.

There are much better ways of detecting leaves, which involves more complex edge detection that just thresholding, but this seems to work! If you want details on the interior of the leaves, this is something I'm working on, so talk to me.