code: def sample_crop_size(
      image_h: int,
      image_w: int,
      resized_size: tuple[int, int],
      scales: tf.Tensor,
      max_distort: int = 1,
  ) -> tuple[int, int, int, int]:
      """Sample a crop size and the offset out of fixed choices.
  
      Args:
        image_h: The height of the image.
        image_w: The width of the image.
        resized_size: The size of the resized image.
        scales: The scales for the resize operation.
        max_distort: How many adjact possitions in the scales array to combine in
        order to get the pairs for the resize options.
  
      Returns:
        A tuple of 4 elements -> [crop_h, crop_w, offset_h, offset_w].
  
      """
  
      if len(scales) != 4:
          raise NotImplementedError(
              "Only 4 values are supported for the scale."
          )
  
      base_size = tf.cast(tf.minimum(image_w, image_h), tf.float32)
  
      crop_sizes = [
          tf.cast(base_size * scales[0], tf.int32),
          tf.cast(base_size * scales[1], tf.int32),
          tf.cast(base_size * scales[2], tf.int32),
          tf.cast(base_size * scales[3], tf.int32),
      ]
      rsize_h, rsize_w = resized_size
  
      crop_h = [
          rsize_h
          if abs(crop_sizes[0] - rsize_h) < 3
          else crop_sizes[0],
          rsize_h
          if abs(crop_sizes[1] - rsize_h) < 3
          else crop_sizes[1],
          rsize_h
          if abs(crop_sizes[2] - rsize_h) < 3
          else crop_sizes[2],
          rsize_h
          if abs(crop_sizes[3] - rsize_h) < 3
          else crop_sizes[3],
      ]
  
      crop_w = [
          rsize_w
          if abs(crop_sizes[0] - rsize_w) < 3
          else crop_sizes[0],
          rsize_w
          if abs(crop_sizes[1] - rsize_w) < 3
          else crop_sizes[1],
          rsize_w
          if abs(crop_sizes[2] - rsize_w) < 3
          else crop_sizes[2],
          rsize_w
          if abs(crop_sizes[3] - rsize_w) < 3
          else crop_sizes[3],
      ]
  
      # Get the resized pairs.
      pairs = []
      for i, h in enumerate(crop_h):
          for j, w in enumerate(crop_w):
              if abs(i - j) <= max_distort:
                  pairs.append((w, h))
  
      # Implement random.choice.
      crop_pair_index = tf.random.uniform(
          (1, 1), minval=0, maxval=len(pairs), dtype=tf.int32
      )[0, 0]
      pairs = tf.stack(pairs)
      crop_pair = tf.slice(pairs, [crop_pair_index, 0], [1, 2])
  
      offset = sample_fixed_offset(
          image_w=image_w,
          image_h=image_h,
          crop_w=crop_pair[0][0],
          crop_h=crop_pair[0][1],
      )
      return (
          crop_pair[0][1],
          crop_pair[0][0],
          offset[0][1],
          offset[0][0],
      )
  
imports: from typing import Optional, Union
  from absl import logging
  from dmvr import builders
  from dmvr import processors
  import ml_collections
  import tensorflow
label_desc: Use image node_id 13 for calling a global function with example usage: sample_crop_size(image_h, image_w, resized_size, scales, max_distort) and returns: crop_pair,  crop_pair,  offset,  offset