code: def resize(
      tens: Tensor,
      target_size: Optional[Tuple[int, int]] = None,
      resize_factor: Optional[Union[float, Tuple]] = None,
      preserve_aspect_ratio: bool = False,
      interpolation: str = "bilinear",
  ) -> Tensor:
      r"""
      Resizes an image to a target_size without aspect ratio distortion.
  
      Your output images will be of size ``target_size``, and will not be distorted. Instead, the parts of the image that do not fit within the target size get cropped out.
  
      The resizing process is:
      1. Resize the image as minimally as possible.
      2. Take the largest centered crop of the image with dimensions = ``target_size``.
  
      Alternatively, you may use:
      ```python
      size = (200,200)
      tens = caer.resize(tens, target_size=size, preserve_aspect_ratio=True)
      ```
  
      Note:
          ``caer.imread()`` comes with an in-built functionality to resize your images, eliminating the need for you to call ``caer.resize()``. This is purely optional and may appeal to certain users.
  
          You may also use ``caer.smart_resize()`` for on-the-fly image resizing that `preserves the aspect ratio`.
  
  
      Args:
          tens (Tensor): Input Image. Must be in the format ``(height, width, channels)``.
          target_size (tuple): Target size. Must be a tuple of ``(width, height)`` integer.
          resize_factor (float, tuple): Resizing Factor to employ.
              Shrinks the image if ``resize_factor < 1``
              Enlarges the image if ``resize_factor > 1``
          preserve_aspect_ratio (bool): Prevent aspect ratio distortion (employs center crop).
          interpolation (str): Interpolation to use for resizing. Defaults to `'bilinear'`.
              Supports `'bilinear'`, `'bicubic'`, `'area'`, `'nearest'`.
  
  
      Returns:
      Tensor of shape ``(height, width, channels)``.
  
  
      Examples::
  
          >> tens = caer.data.sunrise()
          >> tens.shape
          (427, 640, 3)
  
          >> resized = caer.resize(tens, target_size=(200,200)) # Hard-resize. May distort aspect ratio
          >> resized.shape
          (200, 200, 3)
  
          >> resized_wf = caer.resize(tens, resize_factor=.5) # Resizes the image to half its dimensions
          >> resized_wf.shape
          (213, 320, 3)
  
          >> resized = caer.resize(tens, target_size=(200,200), preserve_aspect_ratio=True) # Preserves aspect ratio
          >> resized.shape
          (200, 200, 3)
  
      """
      # Opencv uses the (h,w) format
      height, width = tens.shape[:2]
      interpolation = str(interpolation)
      cspace = None
  
      if isinstance(tens, Tensor):
          # We'll need to preserve this before returning
          cspace = tens.cspace
  
      if resize_factor is None:
          if target_size is None:
              if preserve_aspect_ratio:
                  raise ValueError("Specify a target size")
              else:
                  raise ValueError(
                      "Specify either a resize factor or target dimensions"
                  )
          if target_size is not None:
              if len(target_size) == 2:
                  new_shape = target_size
              else:
                  raise ValueError(
                      "Tuple shape must be = 2 (width, height)"
                  )
  
      if resize_factor is not None:
          target_size = None
          preserve_aspect_ratio = False
  
          if not isinstance(resize_factor, (int, float)):
              raise ValueError(
                  "resize_factor must be an integer or float"
              )
  
          if resize_factor > 1:
              interpolation = "bicubic"
  
          new_shape = (
              int(resize_factor * width),
              int(resize_factor * height),
          )
  
      interpolation_methods = {
          "nearest": INTER_NEAREST,
          "0": INTER_NEAREST,
          "bilinear": INTER_LINEAR,
          "1": INTER_LINEAR,
          "bicubic": INTER_CUBIC,
          "2": INTER_CUBIC,
          "area": INTER_AREA,
          "3": INTER_AREA,
      }
  
      if interpolation not in interpolation_methods:
          raise ValueError(
              "Specify a valid interpolation type - area/nearest/bicubic/bilinear"
          )
  
      if preserve_aspect_ratio:
          img = _resize_with_ratio(
              tens,
              target_size=target_size,  # type: ignore[arg-type]
              preserve_aspect_ratio=preserve_aspect_ratio,
              interpolation=interpolation_methods[interpolation],
          )
      else:
          width, height = new_shape[:2]
          img = _cv2_resize(
              tens,
              (width, height),
              interpolation=interpolation_methods[interpolation],
          )
  
      # For this function, the <cspace> attribute is not required.
      # So, we disable the mandatory check that the <cspace> attribute needs to be passed for
      # foreign Tensors/ndarrays
      return to_tensor(img, cspace=cspace, override_checks=True)
  
file_path: caer/caer/io/resize.py
imports: import math
  import cv2
  from ..coreten import Tensor, to_tensor
  from .._internal import _check_target_size
  from ..globals import INTER_AREA, INTER_CUBIC, INTER_NEAREST, INTER_LINEAR
  from typing import Tuple, Optional, Union
label_desc: Use image node_id 1 for calling a global function with example usage: resize(tens, target_size, resize_factor, preserve_aspect_ratio, interpolation) and returns: to_tensor