Reading files with AICSImageIO#

The AICSImageIO library aims streamlining reading microscopy image data.

To install the library, you need to call the following command. Make sure your conda environment is activated.

mamba install aicsimageio

In case specific proprietary file formats should be read, additional software must be installed. Check the documentation for details.

from aicsimageio import AICSImage
import stackview

First, we create an AICSImage object to see if it understands our file format. In the following example, we read an OME Tif file that was saved with ImageJ before.

As example we are using here an image shared by Célia Baroux et al(University of Zurich) that was resaved for demonstration purposes.

aics_image = AICSImage("data/EM_C_6_c0.ome.tif")
aics_image
<AICSImage [Reader: OmeTiffReader, Image-is-in-Memory: False]>

This object can already give us basic information such as image size/shape, dimensions and dimension names and order.

aics_image.shape
(1, 1, 256, 256, 256)
aics_image.dims
<Dimensions [T: 1, C: 1, Z: 256, Y: 256, X: 256]>
aics_image.dims.order
'TCZYX'

From this object, we can also retrieve pixels as numpy arrays.

np_image = aics_image.get_image_data("ZYX", T=0)
np_image.shape
(256, 256, 256)
stackview.insight(np_image[128])
shape(256, 256)
dtypeuint8
size64.0 kB
min4
max155

Reading meta data#

When working with microscopy image data, it is important to be aware of meta data, for example the voxel size. In order to do volume measurements in proper physical units, we need to know how large a voxel is in X, Y and Z.

aics_image.physical_pixel_sizes
PhysicalPixelSizes(Z=0.16784672897196262, Y=0.16776018346253663, X=0.16776018346253663)

And one can define a helper function for reading the voxel size in Z/Y/X format.

def get_voxel_size_from_aics_image(aics_image):
    return (aics_image.physical_pixel_sizes.Z,
            aics_image.physical_pixel_sizes.Y,
            aics_image.physical_pixel_sizes.X)
get_voxel_size_from_aics_image(aics_image)
(0.16784672897196262, 0.16776018346253663, 0.16776018346253663)

Reading CZI files#

In case additionally the aicspylibczi library is installed one can also open CZI files using AICSImageIO (example dataset kindly provided by kindly provided by Romina Piscitello-Gómez, MPI CBG).

czi_image = AICSImage("data/PupalWing.czi")
czi_image.shape
(1, 1, 80, 520, 692)
np_czi_image = czi_image.get_image_data("ZYX", T=0)
np_czi_image.shape
(80, 520, 692)
get_voxel_size_from_aics_image(czi_image)
(1.0, 0.20476190476190476, 0.20476190476190476)

Exercise#

Open a file from a recent project. Try out CZI, LIF, ND2 and others. Check the aicsimageio documentation for additional installation instructions.