Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Cullen, PhD authored May 18, 2024
1 parent 7f8267c commit b6335be
Showing 1 changed file with 108 additions and 5 deletions.
113 changes: 108 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,117 @@ Further details about installing ANTsPy or building it from source can be found

## Quickstart

Here is an example of reading in an image, using various utility functions such as resampling and masking, then performing three-class Atropos segmentation.
Here is a basic overview of some of the things you can do with ANTsPy. The main functionality includes reading / writing images, basic and advanced image operations, segmentation, registration, and visualization.

### Reading and writing images

You can read and write images of any format.

```python
import ants
img = ants.image_read(ants.get_data("r16"))
img = ants.resample_image(img, (64,64), 1, 0 )
mask = ants.get_mask(img)
segs1 = ants.atropos(a=img, m='[0.2,1x1]', c='[2,0]', i='kmeans[3]', x=mask)
img = ants.image_read('path/to/image.nii.gz')
ants.image_write(img, 'path/to/image.nii.gz')
```

Printing to the console provides a great deal of metadata information about the image.

```python
print(img)
```

```
ANTsImage
Pixel Type : float (float32)
Components : 1
Dimensions : (256, 256)
Spacing : (1.0, 1.0)
Origin : (0.0, 0.0)
Direction : [1. 0. 0. 1.]
```

### Image operations

#### Basic

Images can be operated on similar to numpy arrays - e.g., all math operations will work as expected.

```python
img = ants.image_read(ants.get_data('r16'))
img2 = ants.image_read(ants.get_data('r64'))

img + img2
img - img2
img * img2
img / img2
img ** 2
```

#### Indexing

You can also index images as you would a numpy array. Where possible, indexing an image will return an image with metadata intact.

```python
img = ants.image_read(ants.get_data('mni')) # 3D image

img[:20,:20,:20] # 3D image
img[:,:,20] # 2D image
img[:,20,20] # 1D array
img[20,20,20] # sigle value

# setting works as well
img[:20,:20,:20] = 10
```

#### Advanced

There is a large collection of advanced image operations that can be performed on images.

```python
img = ants.image_read(ants.get_data('mni')) # 3D image
img = ants.smooth_image(img, 2)
img = ants.resample_image(img, (3,3,3))
img = ants.pad_image(img, pad_width=(4,4,4))
```

And if you ever need to convert to or from numpy, it is straight-forward to do so.

```python
img = ants.image_read(ants.get_data('mni')) # 3D image
arr = img.numpy()
arr += 2
img2 = ants.from_numpy(arr)
```

### Segmentation

Atropos is an example of a powerful three-class segmentation algorithm provided to you.

```python
img = ants.image_read(ants.get_data("r16"))
mask = ants.get_mask(img)
result = ants.atropos(a=img, m='[0.2,1x1]', c='[2,0]', i='kmeans[3]', x=mask)
```

### Registration

The full registration functionality of ANTs is available via the `ants.registration` function.

```python
fixed_image = ants.image_read(ants.get_ants_data('r16')).resample_image((60,60), 1, 0)
moving_image = ants.image_read(ants.get_ants_data('r64')).resample_image((60,60), 1, 0)
mytx = ants.registration(fixed_image, moving_image, type_of_transform = 'SyN' )
```

### Plotting

A diverse set of functions are available to flexibly visualize images, optionally with discrete or continuous overlays. The `ants.plot` function will meet most needs.

```python
img = ants.image_read(ants.get_data("mni")) # 3D image
ants.plot(img)

# with overlay
ants.plot(img, overlay = img > img.mean())
```

<br>
Expand Down

0 comments on commit b6335be

Please sign in to comment.