How to deviate the border dimension of an numpy array

Viewed 59

for example in the array how can we vary the border?

   import NumPy as np
     import script. ndimage as nd
     a=np.array(  
        [[0,0, 0, 0, 0, 0,0],
         [0,0, 0, 0, 0, 0,0],
         [0,0, 0, 1, 0, 0,0],
         [0,0, 0, 0, 0, 0,0],
         [0,0, 0, 0, 0, 0,0],
         [0,0, 0, 0, 0, 0,0]])

    s2 = nd.generate_binary_structure(rank=2,connectivity=2)
    lab, nlab = nd.label(input=a,structure=s2)
        for i in range(1, (nlab+1)):
            region_i = lab==i
            expanded = nd.binary_dilation(region_i, iterations=1, 
      structure=s2)
            border = np.logical_xor(region_i, expanded)
            print(border)
            x=np.argwhere(border)
            print(x)

Current output: enter image description here

   in the above output image, true values are the first neighbor of 
  structure false(yellow 
   color ellipse)

requirement:

How can we make only 2nd neighbor true or maybe 3rd, instead of the first neighbor (red color 
square in the image)

Reference question link How to access range of indices of an array where specific conditions match where-specific-conditions-match

0 Answers
Related