code: def step(self):
          
          # Assign attributes to local variables for convenience.
          u = self._u
          gI = self._data
          dgI = self._ddata
          theta = self._theta
          v = self._v
          
          if u is None:
              raise ValueError("the levelset is not set (use set_levelset)")
          
          res = np.copy(u)
          
          # Balloon.
          if v > 0:
              aux = binary_dilation(u, self.structure)
          elif v < 0:
              aux = binary_erosion(u, self.structure)
          if v!= 0:
              res[self._threshold_mask_v] = aux[self._threshold_mask_v]
          
          # Image attachment.
          aux = np.zeros_like(res)
          dres = np.gradient(res)
          for el1, el2 in zip(dgI, dres):
              aux += el1*el2
          res[aux > 0] = 1
          res[aux < 0] = 0
          
          # Smoothing.
          for i in range(self.smoothing):
              res = curvop(res)
          
          self._u = res
docs: Perform a single step of the morphological snake evolution.