/MicroplasticsQuantificationAI

The scripts uploaded in this repository were developed for the automated processing of fluorescence microscopy images of Nile Red stained microplastics

Primary LanguageJava

Quantitative image analysis of microplastics in bottled water using Artificial Intelligence

The scripts uploaded in this repositories were developed for the automated processing of fluorescence microscopy images of Nile Red stained microplastics.

Read more about our method for the analysis of microplastics in bottled water at https://doi.org/10.26434/chemrxiv-2022-cr5ws-v2

ExportH5.java

The macro was developed and tested on ImageJ 1.52

When run via the ImageJ macro function, this script artificially adds a particle in the top left corner of each picture and converts the images in the Hierarchical Data Format version 5 (.h5).

To run this script, data should be organised in a main input directory containing:

  • a folder for each sample, containing the images in tag image file format (.tif)
  • the image (in .tif format) of the particle to be added named “Internal_Standard.tif”
Main directory/
├─ Sample_01/
├─ Sample_02/
│    ├─ Sample_02_01.tif
│    ├─ Sample_02_[...].tif
│    ├─ Sample_02_21.tif
├─ Sample_N/
├─ Internal_Standard.tif

The script creates a new folder inside the sample folder. The script moves the .tif files to the new folder and save the .h5 files in the sample folder.

Main directory/
├─ Sample_01/
├─ Sample_02/
│    ├─ raw/
│        ├─ Sample_02_01.tif
│        ├─ Sample_02_[...].tif
│        ├─ Sample_02_21.tif
│    ├─ Sample_02_01.h5
│    ├─ Sample_02_[...].h5
│    ├─ Sample_02_21.h5
├─ Sample_N/
├─ Internal_Standard.tif

IlastikBinarization.py

This script was developed and tested on Windows 10 64-bit operating system and ilastik-1.4.0rc6

This script uses the headless mode of the Ilastik platform to process the images in batch and produce binarized masks.

To run this script, data should be organised in a main directory containing

  • a folder for each sample, containing the images in .h5 format (as generated by the ExportH5 ImageJ macro)
  • the file containing the script
  • the project created in Ilastik containing the trained Random Forrest Classifier named “Ilastik.ilp”
Main directory/
├─ Sample_01/
├─ Sample_02/
│    ├─ Sample_02_01.h5
│    ├─ Sample_02_[...].h5
│    ├─ Sample_02_21.h5
├─ Sample_N/
├─ Internal_Standard.tif
├─ IlastikBinarization.py
├─ Ilastik.ilp

The script is run via Windows Power Shell as follows:

  • Digit “CD” then paste the address of the main directory
  • Press enter
  • Digit “py” and press tab
  • Digit “Ilastik” press tab
  • Press enter

The script creates a new folder inside the sample folder. The script moves the .H5 files to the new folder and save the binarized images in the sample folder.

Main directory/
├─ Sample_01/
├─ Sample_02/
│    ├─ raw/
│        ├─ Sample_02_01.tif
│        ├─ Sample_02_[...].tif
│        ├─ Sample_02_21.tif
│    ├─ h5_files/
│        ├─ Sample_02_01.h5
│        ├─ Sample_02_[...].h5
│        ├─ Sample_02_21.h5
│    ├─ Sample_02_01_Simple Segmentation.tif
│    ├─ Sample_02_[...]_Simple Segmentation.tif
│    ├─ Sample_02_21.Simple Segmentation.tif
├─ Sample_N/
├─ Internal_Standard.tif
├─ IlastikBinarization.py
├─ Ilastik.ilp

AnalyzeParticles.java

The macro was developed and tested on ImageJ 1.52

Before running the macro open FIJI and go to Analyze > Set Measurements…; select “Area” and “Fit ellipse” in the dialog window.

When run via the ImageJ macro function, this script separates overlapping particles by applying the watershed function and reduces the noise by applying the remove outliers function. Then, the analyse articles tool is used to measure particle count and particle size, as the major and minor axes of the best fitting ellipse. Then, the script calculates the MPs mass: the particle volume is estimated by assuming that the individual particle shapes are ellipsoidal, the volume of each particle is calculated assuming that the third dimension of the MP equals the minor axis of the best fitting ellipse; finally, using polymer density data, the MP mass is estimated. Polymer density can be changed in line 63. A coma separated value (csv) is generated for each image containing the count and size of the particles; the cumulative weight of all particles detected in each image is calculated and reported as well.

To run this script, data should be organised in a main directory containing a folder for each sample. The sample folder should contain the binarized images as generated by the IlastikBinarization script.

Main directory/
├─ Sample_01/
├─ Sample_02/
│    ├─ Sample_02_01_Simple Segmentation.tif
│    ├─ Sample_02_[...]_Simple Segmentation.tif
│    ├─ Sample_02_21.Simple Segmentation.tif
├─ Sample_N/
├─ Internal_Standard.tif
├─ IlastikBinarization.py
├─ Ilastik.ilp

The script creates a new folder inside the sample folder. The script moves the binarized images to the new folder and save the .csv file in the sample folder. The outline of the detected particles are saved in a dedicated subfolder.

Main directory/
├─ Sample_01/
├─ Sample_02/
│    ├─ raw/
│        ├─ Sample_02_01.tif
│        ├─ Sample_02_[...].tif
│        ├─ Sample_02_21.tif
│    ├─ h5_files/
│        ├─ Sample_02_01.h5
│        ├─ Sample_02_[...].h5
│        ├─ Sample_02_21.h5
│    ├─ Processed_tif/
│        ├─ Sample_02_01_Simple Segmentation.tif
│        ├─ Sample_02_[...]_Simple Segmentation.tif
│        ├─ Sample_02_21_Simple Segmentation.tif
│    ├─ Outlines/
│        ├─ Sample_02_01_Simple Segmentation_outlines.tif
│        ├─ Sample_02_[...]_Simple Segmentation_outlines.tif
│        ├─ Sample_02_21_Simple Segmentation_outlines.tif
│    ├─ Sample_02_01_Simple Segmentation_Results.csv
│    ├─ Sample_02_[...]_Simple Segmentation_Results.csv
│    ├─ Sample_02_21.Simple Segmentation_Results.csv
├─ Sample_N/
├─ Internal_Standard.tif
├─ IlastikBinarization.py
├─ Ilastik.ilp

Bootstrap.R

This script was developed and tested on RStudio version 1.3.959

The script reads the 21 csv files generated for each sample and calculates the total particle number or the total weight of MPs on the filter (the output can be selected in line 20). A bootstrapping approach is used to calculate the 95% confidence interval.

To run this script, data should be organised in a main directory containing a folder for each sample. The sample folder should contain .csv files as generated by the AnalyzeParticles ImageJ macro.

Main directory/
├─ Sample_01/
├─ Sample_02/
│    ├─ Sample_02_01_Simple Segmentation_Results.csv
│    ├─ Sample_02_[...]_Simple Segmentation_Results.csv
│    ├─ Sample_02_21.Simple Segmentation_Results.csv
├─ Sample_N/
├─ Internal_Standard.tif
├─ IlastikBinarization.py
├─ Ilastik.ilp

The script saves a final results report in the main directory.

Main directory/
├─ Sample_01/
├─ Sample_02/
│    ├─ raw/
│        ├─ Sample_02_01.tif
│        ├─ Sample_02_[...].tif
│        ├─ Sample_02_21.tif
│    ├─ h5_files/
│        ├─ Sample_02_01.h5
│        ├─ Sample_02_[...].h5
│        ├─ Sample_02_21.h5
│    ├─ Processed_tif/
│        ├─ Sample_02_01_Simple Segmentation.tif
│        ├─ Sample_02_[...]_Simple Segmentation.tif
│        ├─ Sample_02_21_Simple Segmentation.tif
│    ├─ Outlines/
│        ├─ Sample_02_01_Simple Segmentation_outlines.tif
│        ├─ Sample_02_[...]_Simple Segmentation_outlines.tif
│        ├─ Sample_02_21_Simple Segmentation_outlines.tif
│    ├─ Sample_02_01_Simple Segmentation_Results.csv
│    ├─ Sample_02_[...]_Simple Segmentation_Results.csv
│    ├─ Sample_02_21.Simple Segmentation_Results.csv
├─ Sample_N/
├─ Internal_Standard.tif
├─ IlastikBinarization.py
├─ Ilastik.ilp
├─ Final_Results.csv