Skip to content

ttran428/butterfly-wings

 
 

Repository files navigation

Butterfly Wings

Analyzing images of butterflies and measuring their wing lengths. Using binarization techniques and calculating the resolution of ruler ticks, we read in images of butterflies and output the millimeter lengths of their wings.

example output

Usage

$ python pipeline.py -p -i [input directory or image path] -o [output directory] -s [stage to run to] -csv [csv output file path]

The pipeline script combines four modules to analyze an image: ruler detection, binarization, tracing, and final measurement. These modules are located in /butterfly. Python module requirements are listed in requirements.txt.

Run the pipeline.py file with the arguments to read in raw images and output result images and .csv file with the measurements.

Options

  • -p, --plot : This flag is used to generate output images. This can be ommitted to not plot any images (Image outputs can be ommitted to improve runtime or save space.)
  • -i, --input : A single image input or a directory of images to be analyzed. (Default is raw_images).
  • -o, --output_folder : The output directory in which the result images will be outputted. (Default is outputs).
  • -s, --stage : The stage which to run the pipeline until. Must be one of ['ruler_detection', 'binarization', 'tracing', 'measurements']. To run the entire pipeline, simply use -s measurements. (Running the pipeline and stopping at an earlier stage can be useful for debugging.)
  • -csv, --path_csv : Path of .csv file for the measurement results. (Default is results.csv).
  • -dpi : Optional argument to specify resolution of the output image. (Default is 300.)

Examples:

Running

$ python pipeline.py -s measurements

in /butterfly-wings. Expected file locations:

/butterfly-wings
    ...
    pipeline.py
    ...
    /raw_images
        image1.jpg
        image2.jpg
        ...
    results.csv

Running

$ python pipeline.py -p -i ../data/test_pictures -o ../data/test_output -s measurements -csv ../data/test_output/results.csv

in /butterfly-wings. Expected file locations:

/data
    /test_pictures
        image1.jpg
        image2.jpg
        ...
    /test_output
        image1.jpg (result image for image1.jpg)
        image2.jpg
        ...
        results.csv
/butterfly-wings
    ...
    pipeline.py
    ...

Miscellaneous

Jupyter notebooks with prototypes for various methods are located in the /notebooks directory.

The testing suite can be run with PYTHONPATH=. pytest from /butterfly-wings.

Accuracy:

Run the result_plotting.py file to print out to generate a histogram of the difference for all actual - predicted measurements. (Not parametarized, so you will need to edit the script for the correct paths to compare result .csv's)

About

Automated butterfly wing length measurement

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 99.7%
  • Python 0.3%