code: def _tas(img, thresh, margin):
      if len(img.shape) == 2:
          M = _M2
          bins = _bins2
          saved = 9
      elif len(img.shape) == 3:
          M = _M3
          bins = _bins3
          saved = 27
      else:
          raise ValueError(
              "mahotas.tas: Cannot compute TAS for image of %s dimensions"
              % len(img.shape)
          )
  
      def _ctas(img):
          V = convolve(img.astype(np.uint8), M)
          values, _ = np.histogram(V, bins=bins)
          values = values[:saved]
          s = values.sum()
          if s > 0:
              return values / float(s)
          return values
  
      def _compute(bimg):
          alltas.append(_ctas(bimg))
          allntas.append(_ctas(~bimg))
  
      alltas = []
      allntas = []
      total = np.sum(img > thresh)
      mu = ((img > thresh) * img).sum() / (total + 1e-8)
      _compute((img > mu - margin) * (img < mu + margin))
      _compute(img > mu - margin)
      _compute(img > mu)
  
      return np.concatenate(alltas + allntas)
  
imports: import numpy
  from ..convolve import convolve
  from ..thresholding import otsu
label_desc: Use image node_id 1 for calling a global function with example usage: _tas(img, thresh, margin) and returns: np, values, unknown