Pixel neighbors in 2d array (image) using Python

后端 未结 7 1007
灰色年华
灰色年华 2020-12-01 08:40

I have a numpy array like this:

x = np.array([[1,2,3],[4,5,6],[7,8,9]])

I need to create a function let\'s call it \"neighbors\" with the f

7条回答
  •  余生分开走
    2020-12-01 08:55

    I agree with Joe Kingtons response, just an add to the footprints

    import numpy as np
    from scipy.ndimage import generate_binary_structure
    from scipy.ndimage import iterate_structure
    foot = np.array(generate_binary_structure(2, 1),dtype=int)
    

    or for bigger/different footprints for ex.

    np.array(iterate_structure(foot , 2),dtype=int)
    

提交回复
热议问题