Skip to main content

Toolkit for analyzing hair fiber morphology

Project description

fibermorph

Python package for image analysis of hair curvature and cross-section

Quickstart

For those who want to run the program immediately, just follow these commands in your terminal. You will need to have conda and know how to use it. If you need instructions for this, read the detailed set up below.

  1. Create a conda environment. conda create -n fibermorph_env python=3.8

  2. Activate this environment. conda activate fibermorph_env

  3. Install fibermorph. pip install fibermorph

  4. Test fibermorph with real data.
    fibermorph --demo_real_curv --output_directory /Users/<UserName>/<ExistingPath>/<NewFolderName

    and

    fibermorph --demo_real_section --output_directory /Users/<UserName>/<ExistingPath>/<NewFolderName

  5. Use fibermorph on your own grayscale TIFFs of longitudinal or cross-sectional hair images.

    fibermorph --curvature --input_directory /Users/<UserName>/<ImageFolderPath> --output_directory /Users/<UserName>/<ExistingPath>/ --resolution_mm 132 --jobs 2

    and

    fibermorph --section --input_directory /Users/<UserName>/<ImageFolderPath> --output_directory /Users/<UserName>/<ExistingPath>/ --minsize 30 --maxsize 180 --resolution_mu 4.25 --jobs 2

Setting up

  1. We recommend you download miniconda for your operating system. You may also download Anaconda. The only difference is that Anaconda comes preloaded with more libraries (500 Mb). You won't need this to run fibermorph, so we recommend you stick to minconda which is the smaller (58 Mb) and quicker to download.

    Whichever you choose be sure to download the version with Python 3.X and not Python 2.X.

  2. Open a terminal.

    Mac OS:

    • Open the Terminal application.

    Windows:

    • Type miniconda in the search box and open the application.

    Linux:

    • Open the Terminal application.
  3. Now you can set up a virtual environment.

    Create an empty conda environment, e.g. conda create -n <fibermorph_env python=3.8 and load it conda activate fibermorph_env You are now ready to install fibermorph!

Install the package

  1. After having activated your new virtual environment, you can simply run pip install fibermorph. You can find the latest release here on this GitHub page and on the fibermorph PyPI page.
  2. You have successfully installed fibermorph. The package is now ready for use. Enter fibermorph -h or fibermorph --help to see all the flags. You can keep reading to try out the demos and read instructions on the various modules within the package.

Demo data

Before using this on any of your own data, it's recommended that you test that you test whether fibermorph is working properly on your machine. There are a few demo modules you can use to check whether fibermorph is running correctly.

Testing with real data

You can test both the curvature and section modules with real data that is downloaded automatically when you run the --demo_real modules.

In both cases, all you need to do is specify a folder path where the images and results can be created with ---output_directory or -o. This folder can be existing, but you can also establish a new folder by including it in the new path.

Both modules will download the demo data into a new folder tmpdata within the path you gave. Then, fibermorph will run the curvature or section analysis, and the results will be saved in a new folder results_cache at this same location. It is recommended that you specify a path with a new folder name to keep everything organized.

Testing curvature analysis

--demo_real_curv

This flag will run a demo of fibermorph curvature analysis with real data. You will need to provide a folder for the demo data to be downloaded.

To run the demo, you will input something like: fibermorph --demo_real_curv --output_directory /Users/<UserName>/<ExistingPath>/<NewFolderName

Testing section analysis

--demo_real_section

This flag will run a demo of fibermorph section analysis with real data. You will need to provide a folder for the demo data to be downloaded.

To run the demo, you will input something like: fibermorph --demo_real_section --output_directory /Users/<UserName>/<ExistingPath>/<NewFolderName

Curvature

To calculate curvature from grayscale TIFF images of hair fibers, the flag --curvature is used with the following flags in addition to input and output directories:

--resolution_mm       	Integer. Number of pixels per mm for
						curvature analysis.
						Default is 132.
--window_size  [ ...] 	Float or integer or None. Desired size for
						window of measurement
						for curvature analysis in pixels or mm (given
						the flag --window_unit). If nothing is entered, the default
						is None and the entire hair will be used to for the curve fitting."
--window_unit {px,mm}	String. Unit of measurement for window of
						measurement for curvature
                      	analysis. Can be 'px' (pixels) or 'mm'. Default is 'px'.
-W, --within_element  	Boolean. Default is False. Will create
						an additional directory with
                      	spreadsheets of raw curvature measurements for each hair if the
                      	--within_element flag is included.
-s, --save_image      	Default is False. Will save intermediate
						curvature/section processing images if
						--save_image flag is included.

So, to run a curvature analysis, you would enter e.g.

fibermorph --curvature --input_directory /Users/<UserName>/<ImageFolderPath> --output_directory /Users/<UserName>/<ExistingPath>/ --window_size 0.5 --window_unit mm --resolution 132 --save_image --within_element --jobs 2

Section

To calculate cross-sectional properties from grayscale TIFF images of hair fibers, the flag --section is used with the following flags:

--resolution_mu       Float. Number of pixels per micron for section analysis. Default is 4.25.
--minsize             Integer. Minimum diameter in microns for sections. Default is 20.
--maxsize             Integer. Maximum diameter in microns for sections. Default is 150.

An example command would be:

fibermorph --section --input_directory /Users/<UserName>/<ImageFolderPath> --output_directory /Users/<UserName>/<ExistingPath>/ --minsize 20 --maxsize 150 --resolution_mu 4.25 --jobs 2

Converting raw images to grayscale TIFF

This package features an additional auxiliary module to convert raw images to grayscale TIFF files if necessary: --raw2gray

In addition to the input and output directories, the module needs the user to specify what file extension it should be looking for.

--file_extension      Optional. String. Extension of input files to use in input_directory when
                      using raw2gray function. Default is .RW2.

A user could enter, for example:

fibermorph --raw2gray --input_directory /Users/<UserName>/<ImageFolderPath> --output_directory /Users/<UserName>/<ExistingPath>/<NewFolderName> --file_extension .RW2 --jobs 4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fibermorph-0.2.6.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fibermorph-0.2.6-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file fibermorph-0.2.6.tar.gz.

File metadata

  • Download URL: fibermorph-0.2.6.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for fibermorph-0.2.6.tar.gz
Algorithm Hash digest
SHA256 df5c3dae575c3c0ba273951de6d2398af8b2760bd7528f7ca39c3bc0d8df77c0
MD5 b2e364f17d5ac0c19771d5d683229076
BLAKE2b-256 d21296c76465bd9a7c32253e5306cbd14226bdfd13c9e81692faefbdca7f7471

See more details on using hashes here.

File details

Details for the file fibermorph-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: fibermorph-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for fibermorph-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 27616c1822db70b0eefc7ca5998e51bf22e22ff8d380e732d43194f92276acf0
MD5 9d3bccca2138dc033bd5108d555c756b
BLAKE2b-256 2b9b6682bee0957ca688e5200597b7dfc72ff724ab4073760928312e98d6b9b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page