예제 #1
0
    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"]
        # check the template parameters validity. Not really useful in that
        # case, because we do the same here, but a good habit
        LabelDilateImageFilter.check_template_parameters(template_parameters)

        # and store them in an easier way
        ImageType, DistanceMapType = template_parameters

        # build the minipipeline
        self.connect(
            itk.DanielssonDistanceMapImageFilter[ImageType,
                                                 DistanceMapType].New(
                                                     UseImageSpacing=True,
                                                     SquaredDistance=False))
        self.connect(itk.BinaryThresholdImageFilter[DistanceMapType,
                                                    ImageType].New())
        self.expose("UpperThreshold", "Radius")
        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)
예제 #2
0
    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"]
        # check the template parameters validity. Not really useful in that
        # case, because we do the same here, but a good habit
        LabelDilateImageFilter.check_template_parameters(template_parameters)

        # and store them in an easier way
        ImageType, DistanceMapType = template_parameters

        # build the minipipeline
        self.connect(
            itk.DanielssonDistanceMapImageFilter[
                ImageType,
                DistanceMapType].New(
                UseImageSpacing=True,
                SquaredDistance=False))
        self.connect(
            itk.BinaryThresholdImageFilter[DistanceMapType,
                                           ImageType].New())
        self.expose("UpperThreshold", "Radius")
        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)
예제 #3
0
 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
   # the maximum value of the image type
   PixelType, dim = itk.template(ImageType)[1]
   maxValue = itk.NumericTraits[PixelType].max()
   # build the minipipeline
   # use a cast filter to dispatch the input image
   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)
예제 #4
0
def New(self, *args, **kargs):
    import itk

    itk.set_inputs(self, args, kargs)

    # now, try to add observer to display progress
    if "auto_progress" in kargs.keys():
        if kargs["auto_progress"] in [True, 1]:
            callback = itk.terminal_progress_callback
        elif kargs["auto_progress"] == 2:
            callback = itk.simple_progress_callback
        else:
            callback = None
    elif itkConfig.ProgressCallback:
        callback = itkConfig.ProgressCallback
    else:
        callback = None

    if callback and not issubclass(self.__class__, itk.Command):
        try:
            name = self.__class__.__name__

            def progress():
                # self and callback are kept referenced with a closure
                callback(name, self.GetProgress())

            self.AddObserver(itk.ProgressEvent(), progress)
        except AttributeError:
            # as this feature is designed for prototyping, it's not really a
            # problem if an object doesn't have progress reporter, so adding
            # reporter can silently fail
            pass
        except Exception:
            # it seems that something else has gone wrong...
            # silently fail to maintain backward compatibility
            pass

    if itkConfig.NotInPlace and "SetInPlace" in dir(self):
        self.SetInPlace(False)

    if itk.auto_pipeline.current is not None:
        itk.auto_pipeline.current.connect(self)

    return self
예제 #5
0
파일: itkTemplate.py 프로젝트: Niner10/ITK
def New(self, *args, **kargs):
    import sys
    import itk

    itk.set_inputs(self, args, kargs)

    # now, try to add observer to display progress
    if "auto_progress" in kargs.keys():
        if kargs["auto_progress"] in [True, 1]:
            callback = itk.terminal_progress_callback
        elif kargs["auto_progress"] == 2:
            callback = itk.simple_progress_callback
        else:
            callback = None
    elif itkConfig.ProgressCallback:
        callback = itkConfig.ProgressCallback
    else:
        callback = None

    if callback:
        try:
            name = self.__class__.__name__

            def progress():
                # self and callback are kept referenced with a closure
                callback(name, self.GetProgress())

            self.AddObserver(itk.ProgressEvent(), progress)
        except:
            # it seems that something goes wrong...
            # as this feature is designed for prototyping, it's not really a
            # problem if an object doesn't have progress reporter, so adding
            # reporter can silently fail
            pass

    if itkConfig.NotInPlace and "SetInPlace" in dir(self):
        self.SetInPlace(False)

    if itk.auto_pipeline.current is not None:
        itk.auto_pipeline.current.connect(self)

    return self
예제 #6
0
def New(self, *args, **kargs):
    import sys, itk

    itk.set_inputs(self, args, kargs)

    # now, try to add observer to display progress
    if "auto_progress" in kargs.keys():
        if kargs["auto_progress"] in [True, 1]:
            callback = itk.terminal_progress_callback
        elif kargs["auto_progress"] == 2:
            callback = itk.simple_progress_callback
        else:
            callback = None
    elif itkConfig.ProgressCallback:
        callback = itkConfig.ProgressCallback
    else:
        callback = None

    if callback:
        try:
            name = self.__class__.__name__

            def progress():
                # self and callback are kept referenced with a closure
                callback(name, self.GetProgress())

            self.AddObserver(itk.ProgressEvent(), progress)
        except:
            # it seems that something goes wrong...
            # as this feature is designed for prototyping, it's not really a problem
            # if an object  don't have progress reporter, so adding reporter can silently fail
            pass

    if itkConfig.NotInPlace and "SetInPlace" in dir(self):
        self.SetInPlace(False)

    if itk.auto_pipeline.current != None:
        itk.auto_pipeline.current.connect(self)

    return self
예제 #7
0
 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
   # the maximum value of the image type
   PixelType, dim = itk.template(ImageType)[1]
   LabelMapType = itk.LabelMap[itk.StatisticsLabelObject[itk.UL, dim]]
   # build the minipipeline
   self.connect(itk.LabelMapToLabelImageFilter[LabelMapType, ImageType].New())
   self.connect(ClosestLabelDilateImageFilter[ImageType, DistanceMapType].New())
   self.expose("Kernel")
   self.expose("Radius")
   self.connect(itk.LabelImageToLabelMapFilter[ImageType, LabelMapType].New())
   
   # now we can parse the inputs
   itk.set_inputs(self, args, kargs)