# Importing images in czi file extension

**URL:** <https://discourse.slicer.org/t/importing-images-in-czi-file-extension/12291>\
**Category:** Support\
**Created:** [June 30, 2020, 10:33am UTC](https://discourse.slicer.org/t/importing-images-in-czi-file-extension/12291 "2020-06-30T10:33:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)\
**Post date:** [June 30, 2020, 10:33am UTC](https://discourse.slicer.org/t/importing-images-in-czi-file-extension/12291/1 "2020-06-30T10:33:53Z")

</div>

Hi All,  
May I know how to import image files in czi file format generated from Zeiss microscope into Slicer,  
for performing segmentation?

Thanks,  
Deepa

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 30, 2020, 9:25pm UTC](https://discourse.slicer.org/t/importing-images-in-czi-file-extension/12291/2 "2020-06-30T21:25:15Z")

</div>

Probably the easiest is to load it using a Python package (e.g., [czifile](https://pypi.org/project/czifile/)) then set the Python array into a volume node.

If you need to load this kind of images often, then you can write a short Python scripted module that makes loading available in “Add data” dialog the same way as for other formats.

---

<div class="post-metadata">

**Author:** ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)\
**Post date:** [July 1, 2020, 4:52pm UTC](https://discourse.slicer.org/t/importing-images-in-czi-file-extension/12291/3 "2020-07-01T16:52:58Z")

</div>

@lassoan

Thank you.  
I tried the following in python

```auto
import czifile
from skimage import io

img = czifile.imread('file.czi')
print(img.shape)

```

The output is  
(1, 1, 3, 1, 48, 1024, 1024, 1)  
I couldn’t completely understand what each value in the output refers to

Does 3 denote the number of channels?

From what I understand 48 refers to the number of slices in the z-stack. I would like to save the z-stack corresponding to channel 1 in tiff format and load this in Slicer. Could you please offer some advice on how this can be done?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 1, 2020, 5:17pm UTC](https://discourse.slicer.org/t/importing-images-in-czi-file-extension/12291/4 "2020-07-01T17:17:38Z")

</div>

You can use `numpy.squeeze()` to remove singular dimensions of an array. Probably there is a reason for czifile to return these many extra dimensions, so I would recommend to read its documentation.

---

<div class="post-metadata">

**Author:** ![Deepa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deepa/32/5634_2.png) [@Deepa](https://discourse.slicer.org/u/Deepa)\
**Post date:** [July 2, 2020, 5:08pm UTC](https://discourse.slicer.org/t/importing-images-in-czi-file-extension/12291/5 "2020-07-02T17:08:35Z")

</div>

Hi @lassoan  
I could do the following

[input](https://drive.google.com/file/d/1SzbIIrW9jeCSf5bYMZ1BN2GSzANrNTA9/view?usp=sharing)

```
from aicsimageio import AICSImage
from aicsimageio.writers import OmeTiffWriter

img = AICSImage('input.czi')
img.data # returns 6D STCZYX numpy array
print(img.dims) # returns string "STCZYX"
print(img.shape) # returns tuple of dimension sizes in STCZYX order

first_channel_data = img.get_image_data("ZYX", C=1, S=0, T=0)

 with OmeTiffWriter("file.ome.tiff") as writer:
     writer.save(
         first_channel_data,
         pixels_physical_size=img.get_physical_pixel_size(),
         dimension_order="ZYX",
     )

```

The output tiff file has 3 channels. One of the channels has stained cells. But from the other two channels, I am not sure how to find out which channel can be used for 3D reconstruction of vessels  
in Slicer.

Could you please offer some advice?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 2, 2020, 7:58pm UTC](https://discourse.slicer.org/t/importing-images-in-czi-file-extension/12291/6 "2020-07-02T19:58:10Z")

</div>

Why don’t you simple use `squeeze` as I suggested above to remove the singular dimensions set the array in a volume node by calling [slicer.util.updateVolumeFromArray](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.updateVolumeFromArray)?

> [@Deepa](#):
>
> The output tiff file has 3 channels. One of the channels has stained cells. But from the other two channels, I am not sure how to find out which channel can be used for 3D reconstruction of vessels  
> in Slicer.

It depends on the color of the feature that you want to extract and color of background noise that you want to suppress. Try all combinations in “Vector To Scalar Volume” module (Luminance, Average, and each single component) and use whichever works the best.
