code: def strel_octagon(radius):
      
      #
      # Inscribe a diamond in a square to get an octagon.
      #
      iradius = int(radius)
      i, j = np.mgrid[-iradius:(iradius + 1), -iradius:(iradius+1)]
      #
      # The distance to the diagonal side is also iradius:
      #
      # iradius ** 2 = i**2 + j**2 and i = j
      # iradius ** 2 = 2 * i ** 2
      # i = iradius / sqrt(2)
      # i + j = iradius * sqrt(2)
      #
      dradius = float(iradius) * np.sqrt(2)
      strel = (((i+j) <= dradius) & ((i+j) >= -dradius) &
               ((i-j) <= dradius) & ((i-j) >= -dradius))
      return strel
docs: Create an octagonal structuring element for morphological operations
      
      radius - the distance from the origin to each edge of the octagon