Giter Site home page Giter Site logo

czifile's Introduction

Read image and metadata from Carl Zeiss(r) ZISRAW (CZI) files.

CZI is the native image file format of the ZEN(r) software by Carl Zeiss Microscopy GmbH. It stores multidimensional images and metadata from microscopy experiments.

This repository is a mirror of the original release of the code, intended to make pip installation possible.

Author:Christoph Gohlke
Organization:Laboratory for Fluorescence Dynamics, University of California, Irvine
Version:2017.09.12

Requirements

Revisions

2017.09.12
Require tifffile.py 2017.09.12
2017.07.21
Use multi-threading in CziFile.asarray to decode and copy segment data. Always convert BGR to RGB. Remove bgr2rgb options. Decode JpegXR directly from byte arrays.
2017.07.13
Add function to convert CZI file to memory-mappable TIFF file.
2017.07.11
Add 'out' parameter to CziFile.asarray. Remove memmap option from CziFile.asarray (backwards incompatible). Change spline interpolation order to 0 (backwards incompatible). Make axes return a string. Require tifffile 2017.07.11.
2015.08.17
Require tifffile 2015.08.17.
2014.10.10
Read data into a memory mapped array (optional).
2013.12.04
Decode JpegXrFile and JpgFile via _czifle extension module. Attempt to reconstruct tiled mosaic images.
2013.11.20
Initial release.

Notes

The API is not stable yet and might change between revisions.

The file format design specification [1] is confidential and the licence agreement does not permit to write data into CZI files.

Only a subset of the 2012 specification is implemented in the initial release. Specifically, multifile images are not yet supported.

Tested on Windows with a few example files only.

References

  1. ZISRAW (CZI) File Format Design specification Release Version 1.2.2. CZI 07-2016/CZI-DOC ZEN 2.3/DS_ZISRAW-FileFormat.pdf (confidential). Documentation can be requested at <http://microscopy.zeiss.com/microscopy/en_us/downloads/zen.html>
  2. CZI The File Format for the Microscope | ZEISS International <http://microscopy.zeiss.com/microscopy/en_us/products/microscope-software/ zen-2012/czi.html>

Examples

>>> with CziFile('test.czi') as czi:
...     image = czi.asarray()
>>> image.shape
(3, 3, 3, 250, 200, 3)
>>> image[0, 0, 0, 0, 0]
array([10, 10, 10], dtype=uint8)

czifile's People

Contributors

cdw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

czifile's Issues

Asarray function return all zero ndarray

I want to use this library to analyze some czi files which are around 1GB each, I want to get ndarray of the image so that I could split it into small batches of the data and feed into neural network to do a classification problem. I stuck at the first step, I want to read the information from the czi file but it return me all zero.
The following is my code

import czifile
from czifile import CziFile
image_arrays.shape
with CziFile('/Users/ziqisu/Documents/138-DCCD-1-CYS-sample.czi') as czi:
    image_arrays = czi.asarray

image_arrays.shape
the return value is (1, 1, 1, 1, 3, 38880, 38880, 1)

image_arrays.strides

return value is (9069926400, 9069926400, 9069926400, 9069926400, 3023308800, 77760, 2, 2)

If I just want to see what is image_arrays
Image_arrays[0, 0, 0, 0]

It will give me ndarray of all zero just like:
`array([[[[0],
[0],
[0],
...,
[0],
[0],
[0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    ...,

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]]],


   [[[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    ...,

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]]],


   [[[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    ...,

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]],

    [[0],
     [0],
     [0],
     ...,
     [0],
     [0],
     [0]]]], dtype=uint16)`

I already write down a function to check whether or not it is all zero in the array, it turns out it is all zero.
Is there anyone that could help me figure out what actually happened here? Thank you!

Numpy FutureWarning (py36, v0.1.5)

Attempting to use czifile within a Jupyter notebook installed via Anaconda and am seeing FutureWarning as so:

/anaconda3/lib/python3.6/site-packages/czifile/czifile.py:400: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  out[index] = tile

Some quick searching seems to be a numpy warning regarding future deprecation.

numpy/numpy#11411

Doesn't seem to be causing issues yet, but thought I would mention it.

cannot call decode_jxr function

Hi Allen,
I ran czifile using pip and tried fetching decode_jxr function but it is throwing error.
Could you please help me in using decode_jxr ()? Your help is much appreciated

Compression 4 is not supported

(I am new to this data format, so blindly trying to iterate over continuous chunks of data). Using latest czifile:

import czifile
f = czifile.CziFile('/Users/axelr/Downloads/Brightfield+RAC/2019_02_19__11_16__SL000768.czi')
for block in f.subblocks():
    print(block.shape)
    print(block.compression)
    print(block.data())
    break

Result:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-6-a57de3b0f14e> in <module>
      6     print(block.shape)
      7     print(block.compression)
----> 8     print(block.data())
      9     break

~/system1/envs/pipeline/lib/python3.7/site-packages/czifile/czifile.py in data(self, raw, resize, order)
    615                 fh.seek(self.data_offset)
    616                 data = fh.read(self.data_size)
--> 617             data = DECOMPRESS[de.compression](data)
    618             if de.compression == 2:
    619                 # LZW

KeyError: 4

Windows (virtual machine) and max_workers

I've been experimenting with the library on macos, linux, and windows (which generally work great, thank you!) and I encountered a small problem on Windows (10) running in a VM (VMWare) on my mac. The call:

img = czi.asarray()

with no arguments, raises the following error:

C:\Users\sheinb\Anaconda3\lib\site-packages\czifile\czifile.py in func(directory_entry, resize, order, start, out)
    393                  start=self.start, out=out):
    394             """Read, decode, and copy subblock data."""
--> 395             subblock = directory_entry.data_segment()
    396             tile = subblock.data(resize=resize, order=order)
    397             index = [slice(i-j, i-j+k) for i, j, k in
AttributeError: 'list' object has no attribute 'data_segment'

This virtual machine has 2 CPUs assigned, and multiprocessor.cpu_count seems to report this correctly. I found, though, if I explicitly pass max_workers as 2, then the call works but if I pass max_workers as 1, it does not. Probably a rare issue (since everyone presumably has >1 CPU) but maybe there's a small issue is this part of the code? My knowledge of executor maps is limited...

       if max_workers > 1:
            self._fh.lock = True
            with ThreadPoolExecutor(max_workers) as executor:
                executor.map(func, self.filtered_subblock_directory)
            self._fh.lock = None
        else:
            func(self.filtered_subblock_directory)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.