Default rendering settings when script creates an image
Posted: Thu Aug 04, 2011 11:08 am
Hi,
I am using the Gateway API to create new images. I have scripts that work on multi-channel images and create new images using createImageFromNumpySeq().
I would like to know the best way to set up the default rendering settings for the image. I have managed to do this using the following code:
This sets the rendering colours, channel names and physical size using the original image.
However the colours are not set as the defaults and are only applied to the user who owns the connection object:
Is there a way to set the default channel colours for all users?
Thanks,
Alex
I am using the Gateway API to create new images. I have scripts that work on multi-channel images and create new images using createImageFromNumpySeq().
I would like to know the best way to set up the default rendering settings for the image. I have managed to do this using the following code:
- Code: Select all
def cloneImage(conn, img):
"""
Clone the image into the same dataset in OMERO.
@param conn: The BlitzGateway connection
@param img: The OMERO ImageWrapper object
"""
imageName = os.path.basename(img.getName())
print "Image Id = %s" % img.getId()
print "Image name = %s" % imageName
print "Dimensions = x%s,y%s,z%s,c%s,t%s" % (
img.getSizeX(), img.getSizeY(), img.getSizeZ(), img.getSizeC(), img.getSizeT() )
renderingEngine = conn.createRenderingEngine()
updateService = conn.getUpdateService()
pixels = img.getPrimaryPixels()
Z = range(img.getSizeZ())
C = range(img.getSizeC())
T = range(img.getSizeT())
# Store original channel colours and names
colors = []
cNames = []
for index, c in enumerate(img.getChannels()):
colors.append(c.getColor().getRGB())
cNames.append(str(c.getLabel()))
# Use a tile generator to join up multiple frame image and upload to OMERO
def tileGen():
for z in Z:
for c in C:
for t in T:
# ACTUAL PROCESSING WOULD BE DONE HERE
yield pixels.getPlane(z, c, t)
newImg = conn.createImageFromNumpySeq(tileGen(),
img.getName(), len(Z), len(C), len(T),
img.getDescription(), dataset=img.getDataset())
print "New Image Id = %s" % newImg.getId()
# Apply colors from the original image to the new one
newImg._prepareRenderingEngine()
for c, color in enumerate(colors):
r,g,b = color
newImg._re.setRGBA(c, r, g, b, 255)
newImg._re.saveCurrentSettings()
newImg._re.close()
# Apply the original channel names
pixelsId = newImg.getId()
renderingEngine.lookupPixels(pixelsId)
if not renderingEngine.lookupRenderingDef(pixelsId):
renderingEngine.resetDefaults()
renderingEngine.load()
pixels = renderingEngine.getPixels()
for i, c in enumerate(pixels.iterateChannels()):
lc = c.getLogicalChannel()
lc.setName(rstring(cNames[i]))
updateService.saveObject(lc)
# Apply the original pixel size - Need to get the object again to refresh state
newImg = conn.getObject("Image", newImg.getId())
pixels = newImg.getPrimaryPixels()
pixels.setPhysicalSizeX(rdouble(img.getPixelSizeX()))
pixels.setPhysicalSizeY(rdouble(img.getPixelSizeY()))
pixels.setPhysicalSizeZ(rdouble(img.getPixelSizeZ()))
pixels.save()
This sets the rendering colours, channel names and physical size using the original image.
However the colours are not set as the defaults and are only applied to the user who owns the connection object:
- If the owner opens the image in OMERO Insight and, using the rendering controls, resets the image to defaults the channel colours get reset
- Other users do not see the applied colours
Is there a way to set the default channel colours for all users?
Thanks,
Alex