Access to image metadata

Hi all!

I’ve been trying importing some annotations from different format (Aperio xml, Hamamatsu ndpa, csv, etc…) to QuPath in order to visualize and/or continue previous work from my lab.
My question is about the Hamamatsu ndpa format. Eventually, the ndpa file is a xml-based format which is possible to import into QuPath using a script similar to that proposed to import Aperio files (
Labelled annotation import). However, the point positions are related to the image metadata, in particular to the “X (and Y) offset from slide centre” property. Using python (and Openslide) I’ve been able to check this information and import successfully the annotations. Now, I would like to avoid using python everytime (and for each file). Therefore, I need to access to this particular information or, even, the image metadata but, so far I only get the server metadata as is exposed in Metadata batch export . Is there any way to obtain this information via groovy script?

Hi @erme, sure!

def cal = getCurrentServer().getPixelCalibration()
print cal.getPixelWidth()
print cal.getPixelHeight()

That does assume your current image is open… so might just be what you’ve seen in the other script. If you need something else, let me know.

But check out this as well (I haven’t tried it, but might solve the problem already):

The offset between the (0,0) point in the boundsX and boundsY property:

def x = getCurrentServer().boundsX
def y = getCurrentServer().boundsY

When I’ve had annotations, offsetting each vertex by x and y has aligned them with the ndpi files. I’m not sure if that’s the problem here but maybe it can help someone in a similar situation.

1 Like

Hi @petebankhead,

I’m sorry, I didn’t find this thread. I was looking for this piece of code:

def map = getCurrentImageData().getServer().osr.getProperties()
map.each { k, v ->
    if(k.equals("hamamatsu.XOffsetFromSlideCentre")){ offsetX = Float.parseFloat(v) }
    if(k.equals("hamamatsu.YOffsetFromSlideCentre")){ offsetY = Float.parseFloat(v) }

Thank you so much


Hi @Patrick_Leo,

unfortunately, your code doesn’t work in my case. It returns “0” but I can obtain the right value using the code exposed in my previous post.

1 Like

Darn. I wonder if there’s some difference between scanners that the ndpi images I was using had that property but yours don’t. I’ll leave it up anyway in case someone else has some insight.


Ah, I see. Interesting that there is a difference. Both scripts are sneakily accessing a private field within QuPath’s ImageServer, but it’s the only way for now.

One consideration: both will break if Bio-Formats is reading the .ndpi image instead, since it represents the information differently (I’ve never had reason to compare them before). An unfortunate consequence of having multiple readers to try to support as many (proprietary) formats as we can.

Potentially if you wanted to get around this you could request the URIs for the original file(s) with getCurrentServer().getURIs() and construct a tiff reader with ImageIO and request the corresponding tifftags from there (identified with the help of OpenSlide’s description here)… thereby making your script independent of whatever reader QuPath is using. But that could be quite a bit of effort to solve a problem that may not exist if you’re always using OpenSlide anyway.

1 Like