Skip to content

Commit

Permalink
ENH: added initial implementation for python GetPixel method
Browse files Browse the repository at this point in the history
The python implementation of GetPixel does not contain a typed
suffix. Based on the PixelID of the image it chooses the correct
methods to call. Because the return type is not strongly typed the
methods will return the correct type to python.
  • Loading branch information
blowekamp committed Apr 22, 2011
1 parent e3368db commit b821617
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions Wrapping/Python.i
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
// Make __str__ transparent by renaming ToString to __str__
%rename(__str__) ToString;

%rename( __GetPixelAsUInt8__ ) itk::simple::Image::GetPixelAsUInt8;
%rename( __GetPixelAsInt16__ ) itk::simple::Image::GetPixelAsInt16;
%rename( __GetPixelAsUInt16__ ) itk::simple::Image::GetPixelAsUInt16;
%rename( __GetPixelAsInt32__ ) itk::simple::Image::GetPixelAsInt32;
%rename( __GetPixelAsUInt32__ ) itk::simple::Image::GetPixelAsUInt32;
%rename( __GetPixelAsFloat__ ) itk::simple::Image::GetPixelAsFloat;
%rename( __GetPixelAsDouble__ ) itk::simple::Image::GetPixelAsDouble;


%extend itk::simple::Image {


// def __floordiv__( other )
// def __pow__( double s )
// def __neg__( )
Expand Down Expand Up @@ -40,9 +49,53 @@
def __xor__( self, other ): return Xor( self, other )
def __invert__( self ): return Not( self )

%}
def GetPixel(self, x, y, z ):
pixelID = self.GetPixelIDValue()
if pixelID == sitkUnknown:
raise Exception("Logic Error: invalid pixel type")
if pixelID == sitkUInt8 || pixelID == sitkLabelUInt8:
return self.__GetPixelAsUInt8__( [ x, y, z ] )
if pixelID == sitkInt16:
return self.__GetPixelAsInt16__( [ x, y, z ] )
if pixelID == sitkUInt16 || pixelID == sitkLabelUInt16:
return self.__GetPixelAsUInt16__( [ x, y, z ] )
if pixelID == sitkInt32:
return self.__GetPixelAsInt32__( [ x, y, z ] )
if pixelID == sitkUInt32 || pixelID == sitkLabelUInt32:
return self.__GetPixelAsUInt32__( [ x, y, z ] )
if pixelID == sitkFloat32:
return self.__GetPixelAsFloat__( [ x, y, z ] )
if pixelID == sitkFloat64:
return self.__GetPixelAsDouble__( [ x, y, z ] )

raise Exception("Unknown pixel type")


def GetPixel(self, x, y):
pixelID = self.GetPixelIDValue()
if pixelID == sitkUnknown:
raise Exception("Logic Error: invalid pixel type")
if pixelID == sitkUInt8 || pixelID == sitkLabelUInt8:
return self.__GetPixelAsUInt8__( [ x, y ] )
if pixelID == sitkInt16:
return self.__GetPixelAsInt16__( [ x, y ] )
if pixelID == sitkUInt16 || pixelID == sitkLabelUInt16:
return self.__GetPixelAsUInt16__( [ x, y ] )
if pixelID == sitkInt32:
return self.__GetPixelAsInt32__( [ x, y ] )
if pixelID == sitkUInt32 || pixelID == sitkLabelUInt32:
return self.__GetPixelAsUInt32__( [ x, y ] )
if pixelID == sitkFloat32:
return self.__GetPixelAsFloat__( [ x, y ] )
if pixelID == sitkFloat64:
return self.__GetPixelAsDouble__( [ x, y ] )

raise Exception("Unknown pixel type")

%}




};


Expand Down

0 comments on commit b821617

Please sign in to comment.