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

Source Code for Module omero.util.pixelstypetopython

  1  #!/usr/bin/python 
  2  # 
  3  #------------------------------------------------------------------------------ 
  4  #  Copyright (C) 2006-2008 University of Dundee. All rights reserved. 
  5  # 
  6  # 
  7  #       This program is free software; you can redistribute it and/or modify 
  8  #  it under the terms of the GNU General Public License as published by 
  9  #  the Free Software Foundation; either version 2 of the License, or 
 10  #  (at your option) any later version. 
 11  #  This program is distributed in the hope that it will be useful, 
 12  #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  #  GNU General Public License for more details. 
 15  #   
 16  #  You should have received a copy of the GNU General Public License along 
 17  #  with this program; if not, write to the Free Software Foundation, Inc., 
 18  #  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 19  # 
 20  #------------------------------------------------------------------------------ 
 21  # 
 22  # The Pixels object in omero, has a member pixelsType, this can be  
 23  #       INT_8 = "int8"; 
 24  #       UINT_8 = "uint8"; 
 25  #       INT_16 = "int16"; 
 26  #       UINT_16 = "uint16"; 
 27  #       INT_32 = "int32"; 
 28  #       UINT_32 = "uint32"; 
 29  #       FLOAT = "float"; 
 30  #       DOUBLE = "double"; 
 31  # we can convert these to the appropriate types in python.       
 32   
 33  INT_8 = "int8" 
 34  UINT_8 = "uint8" 
 35  INT_16 = "int16" 
 36  UINT_16 = "uint16" 
 37  INT_32 = "int32" 
 38  UINT_32 = "uint32" 
 39  FLOAT = "float" 
 40  DOUBLE = "double" 
 41   
42 -def toPython(pixelType):
43 if(pixelType==INT_8): 44 return 'b' 45 if(pixelType==UINT_8): 46 return 'B' 47 if(pixelType==INT_16): 48 return 'h' 49 if(pixelType==UINT_16): 50 return 'H' 51 if(pixelType==INT_32): 52 return 'i' 53 if(pixelType==UINT_32): 54 return 'I' 55 if(pixelType==FLOAT): 56 return 'f' 57 if(pixelType==DOUBLE): 58 return 'd'
59
60 -def toNumpy(pixelType):
61 import numpy 62 if(pixelType==INT_8): 63 return numpy.int8 64 if(pixelType==UINT_8): 65 return numpy.uint8 66 if(pixelType==INT_16): 67 return numpy.int16 68 if(pixelType==UINT_16): 69 return numpy.uint16 70 if(pixelType==INT_32): 71 return numpy.int32 72 if(pixelType==UINT_32): 73 return numpy.uint32 74 if(pixelType==FLOAT): 75 return numpy.float 76 if(pixelType==DOUBLE): 77 return numpy.double
78
79 -def toArray(pixelType):
80 if(pixelType==INT_8): 81 return 'b' 82 if(pixelType==UINT_8): 83 return 'B' 84 if(pixelType==INT_16): 85 return 'i2' 86 if(pixelType==UINT_16): 87 return 'H2' 88 if(pixelType==INT_32): 89 return 'i4' 90 if(pixelType==UINT_32): 91 return 'I4' 92 if(pixelType==FLOAT): 93 return 'f' 94 if(pixelType==DOUBLE): 95 return 'd'
96
97 -def toPIL(pixelType):
98 if(pixelType==INT_8): 99 return 'L' 100 if(pixelType==UINT_8): 101 return 'L' 102 if(pixelType==INT_16): 103 return 'I;16' 104 if(pixelType==UINT_16): 105 return 'I;16' 106 if(pixelType==INT_32): 107 return 'I' 108 if(pixelType==UINT_32): 109 return 'I' 110 if(pixelType==FLOAT): 111 return 'F' 112 if(pixelType==DOUBLE): 113 return 'F'
114