code: def recoverpix(doc, item):
      """Return image for a given XREF."""
      x = item[0]  # xref of PDF image
      s = item[1]  # xref of its /SMask
      if s == 0:  # no smask: use direct image output
          return doc.extract_image(x)
  
      def getimage(pix):
          if pix.colorspace.n != 4:
              return pix
          tpix = fitz.Pixmap(fitz.csRGB, pix)
          return tpix
  
      # we need to reconstruct the alpha channel with the smask
      pix1 = fitz.Pixmap(doc, x)
      pix2 = fitz.Pixmap(doc, s)  # create pixmap of the /SMask entry
  
      """Sanity check:
      - both pixmaps must have the same rectangle
      - both pixmaps must have alpha=0
      - pix2 must consist of 1 byte per pixel
      """
      if not (
          pix1.irect == pix2.irect
          and pix1.alpha == pix2.alpha == 0
          and pix2.n == 1
      ):
          print("Warning: unsupported /SMask %i for %i:" % (s, x))
          print(pix2)
          pix2 = None
          return getimage(pix1)  # return the pixmap as is
  
      pix = fitz.Pixmap(
          pix1
      )  # copy of pix1, with an alpha channel added
      pix.set_alpha(
          pix2.samples
      )  # treat pix2.samples as the alpha values
      pix1 = pix2 = None  # free temp pixmaps
  
      # we may need to adjust something for CMYK pixmaps here:
      return getimage(pix)
  
imports: import argparse
  import bisect
  import os
  import sys
  import statistics
  from typing import Dict, List, Set, Tuple
  import fitz
  from fitz.fitz import TEXT_INHIBIT_SPACES, TEXT_PRESERVE_LIGATURES, TEXT_PRESERVE_WHITESPACE
label_desc: Use image node_id 1 for calling a global function with example usage: recoverpix(doc, item) and returns: getimage, doc, tpix, getimage, pix