Batch extraction of parameters from .czi metadata?

Discuss questions and projects related to processing of imaging data here
Post Reply
Emily Breeze
Posts: 1
Joined: Wed Jul 07, 2021 6:32 pm

Batch extraction of parameters from .czi metadata?

Post by Emily Breeze »

Hello. I need to analyse several .czi files in which I first need to know the pixel resolution and frame rate. Is there a quicker way of doing this than opening each file individually in Fiji, viewing the metadata and manually finding the values I need? I often have over 50 files per dataset so it is very tedious!!!!

thanks all :)
CarlZeissMicroscopy3
Posts: 180
Joined: Wed May 20, 2020 10:10 am

Re: Batch extraction of parameters from .czi metadata?

Post by CarlZeissMicroscopy3 »

Hello Emily Breeze,

this is a collection of code snippets that show the main steps:

First: Saving the xml-metadata from an 'active image' in Zen

Code: Select all

xmlFile = r'C:\Temp\ActiveDocument.xml'

image = Zen.Application.Documents.ActiveDocument
image.Metadata.SaveAsXml(xmlFile)
Second: Reading data from the xml file

Code: Select all

import clr
clr.AddReference('System.Xml')
import System.Xml

xmlFile = r'C:\Temp\ActiveDocument.xml'

xmlDocument = System.Xml.XmlDocument()
xmlDocument.Load(xmlFile);

node = xmlDocument.SelectNodes('ImageMetadata/Information/Image/SizeX')[0]
value = node.InnerText
Zen.Application.Pause(value)
Third: Saving the xml-metadata from all files of a directory

Code: Select all

from System.IO import File, Directory

path = r'C:\Temp'
imageType = '*.CZI'
files = Directory.GetFiles(path,imageType) 

for file in files:
    xmlFile=file.Replace('.czi','.xml')
    image = ZenImage()
    image.Load(imageFile);
    image.Metadata.SaveAsXml(xmlFile)
    image.Close()
I hope this is a good start for you.
Post Reply