We're Hiring!

Getting stage coordinates for non-SPW images

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Getting stage coordinates for non-SPW images

Postby dsudar » Tue Aug 29, 2017 9:14 pm

Hi team,

I'm trying to find how I can get access in Python to the stage coordinates for regular images. I tried the following:
Code: Select all
stg_lab = image.getStageLabel()
if stg_lab is not None:
    print "StageLabel found:"
    print "  name: %s, version: %s" % (stg_lab.getName(), stg_lab.getVersion())
    print "  pos X: %s" % stg_lab.positionX.getValue()
    print "  pos Y: %s" % stg_lab.positionY.getValue()


But even though for many images "showinf -omexml" shows that the stage coordinates are being extracted properly by BioFormats, I never see a StageLabel populated.

I noticed that when SPW's are imported, the posX and posY in WellSample DO get populated with correct coordinates within each well but images in wells also don't get their StageLabel populated.

Thanks,
- Damir
dsudar
 
Posts: 235
Joined: Mon May 14, 2012 8:43 pm
Location: Berkeley, CA, USA

Re: Getting stage coordinates for non-SPW images

Postby dgault » Wed Aug 30, 2017 2:32 pm

Hi Damir,

The function to use will depend on the format and where in the OME-XML the position data is tored. The image.getStageLabel() function is used for some formats which have a StageLabel entry stored directly under the Image in the OME-XML.

For most formats the positionX and positionY values you are trying to retrieve will be stored on the Plane or WellSample. In these instances you can retrieve them as below:

Code: Select all
root.getImage(imageIndex).getPixels().getPlane(planeIndex).getPositionX();
root.getPlate(plateIndex).getWell(wellIndex).getWellSample(wellSampleIndex).getPositionX();


I hope that is of help, if you are still not able to retrieve the information please provide a example of the generated OME-XML and I can assist further.

David Gault
User avatar
dgault
Team Member
 
Posts: 208
Joined: Fri Aug 14, 2015 2:56 pm

Re: Getting stage coordinates for non-SPW images

Postby dsudar » Wed Aug 30, 2017 6:13 pm

Hi David,

Thanks! Unfortunately, since the example you are showing is in Java, I'm having a hard time finding the equivalent for Python:
- instead of getPixels(), I guess I should use getPrimaryPixels() ?
- in Python getPlane() returns a numpy array which has no getPositionX() attribute. Is there a way to access the real OME Plane object's info?

I'm mostly trying to get the coordinates for images from a large ND2 file so I can organize them by their location. The showinf output shows this type of info:
Code: Select all
Generating OME-XML (schema version 2016-06)
<?xml version="1.0" encoding="UTF-8"?>
<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
   <Instrument ID="Instrument:0">
      <Detector ID="Detector:0:0" Type="Other"/>
      <Objective Correction="Other" ID="Objective:0:0" Immersion="Other"/>
   </Instrument>
   <Image ID="Image:0" Name="PlateLI9V01905_WellA01_Seq0000.nd2 (series 01)">
      <InstrumentRef ID="Instrument:0"/>
      <ObjectiveSettings ID="Objective:0:0" RefractiveIndex="1.0"/>
      <Pixels BigEndian="false" DimensionOrder="XYCZT" ID="Pixels:0" Interleaved="false" PhysicalSizeX="0.321212" PhysicalSizeXUnit="µm" PhysicalSizeY="0.321212" PhysicalSizeYUnit="µm" SignificantBits="16" SizeC="2" SizeT="1" SizeX="1600" SizeY="1600" SizeZ="1" Type="uint16">
         <Channel Color="65535" EmissionWavelength="440.0" EmissionWavelengthUnit="nm" ID="Channel:0:0" Name="395nm" SamplesPerPixel="1">
            <DetectorSettings ID="Detector:0:0"/>
            <LightPath/>
         </Channel>
         <Channel Color="-13434625" EmissionWavelength="607.0" EmissionWavelengthUnit="nm" ID="Channel:0:1" Name="555nm" SamplesPerPixel="1">
            <DetectorSettings ID="Detector:0:0"/>
            <LightPath/>
         </Channel>
         <MetadataOnly/>
         <Plane DeltaT="7.729394392967224" DeltaTUnit="s" ExposureTime="0.0" ExposureTimeUnit="s" PositionX="113148.35" PositionXUnit="reference frame" PositionY="75198.0" PositionYUnit="reference frame" PositionZ="200.0" PositionZUnit="reference frame" TheC="0" TheT="0" TheZ="0"/>
         <Plane DeltaT="7.729394392967224" DeltaTUnit="s" ExposureTime="100.0" ExposureTimeUnit="s" PositionX="113148.35" PositionXUnit="reference frame" PositionY="75198.0" PositionYUnit="reference frame" PositionZ="200.0" PositionZUnit="reference frame" TheC="1" TheT="0" TheZ="0"/>
      </Pixels>
   </Image>
   <Image ID="Image:1" Name="PlateLI9V01905_WellA01_Seq0000.nd2 (series 02)">
      <InstrumentRef ID="Instrument:0"/>
      <ObjectiveSettings ID="Objective:0:0" RefractiveIndex="1.0"/>
      <Pixels BigEndian="false" DimensionOrder="XYCZT" ID="Pixels:1" Interleaved="false" PhysicalSizeX="0.321212" PhysicalSizeXUnit="µm" PhysicalSizeY="0.321212" PhysicalSizeYUnit="µm" SignificantBits="16" SizeC="2" SizeT="1" SizeX="1600" SizeY="1600" SizeZ="1" Type="uint16">
         <Channel Color="65535" EmissionWavelength="440.0" EmissionWavelengthUnit="nm" ID="Channel:1:0" Name="395nm" SamplesPerPixel="1">
            <DetectorSettings ID="Detector:0:0"/>
            <LightPath/>
         </Channel>
         <Channel Color="-13434625" EmissionWavelength="607.0" EmissionWavelengthUnit="nm" ID="Channel:1:1" Name="555nm" SamplesPerPixel="1">
            <DetectorSettings ID="Detector:0:0"/>
            <LightPath/>
         </Channel>
         <MetadataOnly/>
         <Plane DeltaT="9.107385417938232" DeltaTUnit="s" ExposureTime="0.0" ExposureTimeUnit="s" PositionX="112418.75" PositionXUnit="reference frame" PositionY="75198.0" PositionYUnit="reference frame" PositionZ="200.0" PositionZUnit="reference frame" TheC="0" TheT="0" TheZ="0"/>
         <Plane DeltaT="9.107385417938232" DeltaTUnit="s" ExposureTime="0.0" ExposureTimeUnit="s" PositionX="112418.75" PositionXUnit="reference frame" PositionY="75198.0" PositionYUnit="reference frame" PositionZ="200.0" PositionZUnit="reference frame" TheC="1" TheT="0" TheZ="0"/>
      </Pixels>
   </Image>


and those (PositionX, PositionY) coordinates per image are correct and what I need.

Thanks,
- Damir
dsudar
 
Posts: 235
Joined: Mon May 14, 2012 8:43 pm
Location: Berkeley, CA, USA

Re: Getting stage coordinates for non-SPW images

Postby dgault » Thu Aug 31, 2017 2:19 pm

Hi Damir,

My apologies, in that case the information your looking for should be available from the planeInfo object. Either getPixels or getPrimaryPixels should be fine.

Code: Select all
pixels = image.getPrimaryPixels()
assert pixels.OMERO_CLASS == 'Pixels'
assert pixels._obj.__class__ == omero.model.PixelsI
planeInfo = list(pixels.copyPlaneInfo())
assert len(planeInfo) == sizeZ*sizeC*sizeT
planeInfo = list(pixels.copyPlaneInfo())
for p in planeInfo:
  posX = p.positionX
  posY = p.positionY
User avatar
dgault
Team Member
 
Posts: 208
Joined: Fri Aug 14, 2015 2:56 pm

Re: Getting stage coordinates for non-SPW images

Postby dsudar » Thu Aug 31, 2017 6:27 pm

Thanks David, that works like a charm. Much appreciated!
- Damir
dsudar
 
Posts: 235
Joined: Mon May 14, 2012 8:43 pm
Location: Berkeley, CA, USA


Return to Developer Discussion

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron