code: def apply_histogram(
      img: np.ndarray, reference_image: np.ndarray, blend_ratio: float
  ) -> np.ndarray:
      if img.dtype != reference_image.dtype:
          raise RuntimeError(
              f"Dtype of image and reference image must be the same. Got {img.dtype} and {reference_image.dtype}"
          )
      if img.shape[:2] != reference_image.shape[:2]:
          reference_image = cv2.resize(
              reference_image, dsize=(img.shape[1], img.shape[0])
          )
  
      img, reference_image = np.squeeze(img), np.squeeze(
          reference_image
      )
  
      try:
          matched = match_histograms(
              img,
              reference_image,
              channel_axis=2 if len(img.shape) == 3 else None,
          )
      except TypeError:
          matched = match_histograms(
              img, reference_image, multichannel=True
          )  # case for scikit-image<0.19.1
      img = cv2.addWeighted(
          matched,
          blend_ratio,
          img,
          1 - blend_ratio,
          0,
          dtype=get_opencv_dtype_from_numpy(img.dtype),
      )
      return img
  
imports: import random
  from typing import Any, Callable, Literal, Sequence, Tuple
  import cv2
  import numpy
  from qudida import DomainAdapter
  from skimage.exposure import match_histograms
  from sklearn.decomposition import PCA
  from sklearn.preprocessing import MinMaxScaler, StandardScaler
  from albumentations.augmentations.utils import clipped, get_opencv_dtype_from_numpy, is_grayscale_image, is_multispectral_image, preserve_shape, read_rgb_image
  from ..core.transforms_interface import ImageOnlyTransform, ScaleFloatType, to_tuple
label_desc: Use image node_id 2 for calling a global function with example usage: apply_histogram(img, reference_image, blend_ratio) and returns: img