Image erosion and dilation with Scipy

前端 未结 2 1806
广开言路
广开言路 2021-02-19 15:07

I am trying to use scipy to do erosion and dilation of an image. It seems pretty straightforward using scipy -> binary_erosion / dialation. However, the output is n

相关标签:
2条回答
  • 2021-02-19 15:32

    You have two problems: as noted in the comment by @theta, binary ops expect input consisting only of 0 and 1. The second issue is the nd in ndimage --- you supply in an array of shape (nx, ny, 3). The last length-3 axis is considered to be a third spatial dimension, not the three color channels.

    0 讨论(0)
  • 2021-02-19 15:39

    I was using the binary erosion instead of the grey erosion array. I converted the original image to greyscale by using flatten=true like so:

    im = scipy.misc.imread('flower.png', flatten=True).astype(np.uint8)
    

    then called:

    im1 = ndimage.grey_erosion(im, size=(15,15))
    

    And got a nicely eroded picture, although it is greyscale.

    0 讨论(0)
提交回复
热议问题