Ejemplo n.º 1
0
    def _run(self, meta_image, container_prim, container_sec):
        image = meta_image.image
        if not self.params['reverse']:
            img_labels = ccore.substractImages(container_prim.img_labels, container_sec.img_labels)
        else:
            img_labels = ccore.substractImages(container_sec.img_labels, container_prim.img_labels)

        #array = img_labels.toArray()
        #array = numpy.abs(array)
        #img_labels = ccore.numpy_to_image(array, copy=True)
        return ccore.ImageMaskContainer(image, img_labels, False, True, True)
Ejemplo n.º 2
0
    def _run(self, meta_image, container):
        image = meta_image.image
        if self.params['expansion_size'] > 0 or self.params['shrinking_size'] > 0:

            nr_objects = container.img_labels.getMinmax()[1] + 1
            if self.params['shrinking_size'] > 0:
                img_labelsA = ccore.seeded_region_shrinking(image,
                                                            container.img_labels,
                                                            nr_objects,
                                                            self.params['shrinking_size'])
            else:
                img_labelsA = container.img_labels

            if self.params['expansion_size'] > 0:
                img_labelsB = ccore.seeded_region_expansion(image,
                                                            container.img_labels,
                                                            ccore.SrgType.KeepContours,
                                                            nr_objects,
                                                            0,
                                                            self.params['expansion_size'],
                                                            0)
            else:
                img_labelsB = container.img_labels
            img_labels = ccore.substractImages(img_labelsB, img_labelsA)
            return ccore.ImageMaskContainer(image, img_labels, False, True, True)
        else:
            raise ValueError("Parameters are not valid. Requirements: 'expansion_size' > 0 and/or "
                             "'shrinking_size' > 0")
Ejemplo n.º 3
0
    def _run(self, meta_image, container):
        image = meta_image.image
        if self.params['expansion_size'] > 0 or self.params[
                'shrinking_size'] > 0:

            nr_objects = container.img_labels.getMinmax()[1] + 1
            if self.params['shrinking_size'] > 0:
                img_labelsA = ccore.seeded_region_shrinking(
                    image, container.img_labels, nr_objects,
                    self.params['shrinking_size'])
            else:
                img_labelsA = container.img_labels

            if self.params['expansion_size'] > 0:
                img_labelsB = ccore.seeded_region_expansion(
                    image, container.img_labels, ccore.SrgType.KeepContours,
                    nr_objects, 0, self.params['expansion_size'], 0)
            else:
                img_labelsB = container.img_labels
            img_labels = ccore.substractImages(img_labelsB, img_labelsA)
            return ccore.ImageMaskContainer(image, img_labels, False, True,
                                            True)
        else:
            raise ValueError(
                "Parameters are not valid. Requirements: 'expansion_size' > 0 and/or "
                "'shrinking_size' > 0")
Ejemplo n.º 4
0
 def _run(self, meta_image, container):
     image = meta_image.image
     if self.params['expansion_size'] > 0 and self.params['expansion_size'] > self.params['separation_size']:
         nr_objects = container.img_labels.getMinmax()[1] + 1
         img_labels = ccore.seeded_region_expansion(image,
                                                    container.img_labels,
                                                    ccore.SrgType.KeepContours,
                                                    nr_objects,
                                                    0,
                                                    self.params['expansion_size'],
                                                    self.params['separation_size'])
         img_labels = ccore.substractImages(img_labels, container.img_labels)
         return ccore.ImageMaskContainer(image, img_labels, False, True, True)
     else:
         raise ValueError("Parameters are not valid. Requirements: 'expansion_size' > 0 and "
                          "'expansion_size' > 'separation_size'")
Ejemplo n.º 5
0
    def __call__(self, meta_image, container):
        stopwatch_total = StopWatch()
        stopwatch = StopWatch()
        image, width, height = meta_image.image, meta_image.width, meta_image.height
        containers = {}
        iLabelNumber = container.img_labels.getMinmax()[1]+1
        img_prefiltered = image

        # expanded - in case expansion size == 0 original regions are taken
        if 'expanded' in self.lstAreaSelection:
            stopwatch.reset()
            if self.iExpansionSizeExpanded > 0:
                imgLabelsOut = ccore.seeded_region_expansion(img_prefiltered,
                                                             container.img_labels,
                                                             ccore.SrgType.KeepContours,
                                                             iLabelNumber,
                                                             self.fExpansionCostThreshold,
                                                             self.iExpansionSizeExpanded,
                                                             0
                                                             )
            else:
                imgLabelsOut = container.img_labels
            containers['expanded'] =\
                ccore.ImageMaskContainer(image, imgLabelsOut, False, True, True)
            self._logger.debug("         --- expanded region ok, %s" %
                               stopwatch.current_interval())

        # inside - in case shrinking size == 0 original regions are taken
        if 'inside' in self.lstAreaSelection:
            stopwatch.reset()
            if self.iShrinkingSizeInside > 0:
                imgLabelsOut = ccore.seeded_region_shrinking(img_prefiltered,
                                                             container.img_labels,
                                                             iLabelNumber,
                                                             self.iShrinkingSizeInside
                                                             )
            else:
                imgLabelsOut = container.img_labels
            containers['inside'] =\
                ccore.ImageMaskContainer(image, imgLabelsOut, False, True, True)
            self._logger.debug("         --- inside region ok, %s" %
                               stopwatch.current_interval())

        # outside - expansion size > 0 AND expansion > separation size needed,
        # otherwise area is 0
        if ('outside' in self.lstAreaSelection
             and self.iExpansionSizeOutside > 0
             and self.iExpansionSizeOutside > self.iExpansionSeparationSizeOutside):
            stopwatch.reset()
            imgLabelsOut = ccore.seeded_region_expansion(img_prefiltered,
                                                         container.img_labels,
                                                         ccore.SrgType.KeepContours,
                                                         iLabelNumber,
                                                         self.fExpansionCostThreshold,
                                                         self.iExpansionSizeOutside,
                                                         self.iExpansionSeparationSizeOutside,
                                                         )
            imgLabelsOut = ccore.substractImages(imgLabelsOut, container.img_labels)
            containers['outside'] =\
                ccore.ImageMaskContainer(image, imgLabelsOut, False, True, True)
            self._logger.debug("         --- outside region ok, %s" %
                               stopwatch.current_interval())

        # rim - one value > 0 needed, otherwise area is 0
        if ('rim' in self.lstAreaSelection and
            (self.iExpansionSizeRim > 0 or self.iShrinkingSizeRim > 0)):
            stopwatch.reset()
            if self.iShrinkingSizeRim > 0:
                imgLabelsOutA = ccore.seeded_region_shrinking(img_prefiltered,
                                                              container.img_labels,
                                                              iLabelNumber,
                                                              self.iShrinkingSizeRim
                                                              )
            else:
                imgLabelsOutA = container.img_labels
            if self.iExpansionSizeRim > 0:
                imgLabelsOutB = ccore.seeded_region_expansion(img_prefiltered,
                                                              container.img_labels,
                                                              ccore.SrgType.KeepContours,
                                                              iLabelNumber,
                                                              self.fExpansionCostThreshold,
                                                              self.iExpansionSizeRim,
                                                              0
                                                              )
            else:
                imgLabelsOutB = container.img_labels
            imgLabelsOut = ccore.substractImages(imgLabelsOutB, imgLabelsOutA)
            containers['rim'] =\
                ccore.ImageMaskContainer(image, imgLabelsOut, False, True, True)
            self._logger.debug("         --- rim region ok, %s" %
                               stopwatch.current_interval())

        if ('propagate' in self.lstAreaSelection):
            stopwatch.reset()

            if self.iPresegmentationMedianRadius > 0:
                img_prefiltered = ccore.disc_median(image,
                                                    self.iPresegmentationMedianRadius)

            t = int(ccore.get_otsu_threshold(img_prefiltered) *
                    self.fPresegmentationAlpha)
            img_binary = ccore.threshold_image(img_prefiltered, t)

            #self._logger.debug("         --- pre-segmentation ok, %s" %
            #                    stopwatch.current_interval())

            labels_out = ccore.segmentation_propagate(img_prefiltered, img_binary,
                                                      container.img_labels,
                                                      self.fPropagateLambda,
                                                      self.iPropagateDeltaWidth)
            containers['propagate'] =\
                ccore.ImageMaskContainer(image, labels_out, False, True, True)
            self._logger.debug("         --- propagate region ok, %s" %
                               stopwatch.current_interval())

        if ('constrained_watershed' in self.lstAreaSelection):
            labels_out = self.constrainedWatershedApproach(image, container.img_labels,
                                                           iGaussFilterSize=self.iConstrainedWatershedGaussFilterSize)

            containers['constrained_watershed'] =\
                ccore.ImageMaskContainer(image, labels_out, False, True, True)
            self._logger.debug("         --- constrained_watershed region ok, %s",
                               stopwatch.current_interval())


        self._logger.debug("         total time: %s" %
                            stopwatch_total.current_interval())
        return containers