Re: converting XML file to ImageJ format


I was wondering if anyone could help me with converting a XML metadata file to a format that ImageJ will accept?


1 Like

Can you please post a link to the specific xml that you posted on gitter?

From gitter
Hello! I have a fluorescent set of images taken at x20 over 3 channels accounting for 600 odd images - I wonder if anyone knew of a way to stitch them using image j ?
I’ve got the metadata file for it too -unfortunately - when i run it on the grid/collection plug in it reads unknown format exception/ unknown file formate
*even though my file format is .xml
I’ve tried googling extensively, and am knew to imagej and have nil knowledge of java and any help would be greatly appreciated! thanks
John Bogovic
@shavi1995 , is this the plugin you tried?
yes - the grid/collection stitching plug in is the one
John Bogovic
Probably the plugin does not understand how to get the meta data out of the xml
(It sounds like you gave that to the plugin right?)
Choosing the “positions from file” option? is that right?
yes that’s right
can image j read any .xml meta data file or does it need to be in a particular format?
John Bogovic
It has to be in a particular format, its described on that page i linked above about 3/4 of the way down
it looks like:

# Define the number of dimensions we are working on
dim = 3
# Define the image coordinates (in pixels)
img_73.tif; ; (0.0, 0.0, 0.0)
img_74.tif; ; (409.0, 0.0, 0.0)
img_75.tif; ; (0.0, 409.0, 0.0)
img_76.tif; ; (409.0, 409.0, 0.0)
img_77.tif; ; (0.0, 818.0, 0.0)
img_78.tif; ; (409.0, 818.0, 0.0)

If you need help getting your xml to this format, post something on the forum, and I or someone else can try to help
oh! i thought that was just for the tile configuration.txt but is this true for the metadata file too?
John Bogovic
err, ya, I thought the “tileConfig” is what you meant by metadata…
is there some other metadata?

Does that link work?

@sh95 What system produced this XML file? Is it one of the Bio-Formats supported formats? Note that the Stitching plugin leans on Bio-Formats to convert proprietary file formats (PFFs) into a standard which can be consumed by plugins like Stitching. Can you share the complete dataset?

/cc @dgault @melissa

Thank you for your reply! Its from tissuefax scanner and the metadata set is .xml format which i believe is a bioformat supported format. by complete dataset if you mean images - they are just jpeg files - i prefer not to share due to confidentiality

By data set do you mean all 600 images? The software used is called tissueQuest


Yes, or if you can generate a much smaller subset, as long as it is standalone and complete in a technical sense, that would be good enough.

Please understand that XML is simply the broad structure. Bio-Formats does not support all XML files, only those structured in certain ways, in the same way that Bio-Formats cannot support all “binary” files. It really depends on the XML schema used.

It sounds like this XML file is produced by tissueQuest, meaning it is really a tissueQuest metadata file. So Bio-Formats needs to gain support for tissueQuest. You can send a request to the Bio-Formats team asking for this support to be added, but you’ll need to share at least one sample dataset, and be patient. Alternately (or in addition), you could contact the company which makes tissueQuest asking them to implement an OME-TIFF export feature or similar conversion on their side.

1 Like

Okay - thanks for explaining :slight_smile: cheers

In the mean time, if I may ask I was wondering if you knew of any other way of stitching the images - without using meta data

All the images are stored in sequence, but the number of images in each row varies, i.e. the stitched image is not a rectangle/square.

I am pressed for time to get these images - and will appreciate any suggestions:)


If this were my project, I would write a script which parses your XML file, and writes out a TileConfiguration.txt file. Then I’d use the stitching plugin’s Positions from metadata :arrow_forward: Defined by TileConfiguration option with that file.

Because I personally have unlimited amounts of time :wink:, here is a first cut at such a conversion script:

// @File xmlFile
// @String(label = "Channel", choices = {"Transmission", "DAPI", "Cy 3", "GFP"}) channelName
// @File(label = "TileConfiguration output directory", style = "directory") tcDir

import org.scijava.util.XML

// write the header
tcFile = new File(tcDir, "TileConfiguration-" + channelName + ".txt")
tcFile << "# Define the number of dimensions we are working on\n"
tcFile << "dim = 3\n"
tcFile << "# Define the image coordinates (in pixels)\n"

xml = new XML(xmlFile)
for (fov in xml.elements("//Experiment/Slide/RegionList/Region/FieldOfViewList/FieldOfView")) {
	posOnSlide = fov.getAttribute("PositionOnSlide")

	// parse the PositionOnSlide string into a map
	pos = [:]
	posOnSlide.split(";").each {p ->
    	def keyValue = p.split("=")
    	pos[keyValue[0]] = keyValue[1]
	x = pos['X']
	y = pos['Y']
	z = pos['Z']

	channels = xml.elements(fov, "Channel")
	for (channel in channels) {
		name = channel.getAttribute("Name")
		fileName = channel.getAttribute("FileName")

		if (name == channelName) {
			tcFile << fileName + "; ; (" + x + ", " + y + ", " + z + ")\n"

Note that this is a Groovy script which you can run via the ImageJ Script Editor. It produces a tile configuration file for only one channel at a time. For now, I hardcoded the channel names. You can run it for each channel, and end up with four TileConfiguration files, which you then run through the stitcher one by one, then combine the results using Merge Channels or similar.

I did not test the actual stitching, since I do not have your data to test with.

Hopefully others here can follow up with enhancements, answer further questions, etc.


Thanks so much for this! absolute life saver - however, I ran it on one of the channels - and unfortunately come up with this error message

java.lang.ClassCastException: mpicbg.models.TranslationModel3D cannot be cast to mpicbg.models.TranslationModel2D
	at mpicbg.stitching.CollectionStitchingImgLib.stitchCollection(
	at ij.IJ.runUserPlugIn(
	at ij.IJ.runPlugIn(
	at ij.Executer.runCommand(

Wondered if it was a problem with my Fiji and ran it on a different computer - but same error. The image is not a 3D model either - so I’m unsure what this error message means.

Any help would be appreciated (don’t have a computer/imaging background) !


The issue seems to be that your images are 2D (jpeg) and your TileConfiguration.txt defines 3D coordinates for each tile. You can either leave away the z coordinates from the tile configuration file, or (as it seems you have multiple slices in separate files) first merge the single slices into stacks, re-save them, and stitch these stacks with a TileConfiguration.txt that contains 0 as the third coordinate for each tile.

In the past I was using the XML Reader and XPath nodes in KNIME to do similar pre-processing for tiled datasets from a Yokogawa CV7000 high-content screening microscope. If I find the time, I’ll share an example workflow later on.