code: def _scan_level(self, level, prev, img):
          
          if level == 0:
              width, height = img.size
          else:
              width, height = prev.size
  
          tr = self.traversal[0](width, height, ends=(level == 0))
          if level == 0:
              for xy in tr:
                  if xy is None:
                      yield self.END
                  else:
                      yield pixel_to_state(img.getpixel(xy))
              yield self.END
          else:
              scale = self.level_scale[level - 1]
              for xy in tr:
                  x0 = xy[0] * scale
                  y0 = xy[1] * scale
                  start = (
                      self.START,
                      pixel_to_state(prev.getpixel(xy))
                  )
                  yield start
                  for dxy in self.traversal[level](scale, scale, True):
                      if dxy is None:
                          yield start
                      yield pixel_to_state(
                          img.getpixel((x0 + dxy[0], y0 + dxy[1]))
                      )
                  yield self.END
docs: Scan a level.
  
          Parameters
          ----------
          level : `int`
              Level number.
          prev : `PIL.Image` or None
              Previous level image or None if level == 0.
          img : `PIL.Image`
              Current level image.
  
          Returns
          -------
          `generator` of (`str` or `markovchain.scanner.Scanner.END` or (`markovchain.scanner.Scanner.START`, `str`))
              Token generator.