§
    eznim  ã                   ó   — d dl Z dd„Zd	d„ZdS )
é    Né   c                 óÄ   — |\  }}d| | dd…df         |k     df<   d| | dd…df         |k     df<   || | dd…df         ||z
  k    df<   || | dd…df         ||z
  k    df<   | S )a3  
    Adjust bounding boxes to stick to image border if they are within a certain threshold.

    Args:
        boxes (torch.Tensor): (n, 4)
        image_shape (tuple): (height, width)
        threshold (int): pixel threshold

    Returns:
        adjusted_boxes (torch.Tensor): adjusted bounding boxes
    r   Né   é   é   © )ÚboxesÚimage_shapeÚ	thresholdÚhÚws        ú€/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/ultralytics/models/fastsam/utils.pyÚadjust_bboxes_to_image_borderr      sœ   € ð �D€A€qð )*€Eˆ%����1�Œ+˜	Ò
! 1Ð
$Ñ%Ø()€Eˆ%����1�Œ+˜	Ò
! 1Ð
$Ñ%Ø,-€Eˆ%����1�Œ+˜˜I™Ò
% qÐ
(Ñ)Ø,-€Eˆ%����1�Œ+˜˜I™Ò
% qÐ
(Ñ)Ø€Ló    çÍÌÌÌÌÌì?©é€  r   Fc                 ó  — t          ||¦  «        }t          j        | d         |dd…df         ¦  «        }t          j        | d         |dd…df         ¦  «        }t          j        | d         |dd…df         ¦  «        }t          j        | d         |dd…df         ¦  «        }||z
                       d¦  «        ||z
                       d¦  «        z  }	| d         | d         z
  | d         | d         z
  z  }
|dd…df         |dd…df         z
  |dd…df         |dd…df         z
  z  }|
|z   |	z
  }|	|z  }|r|                     ¦   «         dk    rdn|S t          j        ||k    ¦  «                             ¦   «         S )aÈ  
    Compute the Intersection-Over-Union of a bounding box with respect to an array of other bounding boxes.

    Args:
        box1 (torch.Tensor): (4, )
        boxes (torch.Tensor): (n, 4)
        iou_thres (float): IoU threshold
        image_shape (tuple): (height, width)
        raw_output (bool): If True, return the raw IoU values instead of the indices

    Returns:
        high_iou_indices (torch.Tensor): Indices of boxes with IoU > thres
    r   Nr   r   r   )r   ÚtorchÚmaxÚminÚclampÚnumelÚnonzeroÚflatten)Úbox1r	   Ú	iou_thresr
   Ú
raw_outputÚx1Úy1Úx2Úy2ÚintersectionÚ	box1_areaÚ	box2_areaÚunionÚious                 r   Úbbox_iour(      s�  € õ *¨%°Ñ=Ô=€Eå	Œ�4˜”7˜E ! ! ! Q $œKÑ	(Ô	(€BÝ	Œ�4˜”7˜E ! ! ! Q $œKÑ	(Ô	(€BÝ	Œ�4˜”7˜E ! ! ! Q $œKÑ	(Ô	(€BÝ	Œ�4˜”7˜E ! ! ! Q $œKÑ	(Ô	(€Bð ˜‘G—?’? 1Ñ%Ô%¨¨b©¯ª¸Ñ(:Ô(:Ñ:€Lð �a”˜4 œ7Ñ" t¨A¤w°°a´Ñ'8Ñ9€IØ�q�q�q˜!�t”˜u Q Q Q¨ Tœ{Ñ*¨u°Q°Q°Q¸°T¬{¸UÀ1À1À1ÀaÀ4¼[Ñ/HÑI€Ið ˜	Ñ! LÑ0€Eð ˜Ñ
€CØð .Ø—I’I‘K”K 1Ò$Ð$ˆqˆq¨#Ð-õ Œ=˜˜yšÑ)Ô)×1Ò1Ñ3Ô3Ð3r   )r   )r   r   F)r   r   r(   r   r   r   ú<module>r)      sB   ðð €€€ðð ð ð ð0%4ð %4ð %4ð %4ð %4ð %4r   