生成一个可以序列化为OME-NGFF的多尺度、分块、多维空间图像数据结构。
项目描述
multiscale-spatial-image
生成一个可以序列化为OME-NGFF的多尺度、分块、多维空间图像数据结构。
每个尺度都是一个科学Python Xarray 空间图像 数据集,组织成一个Xarray 数据树的节点。
安装
pip install multiscale_spatial_image
用法
import numpy as np
from spatial_image import to_spatial_image
from multiscale_spatial_image import to_multiscale
import zarr
# Image pixels
array = np.random.randint(0, 256, size=(128,128), dtype=np.uint8)
image = to_spatial_image(array)
print(image)
一个Xarray 空间图像 数据数组。在构建过程中也可以传递空间元数据。
<xarray.SpatialImage 'image' (y: 128, x: 128)>
array([[114, 47, 215, ..., 245, 14, 175],
[ 94, 186, 112, ..., 42, 96, 30],
[133, 170, 193, ..., 176, 47, 8],
...,
[202, 218, 237, ..., 19, 108, 135],
[ 99, 94, 207, ..., 233, 83, 112],
[157, 110, 186, ..., 142, 153, 42]], dtype=uint8)
Coordinates:
* y (y) float64 0.0 1.0 2.0 3.0 4.0 ... 123.0 124.0 125.0 126.0 127.0
* x (x) float64 0.0 1.0 2.0 3.0 4.0 ... 123.0 124.0 125.0 126.0 127.0
# Create multiscale pyramid, downscaling by a factor of 2, then 4
multiscale = to_multiscale(image, [2, 4])
print(multiscale)
一个分块的多尺度空间图像Dask Array Xarray Datatree。
DataTree('multiscales', parent=None)
├── DataTree('scale0')
│ Dimensions: (y: 128, x: 128)
│ Coordinates:
│ * y (y) float64 0.0 1.0 2.0 3.0 4.0 ... 123.0 124.0 125.0 126.0 127.0
│ * x (x) float64 0.0 1.0 2.0 3.0 4.0 ... 123.0 124.0 125.0 126.0 127.0
│ Data variables:
│ image (y, x) uint8 dask.array<chunksize=(128, 128), meta=np.ndarray>
├── DataTree('scale1')
│ Dimensions: (y: 64, x: 64)
│ Coordinates:
│ * y (y) float64 0.5 2.5 4.5 6.5 8.5 ... 118.5 120.5 122.5 124.5 126.5
│ * x (x) float64 0.5 2.5 4.5 6.5 8.5 ... 118.5 120.5 122.5 124.5 126.5
│ Data variables:
│ image (y, x) uint8 dask.array<chunksize=(64, 64), meta=np.ndarray>
└── DataTree('scale2')
Dimensions: (y: 16, x: 16)
Coordinates:
* y (y) float64 3.5 11.5 19.5 27.5 35.5 ... 91.5 99.5 107.5 115.5 123.5
* x (x) float64 3.5 11.5 19.5 27.5 35.5 ... 91.5 99.5 107.5 115.5 123.5
Data variables:
image (y, x) uint8 dask.array<chunksize=(16, 16), meta=np.ndarray>
以 Open Microscopy Environment-Next Generation File Format (OME-NGFF) / netCDF / Zarr 存储格式存储。
强烈建议在构建 Zarr 存储时使用 dimension_separator='/'
。
store = zarr.storage.DirectoryStore('multiscale.zarr', dimension_separator='/')
multiscale.to_zarr(store)
注意:API 正在开发中,直到 1.0.0 版本发布,可能会有所变化。我们认真对待这个承诺 :-)。
示例
Hello MultiscaleSpatialImage World!
Convert itk.Image
Convert imageio ImageResource
Convert pyimagej Dataset
开发
欢迎并感谢贡献。
获取源代码
git clone https://github.com/spatial-image/multiscale-spatial-image
cd multiscale-spatial-image
安装依赖项
首先安装 pixi。然后,安装项目依赖项
pixi install -a
pixi run pre-commit-install
运行测试套件
单元测试
pixi run -e test test
笔记本测试
pixi run test-notebooks
更新测试数据
要添加新数据或更新测试数据,例如此块的基线
dataset_name = "cthead1"
image = input_images[dataset_name]
baseline_name = "2_4/XARRAY_COARSEN"
multiscale = to_multiscale(image, [2, 4], method=Methods.XARRAY_COARSEN)
verify_against_baseline(test_data_dir, dataset_name, baseline_name, multiscale)
在您的测试块中添加一个 store_new_image
调用
dataset_name = "cthead1"
image = input_images[dataset_name]
baseline_name = "2_4/XARRAY_COARSEN"
multiscale = to_multiscale(image, [2, 4], method=Methods.XARRAY_COARSEN)
store_new_image(dataset_name, baseline_name, multiscale)
verify_against_baseline(dataset_name, baseline_name, multiscale)
运行测试以生成输出。删除 store_new_image
调用。
然后,创建当前测试数据的 tar 包
cd test/data
tar cvf ../data.tar *
gzip -9 ../data.tar
python3 -c 'import pooch; print(pooch.file_hash("../data.tar.gz"))'
在 test/_data.py 文件中更新 test_data_sha256
变量。将数据上传到 web3.storage。并更新 test_data_ipfs_cid
内容标识符 (CID) 变量,该变量可在 web3.storage 网页界面中找到。
提交补丁
我们使用标准的 GitHub flow。
项目详情
关闭
multiscale_spatial_image-1.0.1.tar.gz 的散列
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 7d8ef88d1892efa8c69878695cead310a2d5c10c64baad4e4fc9e381ac42ed36 |
|
MD5 | 2d8f46154c352046fdb93a81b76e3dce |
|
BLAKE2b-256 | b480e2eb1b4f892bfb73cd3b9ef54ce1122a3c2d15d24a797831d9ecb7621ace |
关闭
multiscale_spatial_image-1.0.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e927ed619d23e6b61777ca05a7c50f29db86dcfc2857f512bec6be8bcb351fcf |
|
MD5 | 1a0ad494d682e6aef5d36deee310988c |
|
BLAKE2b-256 | f59823d67fb3e1cb801122bbf3ced565e796d471a09b610cd9c5697528e83494 |