Morphological erosion - difference between betwen Scipy ndimage and Scikit image

morphology operators differ in the pattern of Scipy ndimage and Scikit. I believe that the boundary conditions are interpreted differently:

import numpy as np
from scipy import ndimage
from skimage import morphology

scp = ndimage.binary_erosion(np.ones((10,10),dtype="uint8"),).astype("uint8")
sci = morphology.binary_erosion(np.ones((10,10),dtype="uint8"),morphology.disk(1))

scp, as expected, but sci does not:

>>>> scp
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

>>>> sci
array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=uint8)

How to establish a boundary condition in the operations of morphology of scikit images?

Regards

+4
source share
1 answer

Well, this is not about the border_value parameter. I found in skimage / morphology / binary.py:

import numpy as np
from scipy import ndimage

def binary_erosion(image, selem, out=None):
    conv = ndimage.convolve(image > 0, selem, output=out,
                            mode='constant', cval=1) <---Here!
    if conv is not None:
        out = conv
    return np.equal(out, np.sum(selem), out=out)

From the Scipy Reference:

scipy.ndimage.filters.convolve (input, weight, output = None, mode = 'reflect', cval = 0.0, origin = 0):

: {', , , ,' wrap}, mode , . " " cval. - "". cval: scalar, optional , "". 0.0 < ----- !

!

+1

All Articles