ms
==

.. py:module:: ms


Functions
---------

.. autoapisummary::

   ms.kill_count_img
   ms.kill_rate_obj
   ms.un_ms_calcu
   ms.check_kill_binomial_test
   ms.iskill_img
   ms.calcu_mean
   ms.compute_iou
   ms.spatial_aware
   ms.identify_matches_misses_ghosts
   ms.convert_detection_output
   ms.yolo_to_absolute


Module Contents
---------------

.. py:function:: kill_count_img(miss_s, ghost_s)

.. py:function:: kill_rate_obj(match_s, miss_s, ghost_s)

.. py:function:: un_ms_calcu(match_metrics, miss_metrics, ghost_metrics)

.. py:function:: check_kill_binomial_test(success, n, p_null, alpha=0.05)

   Calculates Cohen's h, Power, and P-value for a one-sided (right-tailed) Binomial Test.

   Parameters:
   -----------
   n : int
       Sample size (e.g., 10)
   success : int
       Number of observed successes (e.g., 3)
   p_null : float
       The null hypothesis proportion/noise level (e.g., 0.05)
   alpha : float, optional
       Significance level, default is 0.05

   Returns:
   --------
   dict
       A dictionary containing the calculated statistics.


.. py:function:: iskill_img(miss_s, ghost_s)

.. py:function:: calcu_mean(results, cols_to_mean)

.. py:function:: compute_iou(boxA, boxB)

   Standard IoU calculation with safe checks.


.. py:function:: spatial_aware(rate, metric, penalty)

.. py:function:: identify_matches_misses_ghosts(orig_objs, mut_objs, iou_threshold=0.5)

   Performs Hungarian Matching and filters by IoU threshold.


.. py:function:: convert_detection_output(pred, default_score=1.0)

   Convert a torchvision-style detection output (boxes/labels tensors) into
   the ``{"label_i": {"box", "label", "score", "logit"}}`` format expected by
   :func:`identify_matches_misses_ghosts`.


.. py:function:: yolo_to_absolute(yolo_labels, img_w=1280, img_h=736)

   Convert YOLO normalized bounding boxes to absolute pixel coordinates and compute their areas.

   :param yolo_labels: Each element is [label, x_center, y_center, width, height],
                       where coordinates are normalized between 0 and 1.
   :type yolo_labels: list of lists
   :param img_w: Image width in pixels.
   :type img_w: int
   :param img_h: Image height in pixels.
   :type img_h: int

   :returns:

             {
                 'boxes': torch.Tensor of shape [N, 4] with absolute coordinates [xmin, ymin, xmax, ymax],
                 'labels': torch.Tensor of shape [N] with class IDs,
                 'areas': torch.Tensor of shape [N] with the area of each bounding box in pixels.
             }
   :rtype: dict


