docstr: Parameters
  ----------
  img image with dtype=np.uint8
  cval
  
  Returns image with dtype=np.uint8
  -------
docstr_tok: ["Parameters","--","--","--","--","--","img","image","with","dtype=np.uint8","cval","Returns","image","with","dtype=np.uint8","--","--","--","-"]
code: def dewarp(self, img, cval=0):
      """
  
      Parameters
      ----------
      img image with dtype=np.uint8
      cval
  
      Returns image with dtype=np.uint8
      -------
  
      """
      if img.size == 0:
          # Empty image
          return img
  
      if img.ndim > 2:
          assert img.ndim == 3, img.shape
          if img.shape[-1] == 1:
              temp = np.squeeze(img, axis=-1)
          elif img.shape[-1] == 3:
              temp = (cv.cvtColor(img, cv.COLOR_RGB2GRAY) / 255).astype(
                  np.float32
              )
          else:
              temp = np.mean(img, axis=-1)
      else:
          temp = (img / 255).astype(np.float32)
      temp = np.amax(temp) - temp
      amax = np.amax(temp)
      if amax == 0:
          # white image
          return (temp * 255).astype(np.uint8)
      inverted = temp * 1.0 / np.amax(temp)
  
      center, r = self.measure(inverted)
  
      # The actual image img is embedded into a larger image by
      # adding vertical space on top and at the bottom (padding)
      hpad = r  # this is large enough
      padded = cv.copyMakeBorder(
          img, hpad, hpad, 0, 0, cv.BORDER_CONSTANT, value=cval
      )
  
      center = center + hpad - r
      new_h = 2 * r
      dewarped = [
          padded[c : c + new_h, i] for i, c in enumerate(center)
      ]
  
      # transpose and convert
      dewarped = np.swapaxes(np.array(dewarped, dtype=np.uint8), 1, 0)
      return dewarped
  
file_path: calamari/calamari_ocr/ocr/dataset/imageprocessors/center_normalizer.py
imports: from dataclasses import dataclass, field
  from typing import Type, Tuple
  import numpy
  import cv2
  from paiargparse import pai_dataclass
  from tfaip.data.pipeline.processor.dataprocessor import DataProcessorParams
  from calamari_ocr.ocr.dataset.imageprocessors.scale_to_height_processor import scale_to_h
  from calamari_ocr.ocr.dataset.imageprocessors.data_preprocessor import ImageProcessor
label_desc: Use image node_id 5 for calling the CenterNormalizerProcessor obj's underlying member method code with example usage: obj.dewarp(img, cval) and returns: dewarped, img, unknown