Bio image reading, metadata and some affine registration.
Project description
ndbioimage
Exposes (bio) images as a numpy ndarray-like object, but without loading the whole image into memory, reading from the file only when needed. Some metadata is read and stored in an ome 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 can handle.
Installation
pip install ndbioimage
Installation with option to write mp4 or mkv:
Work in progress! Make sure ffmpeg is installed.
pip install ndbioimage[write]
Usage
Python
- Reading an image file and plotting the frame at channel=2, time=1
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
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
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
from ndbioimage import Imread
import numpy as np
with Imread('image_file.tif', axes='cztyx') as im:
array = np.asarray(im[0, 0])
Command line
ndbioimage --help
: show help
ndbioimage image
: show metadata about image
ndbioimage image {name}.tif -r
: copy image into image.tif (replacing {name} with image), while registering channels
ndbioimage image image.mp4 -C cyan lime red
copy image into image.mp4 (z will be max projected), make channel colors cyan lime and red
Adding more formats
Readers for image formats subclass AbstractReader. When an image reader is imported, Imread will automatically recognize it and use it to open the appropriate file format. Image readers are required to implement the following methods:
- staticmethod _can_open(path): return True if path can be opened by this reader
- __frame__(self, c, z, t): return the frame at channel=c, z-slice=z, time=t from the file
Optional methods:
- get_ome: reads metadata from file and adds them to an OME object imported from the ome-types library
- open(self): maybe open some file handle
- close(self): close any file handles
Optional fields:
- priority (int): Imread will try readers with a lower number first, default: 99
- do_not_pickle (strings): any attributes that should not be included when the object is pickled, for example: any file handles
TODO
- more image formats
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ndbioimage-2024.10.0.tar.gz
.
File metadata
- Download URL: ndbioimage-2024.10.0.tar.gz
- Upload date:
- Size: 47.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3551c9bfdd6316e3b11876ce205604bf5d6d52ad6ec3af6d7ea1d9755bf1359 |
|
MD5 | 00600ab9d61d933b12aa4dad3e9eda73 |
|
BLAKE2b-256 | fd80de26b14568453a0a5f4c07b4dd8cee49c6cacc4d3526c8751722c733474f |
File details
Details for the file ndbioimage-2024.10.0-py3-none-any.whl
.
File metadata
- Download URL: ndbioimage-2024.10.0-py3-none-any.whl
- Upload date:
- Size: 52.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 187ab5bdde60c8958f02678682e5424db9a2a6e1b8785c498f6674888fb55430 |
|
MD5 | d7bd77d66ae5d0724c0194904c66f508 |
|
BLAKE2b-256 | ab74d92909240ee6fae997331a4567722476d9d2760a77f1f472bff293de69c9 |