code: def check_getArrayRegion(roi, name, testResize=True, transpose=False):
      # on windows, edges corner pixels seem to be slightly different from
      # other platforms giving a pxCount=2 for a fudge factor
      if (
          isinstance(roi, (pg.ROI, pg.RectROI))
          and platform.system() == "Windows"
      ):
          pxCount = 2
      else:
          pxCount = -1
  
      initState = roi.getState()
  
      win = pg.GraphicsView()
      win.show()
      resizeWindow(win, 200, 400)
      # Don't use Qt's layouts for testing--these generate unpredictable results.
      # Instead, place the viewboxes manually
      vb1 = pg.ViewBox()
      win.scene().addItem(vb1)
      vb1.setPos(6, 6)
      vb1.resize(188, 191)
  
      vb2 = pg.ViewBox()
      win.scene().addItem(vb2)
      vb2.setPos(6, 203)
      vb2.resize(188, 191)
  
      img1 = pg.ImageItem(border="w")
      img2 = pg.ImageItem(border="w")
  
      vb1.addItem(img1)
      vb2.addItem(img2)
  
      np.random.seed(0)
      data = np.random.normal(size=(7, 30, 31, 5))
      data[0, :, :, :] += 10
      data[:, 1, :, :] += 10
      data[:, :, 2, :] += 10
      data[:, :, :, 3] += 10
  
      if transpose:
          data = data.transpose(0, 2, 1, 3)
  
      img1.setImage(data[0, ..., 0])
      vb1.setAspectLocked()
      vb1.enableAutoRange(True, True)
  
      roi.setZValue(10)
      vb1.addItem(roi)
  
      if isinstance(roi, pg.RectROI):
          if transpose:
              assert roi.getAffineSliceParams(
                  data, img1, axes=(1, 2)
              ) == ([28.0, 27.0], ((1.0, 0.0), (0.0, 1.0)), (1.0, 1.0))
          else:
              assert roi.getAffineSliceParams(
                  data, img1, axes=(1, 2)
              ) == ([27.0, 28.0], ((1.0, 0.0), (0.0, 1.0)), (1.0, 1.0))
  
      rgn = roi.getArrayRegion(data, img1, axes=(1, 2))
      # assert np.all((rgn == data[:, 1:-2, 1:-2, :]) | (rgn == 0))
      img2.setImage(rgn[0, ..., 0])
      vb2.setAspectLocked()
      vb2.enableAutoRange(True, True)
  
      app.processEvents()
      assertImageApproved(
          win,
          name + "/roi_getarrayregion",
          "Simple ROI region selection.",
          pxCount=pxCount,
      )
  
      with pytest.raises(TypeError):
          roi.setPos(0, False)
  
      roi.setPos([0.5, 1.5])
      rgn = roi.getArrayRegion(data, img1, axes=(1, 2))
      img2.setImage(rgn[0, ..., 0])
      app.processEvents()
      assertImageApproved(
          win,
          name + "/roi_getarrayregion_halfpx",
          "Simple ROI region selection, 0.5 pixel shift.",
          pxCount=pxCount,
      )
  
      roi.setAngle(45)
      roi.setPos([3, 0])
      rgn = roi.getArrayRegion(data, img1, axes=(1, 2))
      img2.setImage(rgn[0, ..., 0])
      app.processEvents()
      assertImageApproved(
          win,
          name + "/roi_getarrayregion_rotate",
          "Simple ROI region selection, rotation.",
          pxCount=pxCount,
      )
  
      if testResize:
          roi.setSize([60, 60])
          rgn = roi.getArrayRegion(data, img1, axes=(1, 2))
          img2.setImage(rgn[0, ..., 0])
          app.processEvents()
          assertImageApproved(
              win,
              name + "/roi_getarrayregion_resize",
              "Simple ROI region selection, resized.",
              pxCount=pxCount,
          )
  
      img1.setPos(0, img1.height())
      img1.setTransform(
          QtGui.QTransform().scale(1, -1).rotate(20), True
      )
      rgn = roi.getArrayRegion(data, img1, axes=(1, 2))
      img2.setImage(rgn[0, ..., 0])
      app.processEvents()
      assertImageApproved(
          win,
          name + "/roi_getarrayregion_img_trans",
          "Simple ROI region selection, image transformed.",
          pxCount=pxCount,
      )
  
      vb1.invertY()
      rgn = roi.getArrayRegion(data, img1, axes=(1, 2))
      img2.setImage(rgn[0, ..., 0])
      app.processEvents()
      assertImageApproved(
          win,
          name + "/roi_getarrayregion_inverty",
          "Simple ROI region selection, view inverted.",
          pxCount=pxCount,
      )
  
      roi.setState(initState)
      img1.setPos(0, 0)
      img1.setTransform(QtGui.QTransform.fromScale(1, 0.5))
      rgn = roi.getArrayRegion(data, img1, axes=(1, 2))
      img2.setImage(rgn[0, ..., 0])
      app.processEvents()
      assertImageApproved(
          win,
          name + "/roi_getarrayregion_anisotropic",
          "Simple ROI region selection, image scaled anisotropically.",
          pxCount=pxCount,
      )
  
      # allow the roi to be re-used
      roi.scene().removeItem(roi)
  
      win.hide()
  
file_path: pyqtgraph/tests/graphicsItems/test_ROI.py
imports: import math
  import platform
  import numpy
  import pytest
  from packaging.version import Version, parse
  import pyqtgraph
  from pyqtgraph.Qt import QtCore, QtGui, QtTest
  from tests.image_testing import assertImageApproved
  from tests.ui_testing import mouseClick, mouseDrag, mouseMove, resizeWindow
label_desc: Use image node_id 3 for calling a global function with example usage: check_getArrayRegion(roi, name, testResize, transpose) without return types