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
Batch extraction of parameters from .czi metadata?
-
- Posts: 1
- Joined: Wed Jul 07, 2021 6:32 pm
-
- Posts: 180
- Joined: Wed May 20, 2020 10:10 am
Re: Batch extraction of parameters from .czi metadata?
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
Second: Reading data from the xml file
Third: Saving the xml-metadata from all files of a directory
I hope this is a good start for you.
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)
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)
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()