How to calculate XY position of an image for a reference image (.scn file and ome-xml)?

As an example .scn file (test.scn), please click the URL below:
https://briefcase.riken.jp/public/kYtIAATmHkFA0-k
Then, input password = scn.
Metadata of the file can be see in Fiji or OMERO through Bio-formats.

My question is how to calculate location of an image within a reference image in a .scn file. (e.g, XY positions of the top-left pixel of image with ID “Image:3” within a reference image with ID =“Image:0” when considering the top-left pixel of the reference image as (0,0) in test.scn).

I guess that clue is the information of PositionX, PositionXUnit, PositionY, and PositionYUnit in tag “Plane" for image with ID “Image:3”.

For “image:0"

  • SizeX = 1616 pixel & PhysicalSizeX = 16.438 micrometer (=> actual SizeX = 26563.808 micrometer)
  • SizeY = 4668 pixel & PhysicalSizeY = 16.438 micrometer (=> actual SizeY = 76732.584 micrometer)

For “image:3”

  • SizeX = 17536 pixel & PhysicalSizeX = 0.25 micrometer (=> actual SizeX = 4384 micrometer)
  • SizeY = 18304 pixel & PhysicalSizeY = 0.25 micrometer (=> actual SizeY = 4576 micrometer).

Here positionXY in tag “Plane" of “Image:3” as follows:

  • PositionX = 17698520 & PositionXUnit = “reference frame"
  • PositionY = 44134172 & PositionYUnit = “reference frame"

How can I convert position XY (17698520, 44134172) to the relative position XY in image with ID “Image:0”?

Best regards,
Yukako

Hi @Yukako_Tohsato -san.

Where are you seeing the Position{XY} fields? In OMERO and via showinf I’m not seeing them. I also tried opening the file in #qupath but again I didn’t see the related metadata.

For everyone’s reference, what version of Bio-Formats are you using?

All the best,
~Josh

Hi, Josh -san.

Thank you for your response.

I can see PositionXY fields on Fiji (ver. 2.0.0-rdc-69) when checked “Display OME-XML metdata”

in “Metadata viewing” section with the latest Bio-Formats (ver. 6.3.1).

Yukako.

Thanks for the details, @Yukako_Tohsato -san. Recording my investigations, the source code for the Leica SCN reader suggests we aren’t exactly sure of the interpretation:

    long vOffsetX; // view offset x (nm?)
    long vOffsetY; // view offset y (nm?)

...

        // Leica units are nanometres; convert to µm
        double sizeX = i.vSizeX / 1000.0;
        double sizeY = i.vSizeY / 1000.0;
        final Length offsetX = new Length(i.vOffsetX, UNITS.REFERENCEFRAME);
        final Length offsetY = new Length(i.vOffsetY, UNITS.REFERENCEFRAME);
        double sizeZ = i.vSpacingZ / 1000.0;

        store.setPixelsPhysicalSizeX(
          FormatTools.getPhysicalSizeX(sizeX / dimension.sizeX), pos);
        store.setPixelsPhysicalSizeY(
          FormatTools.getPhysicalSizeY(sizeY / dimension.sizeY), pos);
        store.setPixelsPhysicalSizeZ(FormatTools.getPhysicalSizeZ(sizeZ), pos);

but let’s assume we’re dealing with nanometers.

Looking at the resolutions for a single image:

image_0000247592 (R0)	18048	15680	0.25µm	  0.25µm	        15	        33
image_0000247592 (R1)	 4512	 3920	1.00µm	  1.00µm	        15	        33
image_0000247592 (R2)	 1128	  980	4.00µm	  4.00µm	        15	        33
image_0000247592 (R3)	  282	  245	16.00µm	  16.00µm	        15	        33
image_0000247592 (R4)	   71	   61	63.55µm	  64.26µm	        15	        33
image_0000247592 (R5)	   18	   15	250.67µm 261.33µm	        15	        33

you’ll see the same position values everywhere, so something’s up there. These are the smallest resolutions:

lowest-resolution       sizeX   sizeY physicalX  physicalY          posX         posY
--------------------    -----   -----   --------    --------         ----          ---
image_0000247585 (R2)	  101	  291	263.02µm	263.69µm	         0	         0
image_0000247589 (R5)	   17	   17	257.88µm	269.18µm	        17	        44
image_0000247590 (R5)	   21	   16	255.24µm	266.00µm	        17	        23
image_0000247591 (R5)	   21	   12	259.05µm	261.33µm	        16	        52
image_0000247592 (R5)	   18	   15	250.67µm	261.33µm	        15	        33
image_0000247593 (R5)	   26	   23	251.69µm	256.00µm	        14	        13
image_0000247594 (R5)	   21	   15	255.24µm	265.60µm	         4	        50
image_0000247595 (R5)	   21	   15	255.24µm	269.87µm	         4	        43
image_0000247596 (R5)	   24	   19	259.33µm	261.89µm	         4	        23
image_0000247597 (R5)	   22	   24	258.91µm	256.67µm	         4	        13
image_0000247598 (R5)	   20	   17	258.40µm	269.18µm	         3	        33

and these the largest:

image_0000247585 (R0)	 1616	 4668	16.44µm	16.44µm	         0	         0
image_0000247589 (R0)	17536	18304	0.25µm	0.25µm	        17	        44
image_0000247590 (R0)	21440	17024	0.25µm	0.25µm	        17	        23
image_0000247591 (R0)	21760	12544	0.25µm	0.25µm	        16	        52
image_0000247592 (R0)	18048	15680	0.25µm	0.25µm	        15	        33
image_0000247593 (R0)	26176	23552	0.25µm	0.25µm	        14	        13
image_0000247594 (R0)	21440	15936	0.25µm	0.25µm	         4	        50
image_0000247595 (R0)	21440	16192	0.25µm	0.25µm	         4	        43
image_0000247596 (R0)	24896	19904	0.25µm	0.25µm	         4	        23
image_0000247597 (R0)	22784	24640	0.25µm	0.25µm	         4	        13
image_0000247598 (R0)	20672	18304	0.25µm	0.25µm	         3	        33

(Positions are divided by 10^6.) I don’t yet see a conclusive interpretation of the position information.

~Josh

p.s. investigation gist in case anyone wants it.

1 Like

Hi Josh, @joshmoore

Thanks a lot for giving me your investigations based on source codes (Leica reader & your test.py) have been very useful.

To export positionXY information as .xml from .scn, I will use showinf (e.g. showinf test.scn -nopix -omexml-only > test.xml), after configuring the maximum heap size of bfconvert by setting the BF_MAX_MEN environment variables, since actual .scn file is too large. I will then regenerate ROI information from the .xml file based on your code.

Regards,
Yukako

1 Like