|
| 1 | +# RFC 4: Anatomical Orientation Support |
| 2 | + |
| 3 | +RFC 4 adds support for anatomical orientation metadata to OME-NGFF axes, |
| 4 | +enabling precise description of spatial axis directions in biological and |
| 5 | +medical imaging data. |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +Anatomical orientation refers to the specific arrangement and directional |
| 10 | +alignment of anatomical structures within an imaging dataset. This is crucial |
| 11 | +for ensuring accurate alignment and comparison of images to anatomical atlases, |
| 12 | +facilitating consistent analysis and interpretation of biological data. |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +### Programmatic Usage |
| 17 | + |
| 18 | +#### Enabling RFC 4 |
| 19 | + |
| 20 | +To enable RFC 4 support when writing OME-NGFF Zarr data, include `4` in the |
| 21 | +`enabled_rfcs` parameter: |
| 22 | + |
| 23 | +```python |
| 24 | +import ngff_zarr |
| 25 | + |
| 26 | +# Enable RFC 4 when converting to NGFF Zarr |
| 27 | +ngff_zarr.to_ngff_zarr( |
| 28 | + store="output.ome.zarr", |
| 29 | + multiscales=multiscales, |
| 30 | + enabled_rfcs=[4] # Enable RFC 4 |
| 31 | +) |
| 32 | +``` |
| 33 | + |
| 34 | +### CLI Usage |
| 35 | + |
| 36 | +RFC 4 can be enabled via the command line using the `--enable-rfc` flag: |
| 37 | + |
| 38 | +```bash |
| 39 | +# Convert a medical image with RFC 4 anatomical orientation enabled |
| 40 | +ngff-zarr -i image.nii.gz -o output.ome.zarr --enable-rfc 4 |
| 41 | + |
| 42 | +# Enable multiple RFCs (when available) |
| 43 | +ngff-zarr -i image.nii.gz -o output.ome.zarr --enable-rfc 4 --enable-rfc 5 |
| 44 | + |
| 45 | +# Without RFC 4 (default behavior - orientation metadata filtered out) |
| 46 | +ngff-zarr -i image.nii.gz -o output.ome.zarr |
| 47 | +``` |
| 48 | + |
| 49 | +### ITK Integration |
| 50 | + |
| 51 | +When converting ITK images (including from NRRD, NIfTI, or DICOM formats), |
| 52 | +anatomical orientation is automatically added based on ITK's LPS coordinate |
| 53 | +system: |
| 54 | + |
| 55 | +```python |
| 56 | +import ngff_zarr |
| 57 | +import itk |
| 58 | + |
| 59 | +# Read a medical image (NRRD, NIfTI, DICOM, etc.) |
| 60 | +image = itk.imread("image.nrrd") |
| 61 | + |
| 62 | +# Convert to NGFF image with anatomical orientation |
| 63 | +ngff_image = ngff_zarr.itk_image_to_ngff_image( |
| 64 | + image, |
| 65 | + add_anatomical_orientation=True |
| 66 | +) |
| 67 | + |
| 68 | +# Convert to multiscales and write to Zarr with RFC 4 enabled |
| 69 | +multiscales = ngff_zarr.to_multiscales(ngff_image) |
| 70 | +ngff_zarr.to_ngff_zarr( |
| 71 | + store="output.ome.zarr", |
| 72 | + multiscales=multiscales, |
| 73 | + enabled_rfcs=[4] |
| 74 | +) |
| 75 | +``` |
| 76 | + |
| 77 | +### ITK-Wasm Integration |
| 78 | + |
| 79 | +Similar support is available for ITK-Wasm: |
| 80 | + |
| 81 | +```python |
| 82 | +import ngff_zarr |
| 83 | +import itkwasm |
| 84 | + |
| 85 | +# Read with ITK-Wasm |
| 86 | +image = itkwasm.imread("image.nii.gz") |
| 87 | + |
| 88 | +# Convert with anatomical orientation |
| 89 | +ngff_image = ngff_zarr.itk_image_to_ngff_image( |
| 90 | + image, |
| 91 | + add_anatomical_orientation=True |
| 92 | +) |
| 93 | +``` |
| 94 | + |
| 95 | +## Anatomical Orientation Values |
| 96 | + |
| 97 | +RFC 4 supports the following anatomical orientation values: |
| 98 | + |
| 99 | +- `left-to-right`: From left side to right lateral side |
| 100 | +- `right-to-left`: From right side to left lateral side |
| 101 | +- `anterior-to-posterior`: From front (anterior) to back (posterior) |
| 102 | +- `posterior-to-anterior`: From back (posterior) to front (anterior) |
| 103 | +- `inferior-to-superior`: From below (inferior) to above (superior) |
| 104 | +- `superior-to-inferior`: From above (superior) to below (inferior) |
| 105 | +- `dorsal-to-ventral`: From top/upper (dorsal) to belly/lower (ventral) |
| 106 | +- `ventral-to-dorsal`: From belly/lower (ventral) to top/upper (dorsal) |
| 107 | +- `dorsal-to-palmar`: From top/upper (dorsal) to palm of hand (palmar) |
| 108 | +- `palmar-to-dorsal`: From palm of hand (palmar) to top/upper (dorsal) |
| 109 | +- `dorsal-to-plantar`: From top/upper (dorsal) to sole of foot (plantar) |
| 110 | +- `plantar-to-dorsal`: From sole of foot (plantar) to top/upper (dorsal) |
| 111 | + |
| 112 | +## ITK LPS Coordinate System |
| 113 | + |
| 114 | +ITK uses the LPS (Left-to-right, Posterior-to-anterior, Superior-to-inferior) |
| 115 | +coordinate system by default. When converting ITK images, the following mappings |
| 116 | +are applied: |
| 117 | + |
| 118 | +- **X axis**: `left-to-right` |
| 119 | +- **Y axis**: `posterior-to-anterior` |
| 120 | +- **Z axis**: `inferior-to-superior` |
| 121 | + |
| 122 | +## Manual Orientation Specification |
| 123 | + |
| 124 | +You can also manually specify orientations: |
| 125 | + |
| 126 | +```python |
| 127 | +from ngff_zarr import ( |
| 128 | + AnatomicalOrientation, |
| 129 | + AnatomicalOrientationValues, |
| 130 | + NgffImage |
| 131 | +) |
| 132 | +import dask.array as da |
| 133 | + |
| 134 | +# Create orientation objects |
| 135 | +x_orientation = AnatomicalOrientation( |
| 136 | + value=AnatomicalOrientationValues.left_to_right |
| 137 | +) |
| 138 | +y_orientation = AnatomicalOrientation( |
| 139 | + value=AnatomicalOrientationValues.anterior_to_posterior |
| 140 | +) |
| 141 | +z_orientation = AnatomicalOrientation( |
| 142 | + value=AnatomicalOrientationValues.inferior_to_superior |
| 143 | +) |
| 144 | + |
| 145 | +# Create NGFF image with orientations |
| 146 | +data = da.zeros((100, 100, 100)) |
| 147 | +ngff_image = NgffImage( |
| 148 | + data=data, |
| 149 | + dims=("z", "y", "x"), |
| 150 | + scale={"x": 1.0, "y": 1.0, "z": 1.0}, |
| 151 | + translation={"x": 0.0, "y": 0.0, "z": 0.0}, |
| 152 | + axes_orientations={ |
| 153 | + "x": x_orientation, |
| 154 | + "y": y_orientation, |
| 155 | + "z": z_orientation |
| 156 | + } |
| 157 | +) |
| 158 | +``` |
| 159 | + |
| 160 | +## Metadata Format |
| 161 | + |
| 162 | +When RFC 4 is enabled, spatial axes in the OME-NGFF metadata include an |
| 163 | +`orientation` field: |
| 164 | + |
| 165 | +```json |
| 166 | +{ |
| 167 | + "axes": [ |
| 168 | + { |
| 169 | + "name": "z", |
| 170 | + "type": "space", |
| 171 | + "unit": "micrometer", |
| 172 | + "orientation": { |
| 173 | + "type": "anatomical", |
| 174 | + "value": "inferior-to-superior" |
| 175 | + } |
| 176 | + }, |
| 177 | + { |
| 178 | + "name": "y", |
| 179 | + "type": "space", |
| 180 | + "unit": "micrometer", |
| 181 | + "orientation": { |
| 182 | + "type": "anatomical", |
| 183 | + "value": "posterior-to-anterior" |
| 184 | + } |
| 185 | + }, |
| 186 | + { |
| 187 | + "name": "x", |
| 188 | + "type": "space", |
| 189 | + "unit": "micrometer", |
| 190 | + "orientation": { |
| 191 | + "type": "anatomical", |
| 192 | + "value": "left-to-right" |
| 193 | + } |
| 194 | + } |
| 195 | + ] |
| 196 | +} |
| 197 | +``` |
| 198 | + |
| 199 | +## RFC 4 Functions |
| 200 | + |
| 201 | +### Core Functions |
| 202 | + |
| 203 | +- `is_rfc4_enabled(enabled_rfcs)`: Check if RFC 4 is enabled |
| 204 | +- `itk_lps_to_anatomical_orientation(axis_name)`: Map ITK LPS axes to |
| 205 | + orientations |
| 206 | +- `add_anatomical_orientation_to_axis(axis_dict, orientation)`: Add orientation |
| 207 | + to axis |
| 208 | +- `remove_anatomical_orientation_from_axis(axis_dict)`: Remove orientation from |
| 209 | + axis |
| 210 | + |
| 211 | +### Data Classes |
| 212 | + |
| 213 | +- `AnatomicalOrientation`: Orientation specification with type and value |
| 214 | +- `AnatomicalOrientationValues`: Enum of supported orientation values |
| 215 | + |
| 216 | +## Compatibility |
| 217 | + |
| 218 | +When RFC 4 is not enabled (the default), orientation metadata is automatically |
| 219 | +filtered out during Zarr writing to maintain compatibility with standard |
| 220 | +OME-NGFF consumers. |
| 221 | + |
| 222 | +## Best Practices |
| 223 | + |
| 224 | +1. **Enable RFC 4** when working with medical/biological images where |
| 225 | + orientation matters |
| 226 | +2. **Use ITK integration** for automatic LPS-based orientation when converting |
| 227 | + from medical image formats |
| 228 | +3. **Document orientation assumptions** in your analysis pipelines when working |
| 229 | + with oriented data |
| 230 | +4. **Validate orientations** match your expectations, especially when combining |
| 231 | + data from different sources |
0 commit comments