Metadata-Version: 2.4
Name: ndbioimage
Version: 2027.0.8
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Dist: numpy>=1.16.0
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: tiffwrite ; extra == 'test'
Provides-Extra: test
Summary: Read bio image formats using the bio-formats java package.
Keywords: bioformats,imread,ndarray,metadata
Author: Wim Pomp <w.pomp@nki.nl>
Author-email: Wim Pomp <w.pomp@nki.nl>
License: MIT OR Apache-2.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://docs.rs/ndbioimage
Project-URL: Source Code, https://git.pomppervova.nl/wim/ndbioimage

[![pytest](https://git.pomppervova.nl/wim/ndbioimage/actions/workflows/pytest.yml/badge.svg)](https://git.pomppervova.nl/wim/ndbioimage/actions?workflow=pytest.yml)

# NDBioImage
## Work in progress

Rust rewrite of python version. Read bio image formats using some Rust code, the libczi api, and if needed the
bio-formats java package.

Exposes (bio) images as a numpy ndarray-like object (Python) or a struct that can be sliced like an ndarray Array
(Rust), but without loading the whole image into memory, reading from the file only when needed. Some metadata is read
and stored in an [ome](https://genomebiology.biomedcentral.com/articles/10.1186/gb-2005-6-5-r47) structure.
Additionally, it can automatically calculate an affine transform that corrects for chromatic aberrations etc. and apply
it on the fly to the image.

Currently, it supports imagej tif files, czi files, micromanager tif sequences and anything
[bioformats](https://www.openmicroscopy.org/bio-formats/) can handle.

To transition to semver, versions before 0.1.0 were yanked from crates.io.

## Usage

### Python

- Reading an image file and plotting the frame at channel=2, time=1

```python
import matplotlib.pyplot as plt
from ndbioimage import Imread
with Imread('image_file.tif', axes='ctyx', dtype=int) as im:
    plt.imshow(im[2, 1])
```        

- Showing some image metadata

```python
from ndbioimage import Imread
from pprint import pprint
with Imread('image_file.tif') as im:
    pprint(im)
```

- Slicing the image without loading the image into memory

```python
from ndbioimage import Imread
with Imread('image_file.tif', axes='cztyx') as im:
    sliced_im = im[1, :, :, 100:200, 100:200]
```

sliced_im is an instance of Imread which will load any image data from file only when needed

- Converting (part) of the image to a numpy ndarray

```python
from ndbioimage import Imread
import numpy as np
with Imread('image_file.tif', axes='cztyx') as im:
    array = np.asarray(im[0, 0])
```

### Rust

```rust
use ndarray::Array2;
use ndbioimage::{DynReader, Frame, Reader};

fn main() -> Result<(), ndbioimage::error::Error> {
    let path = "/path/to/file";
    let reader = DynReader::new(&path, 0, 0)?;
    println!("shape: {}", reader.shape());
    let frame = reader.get_frame(0, 0, 0)?;
    if let Ok(arr) = <Frame as TryInto<Array2<i8>>>::try_into(frame) {
        println!("{:?}", arr);
    } else {
        println!("could not convert Frame to Array<i8>");
    }
    let xml = reader.metadata()?.to_xml()?;
    println!("{}", xml);
    Ok(())
}
```

```rust
use ndbioimage::{DynReader, Reader};

fn main() -> Result<(), ndbioimage::error::Error> {
    let path = "/path/to/file";
    let reader = DynReader::new(&path, 0, 0)?;
    let view = reader.view();
    let view = view.max_proj(3)?;
    let array = view.as_array::<u16>()?;
    println!("{:?}", array.shape());
    Ok(())
}
```

### Command line

```ndbioimage --help```: show help  
```ndbioimage info image```: show metadata about image  
```ndbioimage tiff image image.tif -r```: copy image into image.tif, while registering channels  
```ndbioimage movie image image.mp4 -C cyan lime red``` copy image into image.mp4 (z will be max projected), make channel
colors cyan lime and red

