Esempio n. 1
0
    self.expose("UpperThreshold", "Radius")
    self.append(itk.CastImageFilter[DistanceMapType, ImageType].New(self.filters[0].GetVoronoiMap()))
    self.connect(itk.MaskImageFilter[ImageType, ImageType, ImageType].New(Input2=self.filters[1]))

    # now we can parse the inputs
    itk.set_inputs(self, args, kargs)

  def check_template_parameters(template_parameters):
    ImageType, DistanceMapType = template_parameters
    itk.DanielssonDistanceMapImageFilter[ImageType, DistanceMapType]
    itk.BinaryThresholdImageFilter[DistanceMapType, ImageType]
    itk.CastImageFilter[DistanceMapType, ImageType]
    itk.MaskImageFilter[ImageType, ImageType, ImageType]
  check_template_parameters = staticmethod(check_template_parameters)

LabelDilateImageFilter = itk.templated_class(LabelDilateImageFilter)


# and use it
dim = 2
IType = itk.Image[itk.US, dim]
OIType = itk.Image[itk.UC, dim]
DIType = itk.Image[itk.F, dim]

reader = itk.ImageFileReader[IType].New( FileName=argv[1] )
dilate = LabelDilateImageFilter[IType, DIType].New(reader, Radius=eval(argv[3]))
cast = itk.CastImageFilter[IType, OIType].New(dilate)
writer = itk.ImageFileWriter[OIType].New( cast, FileName=argv[2] )

writer.Update()
Esempio n. 2
0
        self.append(itk.MaskImageFilter[ImageType, ImageType, ImageType].New(
            self.filters[0].GetVoronoiMap(), Input2=self.filters[1]))

        # now we can parse the inputs
        itk.set_inputs(self, args, kargs)

    def check_template_parameters(template_parameters):
        ImageType, DistanceMapType = template_parameters
        itk.DanielssonDistanceMapImageFilter[ImageType, DistanceMapType]
        itk.BinaryThresholdImageFilter[DistanceMapType, ImageType]
        itk.CastImageFilter[DistanceMapType, ImageType]
        itk.MaskImageFilter[ImageType, ImageType, ImageType]

    check_template_parameters = staticmethod(check_template_parameters)


LabelDilateImageFilter = itk.templated_class(LabelDilateImageFilter)

# and use it
dim = 2
IType = itk.Image[itk.UC, dim]
OIType = itk.Image[itk.UC, dim]
DIType = itk.Image[itk.F, dim]

reader = itk.ImageFileReader[IType].New(FileName=argv[1])
val = argv[3]
dilate = LabelDilateImageFilter[IType, DIType].New(reader, Radius=eval(val))
writer = itk.ImageFileWriter[OIType].New(dilate, FileName=argv[2])

writer.Update()
Esempio n. 3
0
    self.connect(itk.CastImageFilter[ImageType, ImageType].New(InPlace=False))
    # dilate the objects in the input image
    self.connect(itk.BinaryThresholdImageFilter[ImageType, ImageType].New(LowerThreshold=0, UpperThreshold=0, InsideValue=0, OutsideValue=maxValue))
    self.connect(itk.BinaryDilateImageFilter[ImageType, ImageType, itk.FlatStructuringElement[dim]].New())
    self.expose("Kernel")
    self.expose("Radius")
    # compute the voronoi map and cast it to a usable image type
    self.append(itk.DanielssonDistanceMapImageFilter[ImageType, DistanceMapType].New(self.filters[0], UseImageSpacing=True, SquaredDistance=False))
    self.append(itk.CastImageFilter[DistanceMapType, ImageType].New(self.filters[-1].GetVoronoiMap()))
    # and mask the voronoi map with the dilated objects
    self.connect(itk.MaskImageFilter[ImageType, ImageType, ImageType].New(Input2=self.filters[2]))
    
    # now we can parse the inputs
    itk.set_inputs(self, args, kargs)

ClosestLabelDilateImageFilter = itk.templated_class(ClosestLabelDilateImageFilter)
ClosestLabelDilateImageFilter.add_image_templates(itk.INTS, itk.REALS)


class ClosestDilateLabelMapFilter(itk.pipeline):
  def __init__(self, *args, **kargs):
    # call the constructor of the superclass but without args and kargs, because the attributes
    # are not all already there!
    # Set/GetRadius() is created in the constructor for example, with the expose() method
    itk.pipeline.__init__(self)
    
    # get the template parameters
    template_parameters = kargs["template_parameters"]
    
    # and store them in an easier way
    ImageType, DistanceMapType = template_parameters