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

Source Code for Module omero.util.pixelstypetopython

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