예제 #1
0
  def SetInput(self, input) :
    img = image(input)
    self.__input__ = img
    if img :
      # Update to try to avoid to exit if a c++ exception is throwed
      # sadely, it will not prevent the program to exit later...
      # a real fix would be to wrap c++ exception in vtk
      img.UpdateOutputInformation()
      img.Update()
      import itk
      self.__flipper__ = itk.FlipImageFilter[img].New(Input=img)
      axes = self.__flipper__.GetFlipAxes()
      axes.SetElement(1, True)
      self.__flipper__.SetFlipAxes(axes)
      self.__itkvtkConverter__ = itk.ImageToVTKImageFilter[img].New(self.__flipper__)
      self.__volumeMapper__.SetInput(self.__itkvtkConverter__.GetOutput())
      # needed to avoid warnings
      # self.__itkvtkConverter__.GetOutput() must be callable
      import vtk
      if not self.__outline__ :
	  self.__outline__ = vtk.vtkOutlineFilter()
	  self.__outline__.SetInput(self.__itkvtkConverter__.GetOutput())
	  self.__outlineMapper__ = vtk.vtkPolyDataMapper()
	  self.__outlineMapper__.SetInput(self.__outline__.GetOutput())
	  self.__outlineActor__ = vtk.vtkActor()
	  self.__outlineActor__.SetMapper(self.__outlineMapper__)
	  self.__ren__.AddActor(self.__outlineActor__)
      else :
	  self.__outline__.SetInput(self.__itkvtkConverter__.GetOutput())

    self.Render()
예제 #2
0
def show(input, **kargs) :
    img = image(input)
    if img.GetImageDimension() == 3:
	return show3D(input, **kargs)
    else :
	# print "2D not supported yet, use the 3D viewer."
	return show2D(input, **kargs)
예제 #3
0
def range(imageOrFilter) :
  import itk
  img = image(imageOrFilter)
  img.UpdateOutputInformation()
  img.Update()
  comp = itk.MinimumMaximumImageCalculator[img].New(Image=img)
  comp.Compute()
  return (comp.GetMinimum(), comp.GetMaximum())
예제 #4
0
def origin(imageOrFilter):
    """Return the origin of an image, or of the output image of a filter
  
  This method take care of updating the needed informations
  """
    # we don't need the entire output, only its size
    imageOrFilter.UpdateOutputInformation()
    img = image(imageOrFilter)
    return img.GetOrigin()
예제 #5
0
파일: __init__.py 프로젝트: axel971/itk
def index(imageOrFilter) :
  """Return the index of an image, or of the output image of a filter
  
  This method take care of updating the needed informations
  """
  # we don't need the entire output, only its size
  imageOrFilter.UpdateOutputInformation()
  img = image(imageOrFilter)
  return img.GetLargestPossibleRegion().GetIndex()
예제 #6
0
def index(imageOrFilter):
    """Return the index of an image, or of the output image of a filter
  
  This method take care of updating the needed informations
  """
    # we don't need the entire output, only its size
    imageOrFilter.UpdateOutputInformation()
    img = image(imageOrFilter)
    return img.GetLargestPossibleRegion().GetIndex()
예제 #7
0
파일: __init__.py 프로젝트: axel971/itk
def origin(imageOrFilter) :
  """Return the origin of an image, or of the output image of a filter
  
  This method take care of updating the needed informations
  """
  # we don't need the entire output, only its size
  imageOrFilter.UpdateOutputInformation()
  img = image(imageOrFilter)
  return img.GetOrigin()
예제 #8
0
파일: __init__.py 프로젝트: axel971/itk
def show(input, **kargs) :
  """display an image
  """
  import itk
  img = image(input)
  if img.GetImageDimension() == 3 and "show3D" in dir(itk):
	  return itk.show3D(input, **kargs)
  else :
	  # print "2D not supported yet, use the 3D viewer."
	  return show2D(input, **kargs)
예제 #9
0
def show(input, **kargs):
    """display an image
  """
    import itk
    img = image(input)
    if img.GetImageDimension() == 3 and "show3D" in dir(itk):
        return itk.show3D(input, **kargs)
    else:
        # print "2D not supported yet, use the 3D viewer."
        return show2D(input, **kargs)
예제 #10
0
파일: __init__.py 프로젝트: axel971/itk
def write(imageOrFilter, fileName, compression=False):
  """Write a image or the output image of a filter to filename
  
  The writer is instantiated with the image type of the image in
  parameter (or, again, with the output image of the filter in parameter)
  """
  import itk
  img = image(imageOrFilter)
  img.UpdateOutputInformation()
  writer = itk.ImageFileWriter[img].New(Input=img, FileName=fileName, UseCompression=compression)
  writer.Update()
예제 #11
0
파일: __init__.py 프로젝트: axel971/itk
def range(imageOrFilter) :
  """Return the range of values in a image of in the output image of a filter
  
  The minimum and maximum values are returned in a tuple: (min, max)
  range() take care of updating the pipeline
  """
  import itk
  img = image(imageOrFilter)
  img.UpdateOutputInformation()
  img.Update()
  comp = itk.MinimumMaximumImageCalculator[img].New(Image=img)
  comp.Compute()
  return (comp.GetMinimum(), comp.GetMaximum())
예제 #12
0
def range(imageOrFilter):
    """Return the range of values in a image of in the output image of a filter
  
  The minimum and maximum values are returned in a tuple: (min, max)
  range() take care of updating the pipeline
  """
    import itk
    img = image(imageOrFilter)
    img.UpdateOutputInformation()
    img.Update()
    comp = itk.MinimumMaximumImageCalculator[img].New(Image=img)
    comp.Compute()
    return (comp.GetMinimum(), comp.GetMaximum())
예제 #13
0
def write(imageOrFilter, fileName, compression=False):
    """Write a image or the output image of a filter to filename
  
  The writer is instantiated with the image type of the image in
  parameter (or, again, with the output image of the filter in parameter)
  """
    import itk
    img = image(imageOrFilter)
    img.UpdateOutputInformation()
    writer = itk.ImageFileWriter[img].New(Input=img,
                                          FileName=fileName,
                                          UseCompression=compression)
    writer.Update()
예제 #14
0
파일: __init__.py 프로젝트: axel971/itk
def physical_point_to_index( imageOrFilter, p ):
  """Get the index in an image from the physical point
  
  image is the image where the physical point must be computed
  p is the point used to compute the index
  """
  from __builtin__ import range # required because range is overladed in this module
  # get the image if needed
  img = image( imageOrFilter )
  dim = img.GetImageDimension()
  o = origin( img )
  s = spacing( img )
  
  # use the typemaps to really get a point
  import itk
  p = itk.Point[ itk.D, dim ]( p )
  
  # create the output object
  idx = itk.Index[ dim ]()
  for i in range( 0, dim ):
    idx.SetElement( i, int( round( ( p.GetElement(i) - o.GetElement(i) ) / s.GetElement(i) ) ) )
  return idx
예제 #15
0
파일: __init__.py 프로젝트: axel971/itk
def index_to_physical_point( imageOrFilter, idx ):
  """Get the pysical point in an image from an index
  
  imageOrFilter is the image where the physical point must be computed
  idx is the index used to compute the physical point. It can be a continuous index.
  """
  from __builtin__ import range # required because range is overladed in this module
  # get the image if needed
  img = image( imageOrFilter )
  dim = img.GetImageDimension()
  o = origin( img )
  s = spacing( img )
  
  # use the typemaps to really get a continuous index
  import itk
  idx = itk.ContinuousIndex[ itk.D, dim ]( idx )
  
  # create the output object
  p = itk.Point[ itk.D, dim ]()
  for i in range( 0, dim ):
    p.SetElement( i, s.GetElement(i) * idx.GetElement(i) + o.GetElement(i) )
  return p
예제 #16
0
def index_to_physical_point(imageOrFilter, idx):
    """Get the pysical point in an image from an index
  
  imageOrFilter is the image where the physical point must be computed
  idx is the index used to compute the physical point. It can be a continuous index.
  """
    from __builtin__ import range  # required because range is overladed in this module
    # get the image if needed
    img = image(imageOrFilter)
    dim = img.GetImageDimension()
    o = origin(img)
    s = spacing(img)

    # use the typemaps to really get a continuous index
    import itk
    idx = itk.ContinuousIndex[itk.D, dim](idx)

    # create the output object
    p = itk.Point[itk.D, dim]()
    for i in range(0, dim):
        p.SetElement(i, s.GetElement(i) * idx.GetElement(i) + o.GetElement(i))
    return p
예제 #17
0
def physical_point_to_continuous_index(imageOrFilter, p):
    """Get the continuous index in an image from the physical point
  
  imageOrFilter is the image where the physical point must be computed
  p is the point used to compute the index
  """
    from __builtin__ import range  # required because range is overladed in this module
    # get the image if needed
    img = image(imageOrFilter)
    dim = img.GetImageDimension()
    o = origin(img)
    s = spacing(img)

    # use the typemaps to really get a point
    import itk
    p = itk.Point[itk.D, dim](p)

    # create the output object
    idx = itk.ContinuousIndex[itk.D, dim]()
    for i in range(0, dim):
        idx.SetElement(i,
                       (p.GetElement(i) - o.GetElement(i)) / s.GetElement(i))
    return idx
예제 #18
0
def index(imageOrFilter) :
  # we don't need the entire output, only its size
  imageOrFilter.UpdateOutputInformation()
  img = image(imageOrFilter)
  return img.GetLargestPossibleRegion().GetIndex()
예제 #19
0
def write(imageOrFilter, fileName):
  import itk
  img = image(imageOrFilter)
  img.UpdateOutputInformation()
  writer = itk.ImageFileWriter[img].New(Input=img, FileName=fileName)
  writer.Update()