예제 #1
0
파일: threshold.py 프로젝트: rhoef/afw
    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
예제 #2
0
파일: honeycomp.py 프로젝트: rhoef/afw
    def __call__(self, image, window_size=10, threshold=0, fill_holes=True,
                 outline_smoothing=2, remove_borderobjects=True, size_min=1,
                 *args, **kw):

        thresh = threshold_adaptive(image, block_size=window_size,
                                    offset=-1*threshold)

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

        thresh = remove_small_objects(thresh, size_min)

        seeds = ndi.label(clear_border(~thresh))[0]
        thresh = ndi.binary_fill_holes(thresh)
        smask = seeds.astype(bool)

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

        img = np.zeros(thresh.shape)
        img[~smask] = 1
        edt = ndi.morphology.distance_transform_edt(img)
        edt -= ndi.morphology.distance_transform_edt(seeds)

        labels = watershed(edt, seeds)
        labels[smask] = 0
        labels[~thresh] = 0

        return labels