一个用于Zeiss(CZI/ZISRAW)显微镜文件的Python模块和Python扩展。
项目描述
aicspylibczi
一个Python模块,用于公开libCZI功能,用于读取(部分)Zeiss CZI文件和元数据。我们目前仅支持64位架构,如果您急需32位支持,请提出问题或修改源代码,并为您的用例构建它。
用法
第一个示例展示了如何处理标准CZI文件(单个或多个场景)。第二个示例展示了如何处理马赛克CZI文件。
示例1:读取czi并选择图像的一部分进行显示
import numpy as np
from aicspylibczi import CziFile
from pathlib import Path
import matplotlib.pyplot as plt
pth = Path('20190610_S02-02.czi')
czi = CziFile(pth)
# Get the shape of the data, the coordinate pairs are (start index, size)
dimensions = czi.get_dims_shape() # [{'X': (0, 1900), 'Y': (0, 1300), 'Z': (0, 60), 'C': (0, 4), 'S': (0, 40), 'B': (0, 1)}]
czi.dims # BSCZYX
czi.size # (1, 40, 4, 60, 1300, 1900)
# Load the image slice I want from the file
img, shp = czi.read_image(S=13, Z=16)
# shp = [('B', 1), ('S', 1), ('C', 4), ('Z', 1), ('Y', 1300), ('X', 1900)] # List[(Dimension, size), ...]
# img.shape = (1, 1, 4, 1, 1300, 1900) # numpy.ndarray
# define helper functions
def norm_by(x, min_, max_):
norms = np.percentile(x, [min_, max_])
i2 = np.clip((x - norms[0]) / (norms[1] - norms[0]), 0, 1)
return i2
def recolor(im): # transform from rgb to cyan-magenta-yellow
im_shape = np.array(im.shape)
color_transform = np.array([[1, 1, 0], [0, 1, 1], [1, 0, 1]]).T
im_reshape = im.reshape([np.prod(im_shape[0:2]), im_shape[2]]).T
im_recolored = np.matmul(color_transform.T, im_reshape).T
im_shape[2] = 3
im = im_recolored.reshape(im_shape)
return im
# normalize, combine into RGB and transform to CMY
c1 = (norm_by(img[0, 0, 0, 0, 0:750, 250:1000], 50, 99.8) * 255).astype(np.uint8)
c2 = (norm_by(img[0, 0, 1, 0, 0:750, 250:1000], 50, 99.8) * 255).astype(np.uint8)
c3 = (norm_by(img[0, 0, 2, 0, 0:750, 250:1000], 0, 100) * 255).astype(np.uint8)
rgb = np.stack((c1, c2, c3), axis=2)
cmy = np.clip(recolor(rgb), 0, 255)
# plot using matplotlib¶
plt.figure(figsize=(10, 10))
plt.imshow(cmy)
plt.axis('off')
示例2:读取马赛克文件
import numpy as np
import aicspylibczi
import pathlib
from PIL import Image
mosaic_file = pathlib.Path('mosaic_test.czi')
czi = aicspylibczi.CziFile(mosaic_file)
# Get the shape of the data
dimensions = czi.dims # 'STCZMYX'
czi.size # (1, 1, 1, 1, 2, 624, 924)
czi.get_dims_shape() # [{'X': (0, 924), 'Y': (0, 624), 'Z': (0, 1), 'C': (0, 1), 'T': (0, 1), 'M': (0, 2), 'S': (0, 1)}]
czi.is_mosaic() # True
# Mosaic files ignore the S dimension and use an internal mIndex to reconstruct, the scale factor allows one to generate a manageable image
mosaic_data = czi.read_mosaic(C=0, scale_factor=1)
mosaic_data.shape # (1, 1, 624, 1756)
# the C channel has been specified S & M are used internally for position so this is (T, Z, Y, X)
normed_mosaic_data = norm_by(mosaic_data[0, 0, :, :], 5, 98) * 255
img = Image.fromarray(normed_mosaic_data.astype(np.uint8))
安装
首选的安装方法是使用pip install
。这将安装aicspylibczi Python模块和扩展二进制文件(托管在PyPI上)
pip安装aicspylibczi
如果不起作用:请调查以下内容(通常是Windows问题)
- 您的操作系统是64位 - 我们仅支持64位二进制文件
- 您的Python是64位应用程序(不是32位)
- 您的C++运行库是否最新? vc_redist.exe
如果您已尝试此方法但仍有困难,请与我们联系,我们将努力帮助您。
文档
文档可在github.io找到。
构建
使用以下步骤在本地构建和安装aicspylibczi
- 克隆包括子模块的存储库(
--recurse-submodules
)。 - 要求
- libCZI需要与c++11兼容的编译器。使用clang构建和测试。
- 开发需求包括为libCZI所需的内容:libpng,zlib
- 安装包
pip install . pip install -e .[dev] # for development (-e means editable so changes take effect when made) pip install .[all] # for everything including jupyter notebook to work with the Example_Usage above
- libCZI作为子模块自动构建,并静态链接到aicspylibczi中。
- 注意:如果在Windows上直接收到以下消息,您需要将PYTHONHOME设置为编译的python.exe所在的文件夹。
EXEC : Fatal Python error : initfsencoding: unable to load the file system codec ...
ModuleNotFoundError: No module named 'encodings'
已知问题
- 在使用read_mosaic时,如果scale_factor不是1.0,Zeiss的libCZI在某些文件中可能会无法渲染复合镶嵌图像中的某些子块。目前尚不清楚这是文件问题还是libCZI的问题。
历史
aicspylibczi最初是Paul Watkins开发的pylibczi的分支,专注于mSEM数据。在尝试将工作扩展到其他领域时,我们转向了pybind11,实现了C++和Python测试,通过github actions添加了持续集成,并添加了读取单个子块和子块堆栈作为numpy.ndarray的功能。还添加了元数据读取,包括特定子块元数据读取。
一旦我们将新的工作与原始工作集成,我们打算将这项工作合并回原始项目。
许可证和致谢
该项目是根据历史部分中所述的pylibczi的分支创建的,Paul Watkins也是我们的仓库开发者。Pylibczi来自欧洲高级研究与学习中心,核心依赖libCZI,受GPLv3许可证的保护。
GPLv3许可证是libCZI导致的,强制执行GPLv3。如果您希望在商业产品中使用libCZI或此衍生产品,您可能需要与蔡司和CAESAR联系。关于GPLv3的讨论。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
构建的发行版
aicspylibczi-3.2.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 435d1544421cacc05838aa31afaade85da0972bd3638bfe008fae6e023248ad0 |
|
MD5 | 1a3f91b33261a0338afd77c05b05805c |
|
BLAKE2b-256 | cc56e15504cbed8e984c90a7f89ff56b69d6aeb75d1afa139ac64de1569f8123 |
aicspylibczi-3.2.0-cp312-cp312-win_amd64.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 1af91377db16b394086b63b0ab1d334f7be283148153728ac81ccf4974d83743 |
|
MD5 | 3e64b4e8c3d086c0db0ad8d46b845013 |
|
BLAKE2b-256 | 88fd7e637b617a2ccaee3c317609f4964abf5ebd53a3c3ec246c138c091c22fa |
aicspylibczi-3.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 1790d44943459b2386b7274665524e8702dd2011f41dd85655fa89db0b9f8acf |
|
MD5 | b79ce5a82444befcd05c4a1a2486a6d0 |
|
BLAKE2b-256 | 910df7bc5ba9ae92a2b3274d91fd73c1aa882dd8635642caf9289fd5fc4d2bd0 |
aicspylibczi-3.2.0-cp312-cp312-macosx_11_0_arm64.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 507a0edd6b0fb16267bafc8c9863414801c456d62b59a0f5f587f502f66ee819 |
|
MD5 | 06838ec942bbe016d86c4526c33f9c33 |
|
BLAKE2b-256 | 7c1aee1bd310cc8648741ede485a521d382397b21856476369ea79bc8d170b16 |
aicspylibczi-3.2.0-cp312-cp312-macosx_10_9_x86_64.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 8d028a387e89a2e6a0c1df9dda7de23cc451e0ecbdf98b5ad42d85b5c7b45bc1 |
|
MD5 | 498b860fd8c20446a38566631cf89ed1 |
|
BLAKE2b-256 | df463cc39c68b223cdac773ddc7b67301e35a9e3d873fd7c9a2414085c3155c9 |
aicspylibczi-3.2.0-cp312-cp312-macosx_10_9_universal2.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e358f20c23ec9d4ffbd1390683136de9311ff262d150589303a6ceb249d8b3e2 |
|
MD5 | 36d6b6290144da113c12d0009365f4b0 |
|
BLAKE2b-256 | b27d76fe02513f8c963200a54a8a812aacef99be5407e650ab85a4d26640bd82 |
aicspylibczi-3.2.0-cp311-cp311-win_amd64.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b37a59c1b1916ecbc0a15e7d9d5ee94ff2a02cd24e451cfd387111eb1aec2d33 |
|
MD5 | a455acd62a4c63382631280e3ebbe87c |
|
BLAKE2b-256 | 4271ed35a375a75a8f87c59be7305a6537641961bad3c25737f74827883dcb5c |
aicspylibczi-3.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:f113123d72519960d9b3c3829c4bc3cbd23ce1d3398319fc85fbbda80cc837a0 |
|
MD5 | 哈希值:c60c23c335e5326a558ad65e93bd0653 |
|
BLAKE2b-256 | 哈希值:987af8cf7dfaea4334b8809e4a7d54e97dbdae5c7ab9cc92e0407c5ca2ab06fa |
哈希值:aicspylibczi-3.2.0-cp311-cp311-macosx_11_0_arm64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:fedb33b6ad81927e0507375447e468745cc54743f02ae35904eb6954cd3d5840 |
|
MD5 | 哈希值:e4369d3bd1c9a4afd93fb8e8af7fd40c |
|
BLAKE2b-256 | 哈希值:5743f5fb3c96fd770a98ccdbed625acd80788a9077f5c5d733bcf9069fb7ed23 |
哈希值:aicspylibczi-3.2.0-cp311-cp311-macosx_10_9_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:2f5f2107e2521e6de5a835ce2b8cd513f1ddd956fb34119f752b456104b7ef11 |
|
MD5 | 哈希值:8969de9b91148218713b9496417ba47c |
|
BLAKE2b-256 | 哈希值:a40cb78b1284b51166b44343272efc014590bdc9629cb5943082817eacac85f1 |
哈希值:aicspylibczi-3.2.0-cp311-cp311-macosx_10_9_universal2.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:0467e382e65c11c23f34e618f9b53ccf14ae334c4076b4dcc2cc5f5a20b3e36e |
|
MD5 | 哈希值:969eede036d6bd90822e4f5f99d3a59a |
|
BLAKE2b-256 | 哈希值:a19946729c2f23945f8af814f38c3032e711a24e49aa9ec023d65d74d6751cf1 |
哈希值:aicspylibczi-3.2.0-cp310-cp310-win_amd64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:7db1914ed9694ef36099f15170d6a0201f748d9a38fcada77b318ad23a75fbfc |
|
MD5 | 哈希值:d128f3eb484e7d38f14d99880dd558c8 |
|
BLAKE2b-256 | 哈希值:c77ca15dbbadc7c123b1c290fc3691940f5865495f2e879af6cef03a777e2ac5 |
哈希值:aicspylibczi-3.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:ec24e29b9f0a4cc71206df80333142e4f7f3f9d7263ec38b284a09a140dfe003 |
|
MD5 | 哈希值:9c110462b7e5207e2a6f37389077c8f0 |
|
BLAKE2b-256 | 哈希值:1b15154859632db1e65e9c5d5f07d6bd4109a71b7f479ee2c7ba7d20f664dd69 |
哈希值:aicspylibczi-3.2.0-cp310-cp310-macosx_11_0_arm64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:254ee717c4593601905b5c19504c8ba0f76779a30ca4e0d6a0a80fc6dc0e66d3 |
|
MD5 | 哈希值:c73ee160827884f68086f772146bb286 |
|
BLAKE2b-256 | 哈希值:2f8aa468e90c42480f0631fd597a140ee917ed0dcde24e2993c264162a7da0ea |
哈希值:aicspylibczi-3.2.0-cp310-cp310-macosx_10_9_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:66398f4a06a5db34b243954450fc78e19ebd28c555b40b9fff374e48d23a9203 |
|
MD5 | 哈希值:41ba9078ba4ceeaa4aae80f3ec7b1667 |
|
BLAKE2b-256 | 哈希值:73dcbd1da55ce759ba76968ebec04c7b73a0b4caa03d46b1508cac6bdb7cf7e9 |
哈希值:aicspylibczi-3.2.0-cp310-cp310-macosx_10_9_universal2.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:91dca2ae9fd4d0c65475db975d2f9b5de8836db8fa19fca97327df438b05be48 |
|
MD5 | 哈希值:11f41ec508f0d89f8b29a4a0ddb5aefa |
|
BLAKE2b-256 | 哈希值:da95dbf260a7a0046178f7ac95fef632cfcbd6390cbe83194e9959caa9c658fb |
哈希值:aicspylibczi-3.2.0-cp39-cp39-win_amd64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:2532719560a0e031747dd9e3991ba9e134169ec8df7b91fc354773f150295494 |
|
MD5 | 哈希值:51310d1cc5b1e0694930d1fd728ea20b |
|
BLAKE2b-256 | 哈希值:ce1fcb6303f73abebcdfbf3b2a30ea83779e397f3b8db8d0e0d0a27137bb4c24 |
哈希值:aicspylibczi-3.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:4ba081e470003ea613d592db06063f849665de5d24e4bf3c42b310d74ee2bdf6 |
|
MD5 | 哈希值:5739b8e8c2635605f12485f4ea11f857 |
|
BLAKE2b-256 | 哈希值:ea5dad48d60e15acc43bd73dc774bd4944f5df85866220de0ef4ac8258fc13c5 |
哈希值:aicspylibczi-3.2.0-cp39-cp39-macosx_11_0_arm64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:514b5094354cd2bb6257d2794eee5256ae73dcb7e08cab277be6fabdd1e5663f |
|
MD5 | 哈希值:946302e5229b26b20a6e0e81a346acca |
|
BLAKE2b-256 | 哈希值:1b019735fa4ac06a7494a5914bbb1ef55ab95623e0f88411dc711119727b573a |
哈希值:aicspylibczi-3.2.0-cp39-cp39-macosx_10_9_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 哈希值:a60e4413d27904eb9717024e5ba20a6e4aee2fa603e6d26530ded5fec11e77ab |
|
MD5 | 哈希值:9f5f9b9674496b0707b6e0670db56fe2 |
|
BLAKE2b-256 | fd412ef7dfbcc2abe6e69c2523cd08c371bbf6fbe0ad7a554abae0ec87d8c978 |
哈希值 用于 aicspylibczi-3.2.0-cp39-cp39-macosx_10_9_universal2.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ceff17903820ba4bf5c212de526813e6c6c5fa24054f2f8ef3cc5807619c79e5 |
|
MD5 | c7d14926d9b3e4a02b4c1bfcc18c93bb |
|
BLAKE2b-256 | 5d5d8046d09ec7cb2a01847187e50200ac3f5976ff934bdd2c5be2f02e26e61b |
哈希值 用于 aicspylibczi-3.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 045828c5c1d3b78d6a7e6115f9d500f2ea1b2661687ed28b97e9f58a3d5e8c71 |
|
MD5 | 7d76b4385bb2493973382e4005b09d4f |
|
BLAKE2b-256 | 9e4851386fca3933d2a244c705b64c7daaf250794795f62364116dd405c52d39 |
哈希值 用于 aicspylibczi-3.2.0-cp38-cp38-macosx_11_0_arm64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 570a76050443ecc36fc2fcca8ad16ca509daec2e9e2983aeb702a794c8710602 |
|
MD5 | db0c8248620fab391404896b704af4de |
|
BLAKE2b-256 | 96cc46f9b71c306db221b7d188a4396347a3b817d993e8bfb690c02bc9ed0573 |
哈希值 用于 aicspylibczi-3.2.0-cp38-cp38-macosx_10_9_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | cee1c4b89b7c9644c5db8f08929659e07bf1b53129a9a3928e4ec72c858da4e8 |
|
MD5 | 405254e161d7af619c885f64d39288e3 |
|
BLAKE2b-256 | 9ddc6b2a829fc9f7b352bea4c7bb978fa34b4ea0c1e1f88e117f1b92f1904a1a |
哈希值 用于 aicspylibczi-3.2.0-cp38-cp38-macosx_10_9_universal2.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 40de9b350bd85b665a01dea606fc72202db877c259ea419ed10c3f1e0700e90e |
|
MD5 | 7244281a88dc4b77459ad06e465ad9b9 |
|
BLAKE2b-256 | aebccebf980334e24189e91d36d90500569d2617d6da6f1d551f2eece8475580 |