code: def perform_keep_shape_image(
      f: Callable[..., Tensor]
  ) -> Callable[..., Tensor]:
      """A decorator that enable `f` to be applied to an image of arbitrary leading dimensions `(*, C, H, W)`.
  
      It works by first viewing the image as `(B, C, H, W)`, applying the function and re-viewing the image as original
      shape.
      """
  
      @wraps(f)
      def _wrapper(input: Tensor, *args: Any, **kwargs: Any) -> Tensor:
          if not isinstance(input, Tensor):
              raise TypeError(
                  f"Input input type is not a Tensor. Got {type(input)}"
              )
  
          if input.numel() == 0:
              raise ValueError("Invalid input tensor, it is empty.")
  
          input_shape = input.shape
          input = _to_bchw(input)  # view input as (B, C, H, W)
          output = f(input, *args, **kwargs)
          if len(input_shape) == 3:
              output = output[0]
  
          if len(input_shape) == 2:
              output = output[0, 0]
  
          if len(input_shape) > 4:
              output = output.view(
                  *(input_shape[:-3] + output.shape[-3:])
              )
  
          return output
  
      return _wrapper
  
file_path: kornia/kornia/utils/image.py
imports: from functools import wraps
  from typing import Any, Callable, List
  import torch
  from torch import nn
  from kornia.core import Tensor
label_desc: Use image node_id 6 for calling a global function with example usage: perform_keep_shape_image(f) and returns: _wrapper, output