code: def image_from_window(
      render_window, as_vtk=False, ignore_alpha=False, scale=1
  ):
      """Extract the image from the render window as an array.
  
      Parameters
      ----------
      render_window : vtk.vtkRenderWindow
          The render window to extract the image from.
  
      as_vtk : bool, default: False
          If set to True, the image will be returned as a VTK object.
  
      ignore_alpha : bool, default: False
          If set to True, the image will be returned in RGB format,
          otherwise, it will be returned in RGBA format.
  
      scale : int, default: 1
          The scaling factor of the extracted image. The default value is 1
          which means that no scaling is applied.
  
      Returns
      -------
      ndarray | vtk.vtkImageData
          The image as an array or as a VTK object depending on the ``as_vtk`` parameter.
  
      """
      off = not render_window.GetInteractor().GetEnableRender()
      if off:
          render_window.GetInteractor().EnableRenderOn()
      imfilter = _vtk.vtkWindowToImageFilter()
      imfilter.SetInput(render_window)
      imfilter.SetScale(scale)
      imfilter.FixBoundaryOn()
      imfilter.ReadFrontBufferOff()
      imfilter.ShouldRerenderOff()
      if ignore_alpha:
          imfilter.SetInputBufferTypeToRGB()
      else:
          imfilter.SetInputBufferTypeToRGBA()
      imfilter.ReadFrontBufferOn()
      data = run_image_filter(imfilter)
      if off:
          # Critical for Trame and other offscreen tools
          render_window.GetInteractor().EnableRenderOff()
      if as_vtk:
          return wrap_image_array(data)
      return data
  
file_path: pyvista/pyvista/plotting/utilities/regression.py
imports: from typing import Optional, cast
  import numpy
  import pyvista
  from pyvista.core.utilities.arrays import point_array
  from pyvista.core.utilities.helpers import wrap
  from pyvista.plotting import _vtk
label_desc: Use image node_id 4 for calling a global function with example usage: image_from_window(render_window, as_vtk, ignore_alpha, scale) and returns: data, wrap_image_array