I’m really sorry, but I’m sort of blanking in this one: Is there a way to export the metadata / image properties of all images in a project as a .csv file? I mean the information that is displayed under Image > Properties (such as Path, Image type, Magnification, etc.). A short explainer / script snippet would be so much appreciated.
Pete has a script here that shows how to access some of the metadata, and the file name path is stored in a different place, but I don’t know of anything where it is all together. I also believe that metadata access and storage is a bit of a moving target with the current versions, so any script you make for 0.2.0 may be broken with the next version. I believe the link works for 0.1.2 and not 0.2.0, but somewhere on the forum Pete posted a corrected version. I just can’t find it right now.
File path is usually accessed in scripts by:
def server = getCurrentImageData().getServer() def path = server.getPath() println path
I usually only use built in functions to export data files, but once you have a bunch of strings, it should be standard Groovy (not QuPath specific) to export them as a CSV.
@Research_Associate Thanks a lot. I’ll check it out. If you happen to find that corrected version, would you let me know? That would be fantastic. Have an awesome week.
Some further information seems to also be available through getServer(), the script was more geared towards setting the metadata.
def server = getCurrentImageData().getServer() def path = server.getPath() def pixelHeight = server.getPixelHeightMicrons() def imageHeightPixels = server.getHeight() println server.getServerType() println server.getMagnification()
Probably more, but I haven’t figured out all of the commands.
That seems to be more what you want.
@SebastianF Can you specify exactly what metadata you want to export? And is there any reason why it should be .csv?
It would likely be easier to export ‘everything’ as JSON, and in fact that’s how QuPath is likely to store it when v0.2.0 finally does become available. Until then, as @Research_Associate says it is a bit of a moving target as I try to establish which metadata is really needed… it might not all be relevant for your use though.
@petebankhead @Research_Associate Thank you both so much for your fast response. So I have a project dealing with H&E whole slides taken from various scanners and I want to get more information on the images’ properties such as magnification, pyramid, etc. Basically the information from the properties table here:
I would like to run such a short script for all the approx. 800 images in the project and get these information in a table. CSV was just so that I can further process it - JSON would also be helpful. Hope this makes it clearer. Sorry for not being on point earlier. Thanks again big time for your support.
EDIT: If scanner information are available these would also be useful
If the scanners are from different manufacturers, and it is consistent, you might be able to split the file name by periods and create a scanner field based off of the file extension. This is not code but something like:
if split_path[-1].contains(“czi”) set some string variable to “Zeiss Axioscan Z1”
@petebankhead Do we have access to all of the BioFormats functions for reading metadata? I haven’t really tried. I thought that might be separate software. *not that it matters for his OpenSlide example
The easiest thing is to use a script like this:
server = getCurrentImageData().getServer() tab = '\t' String result = server.getPath() << tab << server.getWidth() << tab << server.getHeight() << tab << server.getPixelWidthMicrons() << tab << server.getPixelHeightMicrons() << tab << (server.getPreferredDownsamples() as List) print result
and then Run → Run for project (without save). You’ll need to clean up some of the 'INFO: 's that it prints.
You could also append to an existing text file. From memory, I think it’s something like this:
def file = new File('/path/to/file.txt') // ... result stuff as before... file << result
The formatting for the properties table in the user interface is rather involved, so I think best export exactly what you want without relying on it.