Image Segmentation
medical
biology
File size: 4,852 Bytes
ee42561
 
 
 
 
 
 
 
4e78183
ee42561
 
 
 
 
4e78183
ee42561
4e78183
ee42561
 
 
 
 
 
 
 
4e78183
ee42561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e78183
ee42561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e78183
ee42561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e78183
ee42561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e78183
ee42561
 
 
 
 
 
4e78183
 
 
ee42561
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
license: agpl-3.0
pipeline_tag: image-segmentation
tags:
- medical
- biology
---

# πŸ‘οΈ VascX models

This repository contains the instructions for using the VascX models from the paper [VascX Models: Model Ensembles for Retinal Vascular Analysis from Color Fundus Images](https://arxiv.org/abs/2409.16016).

The model weights are in [huggingface](https://huggingface.co/Eyened/vascx).

<img src="imgs/samples_vascx_hrf.png">

## πŸ› οΈ Installation

To install the entire fundus analysis pipeline including fundus preprocessing, model inference code and vascular biomarker extraction:

1. Create a conda or virtualenv virtual environment, or otherwise ensure a clean environment.

2. Install the [rtnls_inference package](https://github.com/Eyened/retinalysis-inference).


## πŸš€ `vascx run` Command

The `run` command provides a comprehensive pipeline for processing fundus images, performing various analyses, and creating visualizations.

### Usage

```bash
vascx run DATA_PATH OUTPUT_PATH [OPTIONS]
```

### Arguments

- `DATA_PATH`: Path to input data. Can be either:
  - A directory containing fundus images
  - A CSV file with a 'path' column containing paths to images

- `OUTPUT_PATH`: Directory where processed results will be stored

### Options

| Option | Default | Description |
|--------|---------|-------------|
| `--preprocess/--no-preprocess` | `--preprocess` | Run preprocessing to standardize images for model input |
| `--vessels/--no-vessels` | `--vessels` | Run vessel segmentation and artery-vein classification |
| `--disc/--no-disc` | `--disc` | Run optic disc segmentation |
| `--quality/--no-quality` | `--quality` | Run image quality assessment |
| `--fovea/--no-fovea` | `--fovea` | Run fovea detection |
| `--overlay/--no-overlay` | `--overlay` | Create visualization overlays combining all results |
| `--n_jobs` | `4` | Number of preprocessing workers for parallel processing |

### πŸ“ Output Structure

When run with default options, the command creates the following structure in `OUTPUT_PATH`:

```
OUTPUT_PATH/
β”œβ”€β”€ preprocessed_rgb/     # Standardized fundus images
β”œβ”€β”€ vessels/              # Vessel segmentation results
β”œβ”€β”€ artery_vein/          # Artery-vein classification
β”œβ”€β”€ disc/                 # Optic disc segmentation
β”œβ”€β”€ overlays/             # Visualization images
β”œβ”€β”€ bounds.csv            # Image boundary information
β”œβ”€β”€ quality.csv           # Image quality scores
└── fovea.csv             # Fovea coordinates
```

### πŸ”„ Processing Stages

1. **Preprocessing**: 
   - Standardizes input images for consistent analysis
   - Outputs preprocessed images and boundary information

2. **Quality Assessment**:
   - Evaluates image quality with three quality metrics (q1, q2, q3)
   - Higher scores indicate better image quality

3. **Vessel Segmentation and Artery-Vein Classification**:
   - Identifies blood vessels in the retina
   - Classifies vessels as arteries (1) or veins (2) with intersections (3)

4. **Optic Disc Segmentation**:
   - Identifies the optic disc location and boundaries

5. **Fovea Detection**:
   - Determines the coordinates of the fovea (center of vision)

6. **Visualization Overlays**:
   - Creates color-coded images showing:
     - Arteries in red
     - Veins in blue
     - Optic disc in white
     - Fovea marked with yellow X

### πŸ’» Examples

**Process a directory of images with all analyses:**
```bash
vascx run /path/to/images /path/to/output
```

**Process specific images listed in a CSV:**
```bash
vascx run /path/to/image_list.csv /path/to/output
```

**Only run preprocessing and vessel segmentation:**
```bash
vascx run /path/to/images /path/to/output --no-disc --no-quality --no-fovea --no-overlay
```

**Skip preprocessing on already preprocessed images:**
```bash
vascx run /path/to/preprocessed/images /path/to/output --no-preprocess
```

**Increase parallel processing workers:**
```bash
vascx run /path/to/images /path/to/output --n_jobs 8
```

### πŸ“ Notes

- The CSV input must contain a 'path' column with image file paths
- If the CSV includes an 'id' column, these IDs will be used instead of filenames
- When `--no-preprocess` is used, input images must already be in the proper format
- The overlay visualization requires at least one analysis component to be enabled

## πŸ““ Notebooks

For more advanced usage, we have Jupyter notebooks showing how preprocessing and inference are run.

To speed up re-execution of vascx we recommend to run the preprocessing and segmentation steps separately:

1. Preprocessing. See [this notebook](./notebooks/0_preprocess.ipynb). This step is CPU-heavy and benefits from parallelization (see notebook).

2. Inference. See [this notebook](./notebooks/1_segment_preprocessed.ipynb). All models can be ran in a single GPU with >10GB VRAM.