Skip to main content

Summon the secrets of the soil with PyRootMancer - the enchanting way to master root phenotyping.

Project description

PyRootMancer - Root Segmentation Project

Welcome to PyRootMancer, the magical tool for all your root segmentation needs! ๐ŸŒฑโœจ Whether you're a plant physiologist, agronomist, or ecologist, PyRootMancer is here to help you unravel the mysteries of root systems with the power of deep learning.

Harnessing the enchanting capabilities of the U-Net model architecture, PyRootMancer ensures that your root images are segmented with pinpoint accuracy. This wizardry not only facilitates precise detection and segmentation of root structures but also aids in comprehensive analyses and research.

Root system analysis has never been this easy and fun! By automating the segmentation process, PyRootMancer allows you to efficiently process large datasets, extract meaningful data, and conduct thorough analyses with minimal manual intervention. Get ready to streamline your workflow, enhance segmentation accuracy, and accelerate your discoveries in plant science.

Table of Contents

Installation

  1. Clone the repository:
    git clone https://github.com/BredaUniversityADSAI/2023-24d-fai2-adsai-group-cv5.git
    
  2. Navigate to the project directory:
    cd 2023-24d-fai2-adsai-group-cv5
    
  3. Install Poetry if you haven't already:
    pip install poetry
    
  4. Install the project dependencies:
    poetry install
    
  5. Activate the virtual environment:
    poetry shell
    

Alternatively, you can install PyRootMancer using pip:

pip install pyrootmancer

Dependencies

The project dependencies are managed using Poetry. Below is a list of key dependencies:

  • tensorflow-io-gcs-filesystem: 0.30.0
  • tensorflow: 2.16.1
  • tensorflow-intel: 2.16.1
  • opencv-python: ^4.9.0.80
  • pandas: ^2.2.2
  • patchify: ^0.2.3
  • matplotlib: ^3.8.4
  • scikit-image: ^0.23.2
  • skan: ^0.11.1
  • numpy: 1.23.5
  • pytest: ^8.2.0
  • pytest-mock: ^3.14.0
  • sphinx: ^7.3.7
  • coverage: ^7.5.3
  • sphinx_rtd_theme: 2.0.0
  • networkx: ^3.3

For a complete list of dependencies, refer to the pyproject.toml file.

Usage

Data Preprocessing

The DataPipelineSetup class handles data preprocessing tasks such as creating folders, unzipping files, cropping images, and patchifying images.

Example usage:

from src.data.data_preprocessing import DataPipelineSetup

processor = DataPipelineSetup()
processor.create_folders()
processor.unzip("train")
processor.unzip("test")
processor.unzip("masks")
processor.crop("path/to/folder")
processor.img_patchify("path/to/img_dir", "path/to/save_dir")

Model Training

The ModelTraining class handles the training of the U-Net model for image segmentation.

Example usage:

from src.models.model_training import ModelTraining

trainer = ModelTraining()
trainer.training(epochs=10, image_folder="path/to/images", mask_folder="path/to/masks", model_folder="path/to/models", model_name="unet_model")

Instance Segmentation

The InstanceSegmentation class performs instance segmentation tasks including noise removal, overlaying masks, and resizing predicted masks to match the size of original images.

Example usage:

from src.features.instance_segmentation import InstanceSegmentation

segmenter = InstanceSegmentation()

# Perform noise removal on an image
clean_image = segmenter.opening_closing(image)

# Overlay a predicted mask on a test image
blended_image = segmenter.test_overlaying(image_path="path/to/image.png", output_folder="path/to/output", model_folder="path/to/model", model_name="model_name")

# Resize predicted masks to match original image size and overlay them
resized_image = segmenter.return_original_size_image(image_path="path/to/image.png", output_folder="path/to/output")

Root Coordinate Extraction

The LandmarkExtraction class extracts landmarks and coordinates from root images, processes and filters them based on certain criteria.

Example usage:

from src.features.root_coord_extraction import LandmarkExtraction

extractor = LandmarkExtraction()

# Remove small components from a mask
clean_mask = extractor.remove_small_components(mask)

# Get bottom coordinates of roots in an image
coords_0, coords_1 = extractor.get_bottom_coordinates(input_folder="path/to/input", num_img=0)

# Display root landmarks on an image
extractor.display_root_landmarks(input_folder="path/to/input", test_folder="path/to/test", num_img=0)

Root Length Calculation

The RootLengthCalculator class calculates the length of roots from segmented images using a trained model.

Example usage:

from src.features.root_length import RootLengthCalculator
from src.models.model_evaluation import f1, iou

img_dir = "path/to/images"
model_path = "path/to/model"
custom_objects = {"f1": f1, "iou": iou}
csv_filename = "path/to/results.csv"

calculator = RootLengthCalculator(img_dir, model_path, custom_objects)
calculator.process_images()
calculator.save_results(csv_filename)

Model Evaluation

The model_evaluation.py script provides functions for calculating F1 score and Intersection over Union (IoU).

Example usage:

from src.models.model_evaluation import f1, iou

Configuration

The configuration.py script provides the folder and parameter configurations used throughout the project.

Project Structure

2023-24d-fai2-adsai-group-cv5/
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ external/
โ”‚   โ”œโ”€โ”€ processed/
โ”‚   โ”œโ”€โ”€ data_predictions
โ”‚   โ”œโ”€โ”€ data_predictions_clean
โ”‚   โ””โ”€โ”€ raw/
โ”‚       โ”œโ”€โ”€ data_unpatched/
โ”‚       โ””โ”€โ”€ data_patched/
โ”œโ”€โ”€ models/
โ”‚   โ””โ”€โ”€ best_model
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ data/
โ”‚   โ”‚   โ””โ”€โ”€ data_preprocessing.py
โ”‚   โ”œโ”€โ”€ features/
โ”‚   โ”‚   โ”œโ”€โ”€ instance_segmentation.py
โ”‚   โ”‚   โ”œโ”€โ”€ root_coord_extraction.py
โ”‚   โ”‚   โ””โ”€โ”€ root_length.py
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ model_definitions.py
โ”‚   โ”‚   โ”œโ”€โ”€ model_evaluation.py
โ”‚   โ”‚   โ””โ”€โ”€ model_training.py
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ””โ”€โ”€ configuration.py
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ pyproject.toml

Authors

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

pyrootmancer-0.1.5.tar.gz (22.1 MB view details)

Uploaded Source

Built Distribution

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

pyrootmancer-0.1.5-py3-none-any.whl (22.1 MB view details)

Uploaded Python 3

File details

Details for the file pyrootmancer-0.1.5.tar.gz.

File metadata

  • Download URL: pyrootmancer-0.1.5.tar.gz
  • Upload date:
  • Size: 22.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.13 Windows/10

File hashes

Hashes for pyrootmancer-0.1.5.tar.gz
Algorithm Hash digest
SHA256 38a530d60a48f5cd3b4f10207a00956dc95f48be48ddff14f1f63bda68904d38
MD5 e82f1582c6e3a4cba1e67544c58dfb9f
BLAKE2b-256 891c4260e03e5460adb5ddb54de741432ed06bf9861f549ebb6ae306cdaff241

See more details on using hashes here.

File details

Details for the file pyrootmancer-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pyrootmancer-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 22.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.13 Windows/10

File hashes

Hashes for pyrootmancer-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 eb9bfdbad864716ff17e63ddf0ffe34bed13f5b4eddeaef5d591d30ea4a46079
MD5 6dd1fa7e3cd3e756174c97ee73db0584
BLAKE2b-256 c93bbcf2865064d747117a6963433c8cc489dc21ce9ade727750e71a1b79ae71

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