https://github.com/dyollb/itktopologycontrol
ITK external module to control topology of binary mask regions
https://github.com/dyollb/itktopologycontrol
cpp image-preprocessing itk itk-module python segmentation
Last synced: 12 months ago
JSON representation
ITK external module to control topology of binary mask regions
- Host: GitHub
- URL: https://github.com/dyollb/itktopologycontrol
- Owner: dyollb
- License: apache-2.0
- Created: 2022-08-24T19:08:10.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-10T06:10:53.000Z (over 1 year ago)
- Last Synced: 2025-03-27T10:21:33.485Z (about 1 year ago)
- Topics: cpp, image-preprocessing, itk, itk-module, python, segmentation
- Language: C++
- Homepage:
- Size: 5.24 MB
- Stars: 1
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ITKTopologyControl
[](https://github.com/dyollb/ITKTopologyControl/actions)
[](https://github.com/dyollb/ITKTopologyControl/blob/main/LICENSE)
[](https://badge.fury.io/py/itk-topologycontrol)

## Overview
This is a module for the Insight Toolkit ([ITK](https://github.com/InsightSoftwareConsortium/ITK)). The module includes a filter called `FixTopologyCarveOutside` which works like morphological closing, except that in the "erode" phase topological constraints are enforced to avoid re-opening holes. It is able to close holes in thin layers (e.g. skull) with a minimal thickness.
```python
import itk
skull_mask = itk.imread('path/to/skull_with_holes.mha').astype(itk.US)
ImageType = type(skull_mask)
MaskType = itk.Image[itk.UC, 3]
top_control = itk.FixTopologyCarveOutside[ImageType, ImageType, MaskType].New()
top_control.SetInput(skull_mask)
top_control.SetRadius(5)
top_control.Update()
skull_mask_closed = top_control.GetOutput()
itk.imwrite(skull_mask_closed, 'skull_mask_closed.mha')
```
Or using a custom mask (e.g. a sphere around a hole):
```python
import itk
custom_mask = itk.imread('path/to/custom_mask.mha').astype(itk.UC)
skull_mask = itk.imread('path/to/skull_with_holes.mha').astype(itk.US)
skull_mask_closed = itk.fix_topology_carve_outside(skull_mask, MaskImage=custom_mask, Radius=5)
itk.imwrite(skull_mask_closed, 'skull_mask_closed.mha')
```

## Installation
To install the binary Python packages:
```shell
python -m pip install itk-topologycontrol
```