Skip to content

Commit 6a6518f

Browse files
committed
update: 1.0.2; Interface cleanup; Documentation fixes; Added ijk2xyz and xyz2ijk functions
1 parent f72a715 commit 6a6518f

File tree

10 files changed

+228
-151
lines changed

10 files changed

+228
-151
lines changed

Cargo.lock

Lines changed: 17 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nii-rs"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "Rust library for reading/writing NIfTI files, with SimpleITK/Nibabel-like APIs, native Rust support, and Python bindings for cross-language performance."
@@ -27,6 +27,6 @@ nifti = { version = "0.16.0", features = [
2727
] }
2828
num-traits = "0.2.19"
2929
rayon = "1.10.0"
30-
simba = "0.8.1"
30+
simba = "0.9.0"
3131
numpy = "0.23.0"
3232
paste = "1.0.15"

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,36 @@
22

33
Rust library for reading/writing NIfTI-1 (nii.gz) files, with SimpleITK/NiBabel-like APIs, native Rust support, and Python bindings for cross-language performance.
44

5-
If you have used SimpleITK/NiNabel, you will definitely love this and get started right away! 🕶
5+
If you have used SimpleITK/NiBabel, you will definitely love this and get started right away! 🕶
66

77
## 🎨Features
88

99
- 🚀**Pure Rust Implementation**: Thanks to [nifti-rs](https://github.com/Enet4/nifti-rs), I/O speed is comparable to SimpleITK and slightly faster than NiBabel.
1010

11-
-**Carefully Designed API**: *Super easy to use*, with no learning curve; enjoy a consistent experience in Rust as in Python.
11+
-**Carefully Designed API**: _Super easy to use_, with no learning curve; enjoy a consistent experience in Rust as in Python. Ideal for developers familiar with ITK-style libraries.
1212

13-
- 🛠️**Rust-Python bindings**: you can write heavy operations in Rust and easily call them in Python.
13+
- 🛠️**Rust-Python bindings**: Write heavy operations in Rust and easily call them in Python, combining the performance of Rust with the flexibility of Python.
1414

1515
## 🔨Install
1616

17-
`cargo add nii-rs` for rust project and `pip install niirs` for python.
17+
For Rust projects, add the following to your `Cargo.toml`:
18+
19+
```toml
20+
[dependencies]
21+
nii-rs = "*"
22+
```
23+
24+
For Python, install via pip:
25+
26+
```sh
27+
pip install niirs
28+
```
1829

1930
## 🥒Develop
2031

21-
`maturin dev`
32+
To start developing with nii-rs, use the following command:
33+
34+
`maturin dev -r`
2235

2336
## 📘Examples
2437

@@ -48,11 +61,12 @@ nii::write_image(&im, "result.nii.gz")
4861
```
4962

5063
### 🐍Python
64+
5165
```python
52-
import niirs
66+
import nii
5367

5468
# read image
55-
im = niirs.read_image("test.nii.gz")
69+
im = nii.read_image("test.nii.gz")
5670

5771
# get attrs, style same as like SimpleITK
5872
spacing = im.get_spacing()
@@ -66,7 +80,7 @@ affine = im.get_affine()
6680
arr = im.ndarray()
6781

6882
# write image
69-
niirs.write_image(im, "result.nii.gz")
83+
nii.write_image(im, "result.nii.gz")
7084
```
7185

7286
## 🔒License

examples/tutorial.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import niirs
1+
import nii
22
import numpy as np
33

44
pth = rf"test_data\test.nii.gz"
55

6-
im = niirs.read_image(pth, dtype=np.float32)
6+
im = nii.read_image(pth, dtype=np.float32)
77

88
# get attrs, style same as like ITK
99
spacing = im.get_spacing()
@@ -20,19 +20,19 @@
2020
print(arr)
2121

2222
# set attrs, style same as ITK;
23-
im = niirs.read_image(pth, dtype=np.float32)
23+
im = nii.read_image(pth, dtype=np.float32)
2424
im.set_origin([0.0, 1.0, 2.0])
2525
im.set_spacing([1.0, 2.0, 3.0])
2626
im.set_direction([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
2727
print(im)
2828

2929
# or copy information from another image
30-
im2 = niirs.read_image(pth)
30+
im2 = nii.read_image(pth)
3131
im.copy_infomation(im2)
3232

3333
# write image
3434
pth = rf"test_data\result.nii.gz"
35-
niirs.write_image(im, pth)
35+
nii.write_image(im, pth)
3636

3737
# get affine, if you are more familiar with affine matrix
3838
# nibabel style
@@ -41,15 +41,15 @@
4141

4242
# make new image, based on ndarray + affine
4343
# nibabel style
44-
new_affine = im.get_affine();
45-
new_arr = im.ndarray();
46-
new_im = niirs.new(new_arr, new_affine);
47-
print(new_im);
44+
new_affine = im.get_affine()
45+
new_arr = im.ndarray()
46+
new_im = nii.new(new_arr, new_affine)
47+
print(new_im)
4848

4949
# or simpleitk style
5050
new_arr = im.ndarray()
51-
new_im = niirs.get_image_from_array(new_arr);
52-
new_im.copy_infomation(im);
53-
print(new_im);
51+
new_im = nii.get_image_from_array(new_arr)
52+
new_im.copy_infomation(im)
53+
print(new_im)
5454

5555
# that's all

examples/tutorial.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use ndarray::{Array2, Array3};
12
use nii;
2-
use ndarray::{Array3, Array2};
33

4-
fn main () {
4+
fn main() {
55
let pth = r"test_data\test.nii.gz";
6-
6+
77
// Read Image, needs to specific type, eg: f32, u8, ...
88
let im = nii::read_image::<f32>(pth);
99

@@ -12,7 +12,10 @@ fn main () {
1212
let origin: [f32; 3] = im.get_origin();
1313
let direction: [[f32; 3]; 3] = im.get_direction();
1414
let size: [u16; 3] = im.get_size();
15-
println!("spacing: {:?}, origin: {:?}, direction: {:?}, size: {:?}", spacing, origin, direction, size);
15+
println!(
16+
"spacing: {:?}, origin: {:?}, direction: {:?}, size: {:?}",
17+
spacing, origin, direction, size
18+
);
1619

1720
// or print directly
1821
println!("{:?}", im);
@@ -25,7 +28,7 @@ fn main () {
2528
let arr: Array3<f32> = im.into_ndarray();
2629
println!("{:?}", arr);
2730

28-
// set attrs, style same as ITK;
31+
// set attrs, style same as ITK;
2932
// let im as **mut**
3033
let mut im = nii::read_image::<f32>(pth);
3134
im.set_origin([0.0, 1.0, 2.0]);
@@ -60,5 +63,4 @@ fn main () {
6063
println!("{:?}", new_im);
6164

6265
// That's all
63-
64-
}
66+
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ readme = "README.md"
1616
[tool.maturin]
1717
features = ["pyo3/extension-module"]
1818
python-source = "python"
19-
module-name = "niirs._niirs"
19+
module-name = "nii._nii"

0 commit comments

Comments
 (0)