Skip to content

Commit

Permalink
Merge branch 'main' of github.com:FNNDSC/pl-fetal-surface-extract
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Feb 20, 2023
2 parents 9c4005f + d7e405f commit 2670592
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 52 deletions.
33 changes: 14 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
build:
name: Build
if: github.event_name == 'push' || github.event_name == 'release'
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

# A local registry helps us reuse the built image between steps
services:
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Get git tag
id: git_info
if: startsWith(github.ref, 'refs/tags/')
run: echo "::set-output name=tag::${GITHUB_REF##*/}"
run: echo "tag=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
- name: Get project info
id: determine
env:
Expand All @@ -42,49 +42,45 @@ jobs:
repo="${GITHUB_REPOSITORY,,}" # to lower case
# if build triggered by tag, use tag name
tag="${git_tag:-latest}"
# if tag is a version number prefixed by 'v', remove the 'v'
if [[ "$tag" =~ ^v[0-9].* ]]; then
tag="${tag:1}"
fi
dock_image=$repo:$tag
echo $dock_image
echo "::set-output name=dock_image::$dock_image"
echo "::set-output name=repo::$repo"
- uses: actions/checkout@v2
echo "dock_image=$dock_image" >> $GITHUB_OUTPUT
echo "repo=$repo" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
# QEMU is used for non-x86_64 builds
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-qemu-action@v2
# buildx adds additional features to docker build
- uses: docker/setup-buildx-action@v1
- uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
# cache slightly improves rebuild time
- name: Cache Docker layers
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
id: dockerhub_login
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
id: docker_build
with:
context: .
Expand All @@ -105,10 +101,9 @@ jobs:
dock_image=${{ steps.determine.outputs.dock_image }}
docker run --rm localhost:5000/$dock_image chris_plugin_info > /tmp/description.json
jq < /tmp/description.json # pretty print in log
echo "::set-output name=title::$(jq -r '.title' < /tmp/description.json)"
echo "title=$(jq -r '.title' < /tmp/description.json)" >> $GITHUB_OUTPUT
- name: Update DockerHub description
uses: peter-evans/dockerhub-description@v2
uses: peter-evans/dockerhub-description@v3
continue-on-error: true # it is not crucial that this works
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
Expand All @@ -118,7 +113,7 @@ jobs:
repository: ${{ steps.determine.outputs.repo }}

- name: Upload to ChRIS Store
if: github.event_name == 'release'
if: steps.git_info.outcome != 'skipped'
uses: FNNDSC/chrisstore-action@master
with:
descriptor_file: /tmp/description.json
Expand Down
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Fetal CP Surface Extraction

[![Version](https://img.shields.io/docker/v/fnndsc/pl-fetal-cp-surface-extract?sort=semver)](https://hub.docker.com/r/fnndsc/pl-fetal-cp-surface-extract)
[![MIT License](https://img.shields.io/github/license/fnndsc/pl-fetal-cp-surface-extract)](https://github.com/FNNDSC/pl-fetal-cp-surface-extract/blob/main/LICENSE)
[![ci](https://github.com/FNNDSC/pl-fetal-cp-surface-extract/actions/workflows/ci.yml/badge.svg)](https://github.com/FNNDSC/pl-fetal-cp-surface-extract/actions/workflows/ci.yml)
[![Version](https://img.shields.io/docker/v/fnndsc/pl-fetal-surface-extract?sort=semver)](https://hub.docker.com/r/fnndsc/pl-fetal-surface-extract)
[![MIT License](https://img.shields.io/github/license/fnndsc/pl-fetal-surface-extract)](https://github.com/FNNDSC/pl-fetal-surface-extract/blob/main/LICENSE)
[![ci](https://github.com/FNNDSC/pl-fetal-surface-extract/actions/workflows/ci.yml/badge.svg)](https://github.com/FNNDSC/pl-fetal-surface-extract/actions/workflows/ci.yml)

Fetal brain cortical plate surface extraction using CIVET marching-cubes (`sphere_mesh`).

![Figure](docs/fig.png)

## Abstract

`pl-fetal-cp-surface-extract` consumes binary volumetric `.mnc` brain masks to produce
`pl-fetal-surface-extract` consumes binary volumetric `.mnc` brain masks to produce
surfaces as `.obj` files with standard connectivity (81,920 triangles). This program is
suitable for targeting the **inner cortical plate** surface (gray-white matter boundary)
of high-quality human fetal brain MRI segmentation for subjects between 23-35 gestational
Expand All @@ -21,29 +21,29 @@ weeks of age.
Polygonal surface mesh representations of brain hemispheres are useful for measuring cortical
thickness, image registration, and quantitative regional analysis.

## Marching Cubes
## Surface Extraction Algorithm

1. Preprocess mask using `mincmorph` to fill in disconnected voxels (improve mask quality)
2. Marching-cubes -> spherical topology surface mesh with unknown number of triangles
3. Calculate distance error
4. _If_ maximum distance error is too large, _then_ redo marching-cubes with subsampling
5. Sphere-to-sphere interpolation -> resample mesh to standard connectivity of 81,920 triangles, preserving morphology
6. Calculate smoothness error
7. Run `adapt_object_mesh` to achieve desired smoothness. Number of iterations is predicted by a regression

### Marching Cubes

We have evaluated two implementations of marching-cubes:

- [scikit-image](https://github.com/FNNDSC/pl-fetal-cp-surface-extract)
- [scikit-image](https://github.com/FNNDSC/pl-fetal-surface-extract)
- [CIVET](https://github.com/FNNDSC/ep-sphere_mesh)

We found that CIVET's implementation of the marching-cubes algorithm, `sphere_mesh`, is
[more accurate](docs/compare_civet_skimage.md)
than scikit-image's implementation, which requires FWHM blurring of the volume.
Moreover, `sphere_mesh` guarantees a spherical topology.

## Surface Extraction Algorithm

1. Preprocess mask using `mincmorph` to fill in disconnected voxels (improve mask quality)
2. Marching-cubes -> spherical topology surface mesh with unknown number of triangles
3. Calculate distance error
4. _If_ maximum distance error is too large, _then_ redo marching-cubes with subsampling
5. Sphere-to-sphere interpolation -> resample mesh to standard connectivity of 81,920 triangles, preserving morphology
6. Calculate smoothness error
7. Run `adapt_object_mesh` to achieve desired smoothness. Number of iterations is predicted by a regression model

### Estimation of: How much smoothing?
### How much Smoothing? Estimation

We developed a model which predicts the number of `adapt_object_mesh` smoothing iterations necessary, given a desired smoothness error threshold.
The model was created from the experiment described here:
Expand All @@ -55,7 +55,7 @@ The model was created from the experiment described here:
1. https://github.com/FNNDSC/ep-premc-mincmorph
2. https://github.com/FNNDSC/pl-nums2mask
3. https://github.com/FNNDSC/pl-subdiv-minc TODO
4. pl-fetal-cp-surface-extract
4. pl-fetal-surface-extract
5. pl-extracted-surface-asp TODO

<!--
Expand All @@ -67,10 +67,10 @@ without the extra step the accuracy is nonetheless sufficient.

## Installation

`pl-fetal-cp-surface-extract` is a _[ChRIS](https://chrisproject.org/) plugin_, meaning it can
`pl-fetal-surface-extract` is a _[ChRIS](https://chrisproject.org/) plugin_, meaning it can
run from either within _ChRIS_ or the command-line.

[![Get it from chrisstore.co](https://raw.githubusercontent.com/FNNDSC/ChRIS_store_ui/963938c241636e4c3dc4753ee1327f56cb82d8b5/src/assets/public/badges/light.svg)](https://chrisstore.co/plugin/pl-fetal-cp-surface-extract)
[![Get it from chrisstore.co](https://raw.githubusercontent.com/FNNDSC/ChRIS_store_ui/963938c241636e4c3dc4753ee1327f56cb82d8b5/src/assets/public/badges/light.svg)](https://chrisstore.co/plugin/pl-fetal-surface-extract)

## Usage

Expand Down Expand Up @@ -98,31 +98,31 @@ values shouldn't do any harm, and would help compensate for larger brain sizes.

Copy input mask file to output directory.

`--keep-mask` is a workaround for using `pl-fetal-cp-surface-extract` as part of a
`--keep-mask` is a workaround for using `pl-fetal-surface-extract` as part of a
_ChRIS_ pipeline. It eliminates the need for an extra _ts_ plugin step.

## Local Usage

To get started with local command-line usage, use [Apptainer](https://apptainer.org/)
to run `pl-fetal-cp-surface-extract` as a container:
to run `pl-fetal-surface-extract` as a container:

```shell
apptainer exec docker://fnndsc/pl-fetal-cp-surface-extract extract_cp input/ output/
apptainer exec docker://fnndsc/pl-fetal-surface-extract extract_cp input/ output/
```

To print its available options, run:

```shell
apptainer exec docker://fnndsc/pl-fetal-cp-surface-extract extract_cp --help
apptainer exec docker://fnndsc/pl-fetal-surface-extract extract_cp --help
```

## Suggested Software

### Before `pl-fetal-cp-surface-extract`
### Before `pl-fetal-surface-extract`

- [`pl-nums2mask`](https://chrisstore.co/plugin/pl-nums2mask): create input masks

### After `pl-fetal-cp-surface-extract`
### After `pl-fetal-surface-extract`

- [`pl-surfdisterr`](https://chrisstore.co/plugin/pl-surfdisterr): QC
- [`pl-smoothness-error`](https://chrisstore.co/plugin/pl-smoothness-error): QC
Expand All @@ -136,7 +136,7 @@ Instructions for developers.
Build a local container image:

```shell
docker build -t localhost/fnndsc/pl-fetal-cp-surface-extract .
docker build -t localhost/fnndsc/pl-fetal-surface-extract .
```

### Get JSON Representation
Expand All @@ -145,7 +145,7 @@ Run [`chris_plugin_info`](https://github.com/FNNDSC/chris_plugin#usage)
to produce a JSON description of this plugin, which can be uploaded to a _ChRIS Store_.

```shell
docker run --rm localhost/fnndsc/pl-fetal-cp-surface-extract chris_plugin_info > chris_plugin_info.json
docker run --rm localhost/fnndsc/pl-fetal-surface-extract chris_plugin_info > chris_plugin_info.json
```

### Local Test Run
Expand All @@ -156,5 +156,5 @@ Mount the source code `extract_cp.py` into a container to test changes without r
docker run --rm -it --userns=host -u $(id -u):$(id -g) \
-v $PWD/extract_cp:/opt/conda/lib/python3.10/site-packages/extract_cp:ro \
-v $PWD/in:/incoming:ro -v $PWD/out:/outgoing:rw -w /outgoing \
localhost/fnndsc/pl-fetal-cp-surface-extract extract_cp /incoming /outgoing
localhost/fnndsc/pl-fetal-surface-extract extract_cp /incoming /outgoing
```
2 changes: 1 addition & 1 deletion docs/compare_civet_skimage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Brief comparison of marching-cubes implementations between
[scikit-image](https://github.com/FNNDSC/pl-fetal-cp-surface-extract)
[scikit-image](https://github.com/FNNDSC/pl-fetal-surface-extract)
and [CIVET](https://github.com/FNNDSC/ep-sphere_mesh).

Cost function is mean
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from setuptools import setup
from setuptools import setup, find_packages

setup(
name='extract_cp',
version='2.0.1',
description='Fetal brain MRI CP surface extraction using CIVET marching-cubes',
author='Jennings Zhang',
author_email='[email protected]',
url='https://github.com/FNNDSC/pl-fetal-cp-surface-extract',
packages=['extract_cp'],
url='https://github.com/FNNDSC/pl-fetal-surface-extract',
packages=find_packages(exclude=['tests']),
install_requires=['chris_plugin', 'loguru', 'pycivet', 'pybicpl', 'numpy'],
license='MIT',
entry_points={
Expand Down

0 comments on commit 2670592

Please sign in to comment.