code: def masks_to_boxes(masks):
      """
      Compute the bounding boxes around the provided panoptic segmentation masks.
  
      The masks should be in format [N, H, W] where N is the number of masks, (H, W) are the spatial dimensions.
  
      Returns a [N, 4] tensor, with the boxes in corner (xyxy) format.
      """
      if masks.size == 0:
          return np.zeros((0, 4))
  
      h, w = masks.shape[-2:]
  
      y = np.arange(0, h, dtype=np.float32)
      x = np.arange(0, w, dtype=np.float32)
      # see https://github.com/pytorch/pytorch/issues/50276
      y, x = np.meshgrid(y, x, indexing="ij")
  
      x_mask = masks * np.expand_dims(x, axis=0)
      x_max = x_mask.reshape(x_mask.shape[0], -1).max(-1)
      x = np.ma.array(x_mask, mask=~(np.array(masks, dtype=bool)))
      x_min = x.filled(fill_value=1e8)
      x_min = x_min.reshape(x_min.shape[0], -1).min(-1)
  
      y_mask = masks * np.expand_dims(y, axis=0)
      y_max = y_mask.reshape(x_mask.shape[0], -1).max(-1)
      y = np.ma.array(y_mask, mask=~(np.array(masks, dtype=bool)))
      y_min = y.filled(fill_value=1e8)
      y_min = y_min.reshape(y_min.shape[0], -1).min(-1)
  
      return np.stack([x_min, y_min, x_max, y_max], 1)
  
imports: import io
  import pathlib
  import warnings
  from collections import defaultdict
  from typing import Dict, List, Optional, Set, Tuple, Union
  import numpy
  from PIL import Image
  from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
  from ...image_utils import ImageFeatureExtractionMixin, is_torch_tensor
  from ...utils import TensorType, is_torch_available, logging
label_desc: Use image node_id 3 for calling a global function with example usage: masks_to_boxes(masks) and returns: np, np