def _unionize_clusters(self, masked_preds: dict[str, np.ndarray]) -> dict[str, np.ndarray]:
        """
        Cluster the bounding boxes for the pruned masked predictions.

        :param masked_preds: The merged masked predictions of a single image already pruned.
        :return: The clustered masked predictions with overlapping boxes merged.
        """
        boxes = masked_preds["boxes"]
        labels = masked_preds["labels"]
        scores = masked_preds["scores"]

        # Skip clustering if not enough bounding boxes
        if len(boxes) <= 1:
            return masked_preds

        unionized_boxes = []
        unionized_labels = []
        unionized_scores = []

        unique_labels = np.unique(labels)
        for label in unique_labels:
            # Select bounding boxes of same class
            mask = labels == label
            selected_boxes = boxes[mask]
            selected_scores = scores[mask]

            # Calculate pairwise distances between bounding boxes
            areas = (selected_boxes[:, 2] - selected_boxes[:, 0]) * (selected_boxes[:, 3] - selected_boxes[:, 1])
            top_left = np.maximum(selected_boxes[:, None, :2], selected_boxes[:, :2])
            bottom_right = np.minimum(selected_boxes[:, None, 2:], selected_boxes[:, 2:])
            pairwise_intersection = np.prod(np.clip(bottom_right - top_left, 0, None), axis=2)
            pairwise_ioa = pairwise_intersection / (areas[:, None])
            distances = 1 - np.maximum(pairwise_ioa, pairwise_ioa.T)

            # Cluster bounding boxes
            dbscan = DBSCAN(eps=self.epsilon, min_samples=1, metric="precomputed")
            clusters = dbscan.fit_predict(distances)
            num_clusters = np.max(clusters) + 1

            for cluster in range(num_clusters):
                # Merge all boxes in the cluster
                clustered_boxes = selected_boxes[clusters == cluster]

                clustered_box = [
                    np.min(clustered_boxes[:, 0]),
                    np.min(clustered_boxes[:, 1]),
                    np.max(clustered_boxes[:, 2]),
                    np.max(clustered_boxes[:, 3]),
                ]
                clustered_score = np.max(selected_scores)

                unionized_boxes.append(clustered_box)
                unionized_labels.append(label)
                unionized_scores.append(clustered_score)

        unionized_predictions = {
            "boxes": np.asarray(unionized_boxes),
            "labels": np.asarray(unionized_labels),
            "scores": np.asarray(unionized_scores),
        }
        return unionized_predictions

        Cluster the bounding boxes for the pruned masked predictions.

        :param masked_preds: The merged masked predictions of a single image already pruned.
        :return: The clustered masked predictions with overlapping boxes merged.
        
art/estimators/certification/object_seeker/object_seeker.py