code: def _maybe_new_metatensor(img, dtype=None, device=None):
      """create a metatensor with fresh metadata if track_meta is True otherwise convert img into a torch tensor"""
      return convert_to_tensor(
          img.as_tensor() if isinstance(img, MetaTensor) else img,
          dtype=dtype,
          device=device,
          track_meta=get_track_meta(),
          wrap_sequence=True,
      )
  
imports: from __future__ import annotations
  import math
  import warnings
  from enum import Enum
  import numpy
  import torch
  import monai
  from monai.config import USE_COMPILED
  from monai.config.type_definitions import NdarrayOrTensor
  from monai.data.meta_obj import get_track_meta
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import AFFINE_TOL, compute_shape_offset, to_affine_nd
  from monai.networks.layers import AffineTransform
  from monai.transforms.croppad.array import ResizeWithPadOrCrop
  from monai.transforms.intensity.array import GaussianSmooth
  from monai.transforms.inverse import TraceableTransform
  from monai.transforms.utils import create_rotate, create_translate, resolves_modes, scale_affine
  from monai.transforms.utils_pytorch_numpy_unification import allclose
  from monai.utils import LazyAttr, TraceKeys, convert_to_dst_type, convert_to_numpy, convert_to_tensor, ensure_tuple, ensure_tuple_rep, fall_back_tuple, optional_import
label_desc: Use image node_id 1 for calling a global function with example usage: _maybe_new_metatensor(img, dtype, device) and returns: convert_to_tensor