|
| 1 | +# CLI Reference: Preprocessing |
| 2 | + |
| 3 | +The PrismToolBox CLI provides useful preprocessing capabilities for whole slide images through the `ptb preprocessing` command. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The preprocessing module includes two main commands: |
| 8 | + |
| 9 | +1. **`contouring`**: Extract tissue contours from whole slide images |
| 10 | +2. **`patching`**: Extract patches from slides using tissue contours |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +Make sure you have PrismToolBox installed: |
| 15 | + |
| 16 | +```bash |
| 17 | +# Basic installation |
| 18 | +pip install prismtoolbox |
| 19 | +``` |
| 20 | + |
| 21 | +## Global Options |
| 22 | + |
| 23 | +All preprocessing commands support these global options: |
| 24 | + |
| 25 | +- `--verbose, -v`: Increase verbosity (can be used multiple times: `-v`, `-vv`) |
| 26 | +- `--help`: Show help message |
| 27 | + |
| 28 | +## Commands |
| 29 | + |
| 30 | +### `ptb preprocessing contouring` |
| 31 | + |
| 32 | +Extract tissue contours from whole slide images. |
| 33 | + |
| 34 | +#### Usage |
| 35 | + |
| 36 | +```bash |
| 37 | +ptb preprocessing contouring [OPTIONS] SLIDE_DIRECTORY RESULTS_DIRECTORY |
| 38 | +``` |
| 39 | + |
| 40 | +#### Arguments |
| 41 | + |
| 42 | +- **`SLIDE_DIRECTORY`**: Path to the directory containing the slide files |
| 43 | +- **`RESULTS_DIRECTORY`**: Path to the directory where the results will be saved |
| 44 | + |
| 45 | +#### Options |
| 46 | + |
| 47 | +| Option | Type | Description | Default | |
| 48 | +|--------|------|-------------|---------| |
| 49 | +| `--engine` | `str` | Engine for reading slides (`openslide`, `tiffslide`). | `openslide` | |
| 50 | +| `--annotations-directory` | `str | None` | Path to annotations directory | `None` | |
| 51 | +| `--contours-exts` | `list[str]` | File extensions for contour annotations (`geojson`, `pickle`) | `[pickle]` | |
| 52 | +| `--config-file` | `str` | Path to configuration file | `None` | |
| 53 | +| `--visualize` | `bool` | Visualize the extracted contours | `False` | |
| 54 | + |
| 55 | +#### Configuration File |
| 56 | + |
| 57 | +You can use a YAML configuration file to specify tissue extraction and visualization parameters: |
| 58 | + |
| 59 | +```yaml |
| 60 | +--8<-- "./config/default_contouring.yaml" |
| 61 | +``` |
| 62 | + |
| 63 | +#### Examples |
| 64 | + |
| 65 | +```bash |
| 66 | +# Basic contour extraction |
| 67 | +ptb preprocessing contouring slides/ results/ |
| 68 | + |
| 69 | +# With visualization |
| 70 | +ptb preprocessing contouring slides/ results/ --visualize |
| 71 | + |
| 72 | +# Using custom configuration |
| 73 | +ptb preprocessing contouring slides/ results/ --config-file custom_config.yaml |
| 74 | + |
| 75 | +# With annotations and multiple output formats |
| 76 | +ptb preprocessing contouring slides/ results/ --annotations-directory annotations/ --contours-exts pickle geojson --visualize |
| 77 | +``` |
| 78 | + |
| 79 | +### `ptb preprocessing patching` |
| 80 | + |
| 81 | +Extract patches from slides using tissue contours. |
| 82 | + |
| 83 | +#### Usage |
| 84 | + |
| 85 | +```bash |
| 86 | +ptb preprocessing patching [OPTIONS] SLIDE_DIRECTORY RESULTS_DIRECTORY |
| 87 | +``` |
| 88 | + |
| 89 | +#### Arguments |
| 90 | + |
| 91 | +- **`SLIDE_DIRECTORY`**: Path to the directory containing the slide files |
| 92 | +- **`RESULTS_DIRECTORY`**: Path to the directory where the results will be saved |
| 93 | + |
| 94 | +#### Options |
| 95 | + |
| 96 | +| Option | Type | Description | Default | |
| 97 | +|--------|------|-------------|---------| |
| 98 | +| `--contours-directory` | `str | None` | Path to directory containing contour annotations | `None` | |
| 99 | +| `--engine` | `str` | Engine for reading slides | `openslide` | |
| 100 | +| `--mode` | `str` | Extraction mode (`contours`, `roi`, `all`) | `contours` | |
| 101 | +| `--patch-exts` | `list[str]` | File extensions for patches (`h5`, `geojson`) |`[h5]` | |
| 102 | +| `--config-file` | `str | None` | Path to configuration file | `None` | |
| 103 | + |
| 104 | +#### Configuration File |
| 105 | + |
| 106 | +Example configuration for patch extraction: |
| 107 | + |
| 108 | +```yaml |
| 109 | +--8<-- "./config/default_patching.yaml" |
| 110 | +``` |
| 111 | + |
| 112 | +#### Examples |
| 113 | + |
| 114 | +```bash |
| 115 | +# Basic patch extraction |
| 116 | +ptb preprocessing patching slides/ results/ --contours-directory results/contours/ |
| 117 | + |
| 118 | +# With custom configuration |
| 119 | +ptb preprocessing patching slides/ results/ --contours-directory results/contours/ --config-file patch_config.yaml |
| 120 | + |
| 121 | +# Extract patches in multiple formats |
| 122 | +ptb preprocessing patching slides/ results/ --contours-directory results/contours/ --patch-exts h5 geojson |
| 123 | +``` |
| 124 | + |
| 125 | +## Complete Workflow Example |
| 126 | + |
| 127 | +Here's a complete example of processing a dataset: |
| 128 | + |
| 129 | +```bash |
| 130 | +# Step 1: Extract tissue contours with visualization |
| 131 | +ptb preprocessing contouring slides/ results/ --visualize --config-file tissue_config.yaml |
| 132 | + |
| 133 | +# Step 2: Extract patches from the contours |
| 134 | +ptb preprocessing patching slides/ results/ --contours-directory results/contours/ --config-file patch_config.yaml --patch-exts geojson |
| 135 | + |
| 136 | +# Results will be saved in: |
| 137 | +# - results/contours/ (tissue contours) |
| 138 | +# - results/contoured_images/ (visualizations) |
| 139 | +# - results/patches_256_ovelap_0/ (extracted patches) |
| 140 | +# - results/stitched_images_256_ovelap_0/ (patch visualizations) |
| 141 | +``` |
| 142 | + |
| 143 | +## Error Handling |
| 144 | + |
| 145 | +Common issues and solutions: |
| 146 | + |
| 147 | +### Missing Dependencies |
| 148 | + |
| 149 | +```bash |
| 150 | +Error: Segmentation features require additional dependencies. |
| 151 | +Please install with: pip install prismtoolbox[seg] |
| 152 | +``` |
| 153 | + |
| 154 | +**Solution**: Install the required dependencies: |
| 155 | +```bash |
| 156 | +pip install prismtoolbox[seg,emb] |
| 157 | +``` |
| 158 | + |
| 159 | +### Configuration File Issues |
| 160 | + |
| 161 | +```bash |
| 162 | +Warning: Incomplete tissue extraction parameters in config file |
| 163 | +``` |
| 164 | + |
| 165 | +**Solution**: Ensure your configuration file contains all required parameters for each section. |
| 166 | + |
| 167 | +### File Path Issues |
| 168 | + |
| 169 | +```bash |
| 170 | +Error: No valid config file found. Using default parameters. |
| 171 | +``` |
| 172 | + |
| 173 | +**Solution**: Check that your configuration file path is correct and the file exists. |
| 174 | + |
| 175 | +## Tips and Best Practices |
| 176 | + |
| 177 | +1. **Start with visualization**: Use `--visualize` flag to check if tissue detection works correctly |
| 178 | +2. **Test with small datasets**: Process a few slides first to validate your parameters |
| 179 | +3. **Use configuration files**: Store your parameters in YAML files for reproducibility |
| 180 | +4. **Monitor output**: Use verbose mode (`-v` or `-vv`) to see detailed processing information |
0 commit comments