/Zebrafish-AI

Primary LanguagePythonOtherNOASSERTION

Zebrafish AI: Zebrafish Blood Vessel Segmentation and Feature Quantification

This document outlines the use of a Python-based zebrafish blood vessel segmentation model and MATLAB code for feature extraction and quantification.

I. Zebrafish Blood Vessel Segmentation Model

1. Environment Configuration

To use this code, ensure your environment meets the following requirements: Python>=3.6.0 and PyTorch>=1.8.0. Follow these steps to set up the necessary environment:

  • Install Miniconda or Anaconda

  • Creating a Virtual Environment

    conda create --name pytorch python=3.8
    conda activate pytorch
  • Install PyTorch

    Verify PyTorch Installation:

    import torch
    
    print(torch.__version__)
    print(torch.cuda.is_available())
  • Clone Repository and Install Dependencies

    git clone https://github.com/chenjunzhou/Zebrafish-AI.git
    cd ECA-ResXUnet
    pip install -r requirements.txt

2. Inference

The pretrained model weights can be directly applied to segment images of zebrafish blood vessel:

2.1. Download Weights of pretrained model from either of the following links:

- weights
    |—— CBV
    |   |—— CV_best_model.pth
    |—— CCV
    |   |—— CCV_best_model.pth

2.2. Run Inference Script

To make sure the non-professional artificial intelligence researchers can use our model easily, we provide the pre-trained model weights, which can be directly applied to segment images of the zebrafish blood vessels without re-training.

please follow the two steps below:

CUDA_VISIBLE_DEVICES=0 python inference.py --weights weights/ --savedir ./output --imagedir images/

Parameters:

  • weights: Directory where the model weights are stored.
  • imagedir: Directory containing the images to be segmented.
  • savedir: Directory where the segmentation results will be saved.

Upon successful execution of the script, the segmented images will be located in the ./output directory. You can access and review the results in this folder.

3. Training the Model

Optional: Train the model with your custom dataset.

This step is optional and should only be undertaken if you intend to train the model yourself with a custom dataset.

  • Create a Custom Dataset and Run train.py

    - datasets
        |—— CCV
        |   |—— train
        |   |   |—— images
        |   |   |   |—— 1.jpg
        |   |   |   |—— 2.jpg
        |   |   |—— masks
        |   |   |   |—— 1.jpg
        |   |   |   |—— 2.jpg
        |   |—— val
        |        |—— images
        |        |   |—— 3.jpg
        |        |   |—— 4.jpg
        |        |—— masks
        |        |   |—— 3.jpg
        |        |   |—— 4.jpg
        |—— CBV
    # Train the CCV model
    CUDA_VISIBLE_DEVICES=0 python train.py --dataDir datasets/ --batch_size 8 --size 416 1024 --region_list CCV brain_area

    region_list specifies the blood vessel needs to be segmented. You can add more vessels by listing additional vessel names.

II. MATLAB Code for Feature Extraction and Quantification of Zebrafish Segmentation Results

Prepare Segmentation Results

Firstly, ensure you have segmented vascular images of zebrafish.

Download Feature Extraction and Quantification Code

Download the MATLAB code for vascular segmentation analysis from the repository.

1. SIVP

- SIVP
    |—— SIV_budding_num_2.m
    |—— SIV_Fluorescent.m
    |—— SIV_hole_area.m
    |—— SIV_other.m
    |—— SIV_function_all.m
    |—— minboundrect.m
    |—— main.m
    |—— Inpoly.m

Follow these steps:

1.1 Download and place all functions in the same folder.

1.2 Modify main.m in MATLAB, adjusting the pathname:

  • scrDir: folder containing images for processing.
  • output_xlsx_path: path to save the extracted features in an Excel file.

1.3 Modify SIV_function_all.m for the image format (png or bmp).

1.4 Run main.m. Results are saved in the specified output path.

2. CBV

- CBV
    |—— CBV_branch_point.m
    |—— CBV_Fluorescent.m
    |—— CBV_Vessel_area.m
    |—— CBV_branch_point_100.m
    |—— CBV_function_all.m
    |—— minboundrect.m
    |—— main.m
    |—— Inpoly.m

Follow similar steps as for SIVP.

3. CCV

- Matlab
    |—— CCV.m
    |—— Globularity.m
    |—— minboundrect.m
    |—— Inpoly.m

Place the functions in the image directory and run CCV.m.

4. DA, PCV, ISV, CVP

- Matlab
    |—— DA.m
    |—— PCV.m
    |—— ISV.m
    |—— CVP.m
    |—— minboundrect.m
    |—— Inpoly.m

Run each MATLAB script after modifying the pathname.

5. View Feature Quantification Results

After executing the feature extraction and quantification code, the program will produce the quantifiable results. These results will either be displayed in the MATLAB command window or saved to the predefined output path.

To effectively utilize the zebrafish segmentation model and the accompanying feature extraction and quantification code, please follow the steps outlined above. For more comprehensive guidance or additional support, consult the documentation provided in the code repository or reach out to the development team.