Page 1 of 1

setting physical pixel size

PostPosted: Thu Aug 28, 2014 11:23 pm
by ebbwdan
Hello,

I'm probably missing this in the documentation but I was just wondering how I can set the physical pixel size when creating an image from scratch on the server. So, writing an image using 'createImageFromNumpySeq' when a parent image doesn't exist.

Many thanks!

Dan.

Re: setting physical pixel size

PostPosted: Fri Aug 29, 2014 10:08 am
by wmoore
Hi Dan,

Here you go...
Code: Select all
from omero.rtypes import rdouble

conn = BlitzGateway('will', 'ome', host="localhost", port=4064)
conn.connect()

# createImage (details not shown)
i = conn.createImageFromNumpySeq (.....)

# reload the image (also reloads pixels)
image = conn.getObject("Image", i.getId())

# Get the BlitzGateway wrapped pixels and unwrap it
pixelsWrapper = image.getPrimaryPixels()
pixels = pixelsWrapper._obj

# Update and save
pixSize = rdouble(1.1)      # in microns

pixels.setPhysicalSizeX( pixSize )
pixels.setPhysicalSizeY( pixSize )

conn.getUpdateService().saveObject(pixels)

Re: setting physical pixel size

PostPosted: Mon Sep 01, 2014 2:36 am
by ebbwdan
Hi Will,

Thanks! Don't know how I missed that.

Cheers,

Dan.

Re: setting physical pixel size

PostPosted: Thu Apr 14, 2016 8:06 am
by markmendell
Heads up to anyone reading this now - the setPhysicalSize functions expect a "Length"-type argument instead of an "rdouble", so the line

Code: Select all
pixSize = rdouble(1.1)

should be replaced with

Code: Select all
pixSize = omero.model.LengthI(1.1, omero.model.enums.UnitsLength.MICROMETER)

Reference

Re: setting physical pixel size

PostPosted: Fri Apr 15, 2016 11:03 am
by wmoore
Thanks for the heads up.

The docs on this also show the current usage of Units to set pixel size:
https://www.openmicroscopy.org/site/sup ... eate-image

Cheers,

Will.