Problem related to .czi image, I am having trouble while reading .czi file with bio-formats?

Hello there,
I have a .czi image of 4 channel and 120 stacked image on each channel.
I want to select and save each stack of each channel image using python-bioformats.
I was able to load the image and as well as visualize the sizeC, SizeZ but i was not able to read that z images 120 times for each channel.


# when i try read function. it only run for 4 times but i think it should run for 120 times., isn't it?
reader = bioformats.ImageReader(input_any1)
metadata = javabridge.jdictionary_to_string_dictionary(reader.rdr.getMetadata())

print("Series Count", reader.rdr.getSeriesCount())
print("Image Count", reader.rdr.getImageCount())
print("X-dim", reader.rdr.getSizeX())
print("Y-dim", reader.rdr.getSizeY())
print("Image-TIME", reader.rdr.getSizeT())
print("Image-Channel", reader.rdr.getSizeC())
print("Image-Zstack", reader.rdr.getSizeZ())

for channel in range(reader.rdr.getSizeC()):
    for zstack in range(reader.rdr.getSizeZ()):
        img1 =
        img_tiles_org = Image.fromarray(img1)
        np_frame = np.array(img_tiles_org, dtype=np.uint16)
        width, height = img_tiles_org.size


Series Count 1
Image Count 480
X-dim 1316
Y-dim 1316
Image-TIME 1
Image-Channel 4
Image-Zstack 120

Exception in thread "Thread-0" java.lang.IllegalArgumentException: Invalid C index: 4/4
	at loci.formats.FormatTools.getIndex(
	at loci.formats.FormatTools.getIndex(
	at loci.formats.FormatReader.getIndex(
Traceback (most recent call last):
  File "/snap/pycharm-community/224/plugins/python-ce/helpers/pydev/", line 1477, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/snap/pycharm-community/224/plugins/python-ce/helpers/pydev/_pydev_imps/", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/yuvi/PycharmProjects/task-1/temp/", line 42, in <module>
    img1 =
  File "/home/yuvi/anaconda3/envs/task-1/lib/python3.7/site-packages/bioformats/", line 841, in read
    index = self.rdr.getIndex(z,c,t)
  File "/home/yuvi/anaconda3/envs/task-1/lib/python3.7/site-packages/javabridge/", line 961, in method
    result = call(self.o, name, sig, *args)
  File "/home/yuvi/anaconda3/envs/task-1/lib/python3.7/site-packages/javabridge/", line 892, in call
    result = fn(*nice_args)
  File "/home/yuvi/anaconda3/envs/task-1/lib/python3.7/site-packages/javabridge/", line 859, in fn
    raise JavaException(x)
javabridge.jutil.JavaException: Invalid C index: 4/4

As the error says, it has just 4 index to load, but why it’s loading for 4 tiles instead of 120 times.
Does anybody help me to read this image one by one for 120 times for each channel?
Please :slightly_smiling_face:

It was my silly mistake. It has been solved.

1 Like