Figure scripts
Movie Figure
Script produces a figure of a movie, showing panels of different frames. Saves the figure as a jpg or png attached to the first image in the figure.
- Movie_Figure.add_left_labels(panel_canvas, image_labels, row_index, width, spacer)
Takes a canvas of panels and adds one or more labels to the left, with the text aligned vertically. NB: We are passed the set of labels for ALL image panels (as well as the index of the current image panel) so that we know what is the max label count and can give all panels the same margin on the left.
- Parameters
panelCanvas – PIL image - add labels to the left of this
imageLabels – A series of label lists, one per image. We only add labels from one list
rowIndex – The index of the label list we’re going to use from imageLabels
width – Simply used for finding a suitable font size
spacer – Space between panels
- Movie_Figure.createmovie_figure(conn, pixel_ids, t_indexes, z_start, z_end, width, height, spacer, algorithm, stepping, scalebar, overlay_colour, time_units, image_labels, max_col_count)
Makes the complete Movie figure: A canvas showing an image per row with multiple columns showing frames from each image/movie. Labels obove each frame to show the time-stamp of that frame in the specified units and labels on the left name each image.
- Parameters
conn – The OMERO session
pixel_ids – A list of the Pixel IDs for the images in the figure
t_indexes – A list of tIndexes to display frames from
z_start – Projection Z-start
z_end – Projection Z-end
width – Maximum width of panels
height – Max height of panels
spacer – Space between panels
algorithm – Projection algorithm e.g. “MAXIMUMINTENSITY”
stepping – Projection z-step
scalebar – A number of microns for scale-bar
overlay_colour – Color of the scale bar as tuple (255,255,255)
time_units – A string such as “SECS”
image_labels – A list of lists, corresponding to pixelIds, for labelling each image with one or more strings.
- Movie_Figure.movie_figure(conn, command_args)
Makes the figure using the parameters in @command_args, attaches the figure to the parent Project/Dataset, and returns the file-annotation ID
- Parameters
session – The OMERO session
command_args – Map of parameters for the script
- Returns
Returns the id of the originalFileLink child. (ID object, not value)
- Movie_Figure.run_script()
The main entry point of the script. Gets the parameters from the scripting service, makes the figure and returns the output to the client.
Movie ROI Figure
This script takes a number of images and displays regions defined by their ROIs as zoomed panels beside the images.
- Movie_ROI_Figure.get_rectangle(roi_service, image_id, roi_label)
Returns (x, y, width, height, timeShapeMap) of the all rectanges in the first ROI of the image where timeShapeMap is a map of tIndex: (x,y,zMin,zMax) x, y, Width and Height are from the first rectangle (assumed that all are same size!)
- Movie_ROI_Figure.get_roi_movie_view(re, query_service, pixels, time_shape_map, merged_indexes, merged_colours, roi_width, roi_height, roi_zoom, spacer=12, algorithm=None, stepping=1, font_size=24, max_columns=None, show_roi_duration=False)
This takes a ROI rectangle from an image and makes a movie canvas of the region in the ROI, zoomed by a defined factor.
- Movie_ROI_Figure.get_split_view(conn, image_ids, pixel_ids, merged_indexes, merged_colours, width, height, image_labels, spacer, algorithm, stepping, scalebar, overlay_colour, roi_zoom, max_columns, show_roi_duration, roi_label)
This method makes a figure of a number of images, arranged in rows with each row being the split-view of a single image. The channels are arranged left to right, with the combined image added on the right. The combined image is rendered according to current settings on the server, but it’s channels will be turned on/off according to @mergedIndexes.
The figure is returned as a PIL ‘Image’
- Parameters
session – session for server access
pixelIds – a list of the Ids for the pixels we want to display
mergedIndexes – list or set of channels in the merged image
mergedColours – index: colour dictionary of channels in the merged image
width – the size in pixels to show each panel
height – the size in pixels to show each panel
spacer – the gap between images and around the figure. Doubled between rows.
- Movie_ROI_Figure.get_time_indexes(time_points, max_frames)
If we want to display a number of timepoints (e.g. 11), without exceeding max_frames (e.g. 5), need to pick a selection of t-indexes e.g. 0, 2, 4, 7, 10 This method returns the list of indexes. NB - Not used at present - but might be needed.
- Movie_ROI_Figure.log(text)
Adds the text to a list of logs. Compiled into figure legend at the end.
- Movie_ROI_Figure.roi_figure(conn, command_args)
This processes the script parameters, adding defaults if needed. Then calls a method to make the figure, and finally uploads and attaches this to the primary image.
- Parameters
session – The OMERO session
command_args – Map of String:Object parameters for the script. Objects are not rtypes, since getValue() was called when the map was processed below. But, list and map objects may contain rtypes (need to call getValue())
- Returns
the id of the originalFileLink child. (ID object, not value)
- Movie_ROI_Figure.run_script()
The main entry point of the script, as called by the client via the scripting service, passing the required parameters.
ROI Split Figure
This script takes a number of images and displays regions defined by their ROIs as zoomed panels beside the images.
- ROI_Split_Figure.get_rectangle(roi_service, image_id, roi_label)
Returns (x, y, width, height, zMin, zMax, tMin, tMax) of the first rectange in the image that has roi_label as text.
- Returns
First rectangle.
- ROI_Split_Figure.get_roi_split_view(re, pixels, z_start, z_end, split_indexes, channel_names, merged_names, colour_channels, merged_indexes, merged_colours, roi_x, roi_y, roi_width, roi_height, roi_zoom, t_index, spacer, algorithm, stepping, fontsize, show_top_labels)
This takes a ROI rectangle from an image and makes a split view canvas of the region in the ROI, zoomed by a defined factor.
- Parameters
re – The OMERO rendering engine.
- ROI_Split_Figure.get_split_view(conn, image_ids, pixel_ids, split_indexes, channel_names, merged_names, colour_channels, merged_indexes, merged_colours, width, height, image_labels, spacer, algorithm, stepping, scalebar, overlay_colour, roi_zoom, roi_label)
This method makes a figure of a number of images, arranged in rows with each row being the split-view of a single image. The channels are arranged left to right, with the combined image added on the right. The combined image is rendered according to current settings on the server, but it’s channels will be turned on/off according to @mergedIndexes.
The figure is returned as a PIL ‘Image’
- Parameters
session – session for server access
pixel_ids – a list of the Ids for the pixels we want to display
split_indexes – a list of the channel indexes to display. Same channels for each image/row
channel_names – the Map of index:names for all channels
colour_channels – the colour to make each column/ channel
merged_indexes – list or set of channels in the merged image
merged_colours – index: colour dictionary of channels in the merged image
width – the size in pixels to show each panel
height – the size in pixels to show each panel
spacer – the gap between images and around the figure. Doubled between rows.
- ROI_Split_Figure.log(text)
Adds the text to a list of logs. Compiled into figure legend at the end.
- ROI_Split_Figure.roi_figure(conn, command_args)
This processes the script parameters, adding defaults if needed. Then calls a method to make the figure, and finally uploads and attaches this to the primary image.
- Param
session The OMERO session
- Param
command_args Map of String:Object parameters for the script. Objects are not rtypes, since getValue() was called when the map was processed below. But, list and map objects may contain rtypes (need to call getValue())
- Returns
the id of the originalFileLink child. (ID object, not value)
- ROI_Split_Figure.run_script()
The main entry point of the script, as called by the client via the scripting service, passing the required parameters.
Split View Figure
This script takes a number of images an makes a split view figure, one image per row, displayed as a split view with merged image.
- Split_View_Figure.get_split_view(conn, pixel_ids, z_start, z_end, split_indexes, channel_names, colour_channels, merged_indexes, merged_colours, width=None, height=None, spacer=12, algorithm=None, stepping=1, scalebar=None, overlay_colour=(255, 255, 255))
This method makes a figure of a number of images, arranged in rows with each row being the split-view of a single image. The channels are arranged left to right, with the combined image added on the right. The combined image is rendered according to current settings on the server, but its channels will be turned on/off according to @merged_indexes. No text labels are added to the image at this stage.
The figure is returned as a PIL ‘Image’
- Parameters
conn – session for server access
pixel_ids – a list of the Ids for the pixels we want to display
z_start – the start of Z-range for projection
z_end – the end of Z-range for projection
split_indexes – a list of the channel indexes to display. Same channels for each image/row
channel_names – the Map of index:names to go above the columns for each split channel
colour_channels – the colour to make each column/ channel
merged_indexes – list or set of channels in the merged image
merged_colours – index: colour dictionary of channels in the merged image
width – the size in pixels to show each panel
height – the size in pixels to show each panel
spacer – the gap between images and around the figure. Doubled between rows.
- Split_View_Figure.log(text)
Adds the text to a list of logs. Compiled into figure legend at the end.
- Split_View_Figure.make_split_view_figure(conn, pixel_ids, z_start, z_end, split_indexes, channel_names, colour_channels, merged_indexes, merged_colours, merged_names, width, height, image_labels=None, algorithm=None, stepping=1, scalebar=None, overlay_colour=(255, 255, 255))
This method makes a figure of a number of images, arranged in rows with each row being the split-view of a single image. The channels are arranged left to right, with the combined image added on the right. The combined image is rendered according to current settings on the server, but its channels will be turned on/off according to @merged_indexes. The colour of each channel turned white if colour_channels is false or the channel is not in the merged image. Otherwise channel is changed to merged_colours[i] Text is added at the top of the figure, to display channel names above each column, and the combined image may have its various channels named in coloured text. The optional image_labels is a list of string lists for naming the images at the left of the figure (Each image may have 0 or multiple labels).
The figure is returned as a PIL ‘Image’
- Parameters
conn – session for server access
pixel_ids – a list of the Ids for the pixels we want to display
z_start – the start of Z-range for projection
z_end – the end of Z-range for projection
split_indexes – a list of the channel indexes to display. Same channels for each image/row
channel_names – map of index:name to go above the columns for each split channel
colour_channels – true if split channels are
merged_indexes – list (or set) of channels in the merged image
merged_colours – index: colour map of channels in the merged image
merged_names – if true, label with merged panel with channel names (otherwise, label “Merged”)
width – the width of primary image. All images zoomed to this height
height – the height of primary image
image_labels – optional list of string lists.
algorithm – for projection MAXIMUMINTENSITY or MEANINTENSITY
stepping – projection increment
- Split_View_Figure.run_script()
The main entry point of the script, as called by the client via the scripting service, passing the required parameters.
- Split_View_Figure.split_view_figure(conn, script_params)
Processes the arguments, populating defaults if necessary. Prints the details to log (fig-legend). Even handles missing arguments that are not optional (from when this ran from commandline with everything optional) then calls make_split_view_figure() to make the figure, attaches it to the Image as an ‘originalFile’ annotation, with fig-legend as the description.
- Returns
the id of the originalFileLink child. (ID object, not value)
Thumbnail Figure
This script displays a bunch of thumbnails from OMERO as a jpg or png, saved back to the server as a FileAnnotation attached to the parent dataset or project.
- Thumbnail_Figure.get_font(fontsize)
Returns a PIL ImageFont Sans-serif true-type font of the specified size or a pre-compiled font of fixed size if the ttf font is not found
- Parameters
fontsize – The size of the font you want
- Returns
A PIL Font
- Thumbnail_Figure.log(text)
Adds lines of text to the log_lines list, so they can be collected into a figure legend.
- Thumbnail_Figure.make_thumbnail_figure(conn, script_params)
Makes the figure using the parameters in @script_params, attaches the figure to the parent Project/Dataset, and returns the file-annotation ID
- Returns
Returns the id of the originalFileLink child. (ID object, not value)
- Thumbnail_Figure.paint_dataset_canvas(conn, images, title, tag_ids=None, show_untagged=False, col_count=10, length=100)
Paints and returns a canvas of thumbnails from images, laid out in a set number of columns. Title and date-range of the images is printed above the thumbnails, to the left and right, respectively.
- Parameters
conn – Blitz connection
image – Image IDs
title – title to display at top of figure. String
tag_ids – Optional to sort thumbnails by tag. [long]
col_count – Max number of columns to lay out thumbnails
length – Length of longest side of thumbnails
- Thumbnail_Figure.paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids, col_count, bg=(255, 255, 255), left_label=None, text_color=(0, 0, 0), fontsize=None, top_label=None)
Retrieves thumbnails for each pixelId, and places them in a grid, with White background. Option to add a vertical label to the left of the canvas Creates a PIL ‘Image’ which is returned
- Parameters
thumbnail_store – The omero thumbnail store.
length – Length of longest thumbnail side, int
spacing – The spacing between thumbnails and around the edges. int
pixel_ids – List of pixel IDs. [long]
col_count – The number of columns. int
bg – Background colour as (r,g,b). Default is white (255, 255, 255)
left_label – Optional string to display vertically to the left.
text_color – The color of the text as (r,g,b). Default is black (0, 0, 0)
fontsize – Size of the font. Default is calculated based on thumbnail length, int
- Returns
The PIL Image canvas.
- Thumbnail_Figure.paste_image(image, canvas, x, y)
Pastes the image onto the canvas at the specified coordinates Image and canvas are instances of PIL ‘Image’
- Parameters
image – The PIL image to be pasted. Image
canvas – The PIL image on which to paste. Image
x – X coordinate (left) to paste
y – Y coordinate (top) to paste
- Thumbnail_Figure.run_script()
The main entry point of the script. Gets the parameters from the scripting service, makes the figure and returns the output to the client. def __init__(self, name, optional = False, out = False, description = None, type = None, min = None, max = None, values = None)