Example #1
0
    def __call__(
        self,
        image,
        window_size=10,
        threshold=0,
        fill_holes=True,
        remove_borderobjects=True,
        outline_smoothing=0,
        use_watershed=False,
        seeding_size=8,
        *args,
        **kw
    ):
        """Local adaptive threshold segmentation using a gaussian Kernel"""

        thresh = adaptive_threshold(image, window_size, threshold)

        if fill_holes:
            thresh = ndi.morphology.binary_fill_holes(thresh)

        # object don't touch border after outline smoothing
        if remove_borderobjects:
            thresh = clear_border(thresh)

        if outline_smoothing >= 1:
            thresh = outlineSmoothing(thresh, outline_smoothing)

        if use_watershed:
            label_image = watershed(thresh, seeding_size=seeding_size)
        else:
            label_image = ndi.label(thresh)[0]

        return label_image
Example #2
0
    def threshold(self, image, median_radius, window_size, min_contrast,
                  remove_borderobjects, fill_holes, norm_min=0, norm_max=255,
                  use_watershed=True, seeding_size=5, outline_smoothing=1,
                  *args, **kw):

        image = self.normalize(image, norm_min, norm_max)
        image = ccore.numpy_to_image(image, copy=True)

        image_smoothed = ccore.gaussianFilter(image, median_radius)

        label_image = ccore.window_average_threshold(
            image_smoothed, window_size, min_contrast)

        if fill_holes:
            ccore.fill_holes(label_image)

        if outline_smoothing >= 1:
            label_image = outlineSmoothing(label_image.toArray(),
                                           outline_smoothing)
            label_image = ccore.numpy_to_image(label_image, copy=True)


        if use_watershed:
            label_image = label_image.toArray().copy()
            label_image = watershed(label_image, seeding_size=seeding_size)
            label_image = ccore.numpy_to_image(
                label_image.astype(np.int16), copy=True)

            return ccore.ImageMaskContainer(image, label_image,
                                            remove_borderobjects, True, True)
        else:
            # a static type system sucks!
            return ccore.ImageMaskContainer(image, label_image,
                                            remove_borderobjects)
Example #3
0
    def threshold(self,
                  image,
                  median_radius,
                  window_size,
                  min_contrast,
                  remove_borderobjects,
                  fill_holes,
                  norm_min=0,
                  norm_max=255,
                  use_watershed=True,
                  seeding_size=5,
                  outline_smoothing=1,
                  *args,
                  **kw):

        image = self.normalize(image, norm_min, norm_max)
        image = ccore.numpy_to_image(image, copy=True)

        image_smoothed = ccore.gaussianFilter(image, median_radius)

        label_image = ccore.window_average_threshold(image_smoothed,
                                                     window_size, min_contrast)

        if fill_holes:
            ccore.fill_holes(label_image)

        if outline_smoothing >= 1:
            label_image = outlineSmoothing(label_image.toArray(),
                                           outline_smoothing)
            label_image = ccore.numpy_to_image(label_image, copy=True)

        if use_watershed:
            label_image = label_image.toArray().copy()
            label_image = watershed(label_image, seeding_size=seeding_size)
            label_image = ccore.numpy_to_image(label_image.astype(np.int16),
                                               copy=True)

            return ccore.ImageMaskContainer(image, label_image,
                                            remove_borderobjects, True, True)
        else:
            # a static type system sucks!
            return ccore.ImageMaskContainer(image, label_image,
                                            remove_borderobjects)