Package omero :: Package util :: Module imageUtil
[hide private]
[frames] | no frames]

Module imageUtil

source code


 components/tools/OmeroPy/src/omero/util/imageUitl.py

-----------------------------------------------------------------------------
  Copyright (C) 2006-2009 University of Dundee. All rights reserved.


  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

------------------------------------------------------------------------------

A collection of utility methods based on the Python Imaging Library (PIL)
used for making figures. 

@author  William Moore     
<a href="mailto:will@lifesci.dundee.ac.uk">will@lifesci.dundee.ac.uk</a>
@author  Jean-Marie Burel &nbsp;&nbsp;&nbsp;&nbsp;
<a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
@author Donald MacDonald &nbsp;&nbsp;&nbsp;&nbsp;
<a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a>
@version 3.0
<small>
(<b>Internal version:</b> $Revision: $Date: $)
</small>
@since 3.0-Beta4.1
 

Functions [hide private]
 
getFont(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
source code
 
pasteImage(image, canvas, x, y)
Pastes the image onto the canvas at the specified coordinates Image and canvas are instances of PIL 'Image'
source code
 
getThumbnail(thumbnailStore, pixelsId, length)
Returns a thumbnail (as string) from the pixelsId, the longest side is 'length'
source code
 
getThumbnailSet(thumbnailStore, length, pixelIds)
Returns map of thumbnails whose keys are the pixels id and the values are the image, the longest side is 'length'
source code
 
paintThumbnailGrid(thumbnailStore, length, spacing, pixelIds, colCount, bg=(255,255,255), leftLabel=None, textColour=(0,0,0), fontsize=None)
Retrieves thumbnails for each pixelId, and places them in a grid, with White background.
source code
 
checkRGBRange(value)
Checks that the value is between 0 and 255.
source code
 
RGBIntToRGBA(RGB)
Returns a tuple of (r,g,b,a) from an integer colour r, g, b, a are 0-255.
source code
 
RGBIntToRGB(RGB)
Returns a tuple of (r,g,b) from an integer colour r, g, b are 0-255.
source code
 
getZoomFactor(imageSize, maxW, maxH)
Returns the factor by which the Image has to be shrunk so that it's dimensions are less that maxW and maxH E.g.
source code
 
resizeImage(image, maxW, maxH)
Resize the image so that it is as big as possible, within the dimensions maxW, maxH
source code
Variables [hide private]
  GATEWAYPATH = os.path.dirname(os.path.abspath(__file__))

Imports: Image, ImageDraw, ImageFont, os, omero, StringIO


Function Details [hide private]

getFont(fontsize)

source code 

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

pasteImage(image, canvas, x, y)

source code 

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

getThumbnail(thumbnailStore, pixelsId, length)

source code 

Returns a thumbnail (as string) from the pixelsId, the longest side is 'length'

Parameters:
  • thumbnailStore - The Omero thumbnail store
  • pixelsId - The ID of the pixels. long
  • length - Length of longest side. int
Returns:
The thumbnail as a String, or None if not found (invalid image)

getThumbnailSet(thumbnailStore, length, pixelIds)

source code 

Returns map of thumbnails whose keys are the pixels id and the values are the image, the longest side is 'length'

Parameters:
  • thumbnailStore - The Omero thumbnail store
  • pixelIds - The collection of pixels ID.
  • length - Length of longest side. int
Returns:
See above

paintThumbnailGrid(thumbnailStore, length, spacing, pixelIds, colCount, bg=(255,255,255), leftLabel=None, textColour=(0,0,0), fontsize=None)

source code 

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:
  • thumbnailStore - The omero thumbnail store.
  • length - Length of longest thumbnail side. int
  • spacing - The spacing between thumbnails and around the edges. int
  • pixelIds - List of pixel IDs. [long]
  • colCount - The number of columns. int
  • bg - Background colour as (r,g,b). Default is white (255,255,255)
  • leftLabel - Optional string to display vertically to the left.
  • textColour - The colour of the text as (r,g,b). Default is black (0,0,0)
  • fontsize - Size of the font. Defualt is calculated based on thumbnail length. int
Returns:
The PIL Image canvas.

checkRGBRange(value)

source code 

Checks that the value is between 0 and 255. Returns integer value If the value is not valid, return 255 (better to see something than nothing! )

Parameters:
  • value - The value to check.
Returns:
An integer between 0 and 255

RGBIntToRGBA(RGB)

source code 

Returns a tuple of (r,g,b,a) from an integer colour r, g, b, a are 0-255.

Parameters:
  • RGB - A colour as integer. Int
Returns:
A tuple of (r,g,b,a)

RGBIntToRGB(RGB)

source code 

Returns a tuple of (r,g,b) from an integer colour r, g, b are 0-255.

Parameters:
  • RGB - A colour as integer. Int
Returns:
A tuple of (r,g,b)

getZoomFactor(imageSize, maxW, maxH)

source code 

Returns the factor by which the Image has to be shrunk so that it's dimensions are less that maxW and maxH E.g. If the image must be half-sized, this method returns 2.0 (float)

Parameters:
  • imageSize - Size of the image as tuple (width, height)
  • maxW - The max width after zooming
  • maxH - The max height after zooming
Returns:
The factor by which to shrink the image to be within max width and height

resizeImage(image, maxW, maxH)

source code 

Resize the image so that it is as big as possible, within the dimensions maxW, maxH

Parameters:
  • image - The PIL Image to zoom
  • maxW - The max width of the zoomed image
  • maxH - The max height of the zoomed image
Returns:
The zoomed image. PIL Image.