src/create_rois.py
def check_intersections(region, regions):
    '''
    Calculates intersection areas between a region and all other regions and returns the index of the maximum intersection area.

    Parameters:
                    regions (list): tuples of the form (y1,x1,y2,x2) representing the ROI bounding boxes
                    region (tuple): tuple of the form (y1,x1,y2,x2) representing the ROI to be checked against all others
                    
            Returns:
                    index (int): index of the maximum intersection area ROI on the regions list
                                    
    '''
    int_areas = []
    bbox = region
    for r in regions:
        r_bbox = r
        
        # the current region being checked is always on the regions list, so we ignore it
        if (r_bbox == bbox):
            int_areas.append(0)

            continue
        if bbox[0] >= r_bbox[2] or r_bbox[0] >= bbox[2]:
            int_areas.append(0) 
            continue
        if bbox[1] >= r_bbox[3] or r_bbox[1] >= bbox[3]:
            int_areas.append(0) 
            continue

        # magical code that gives us coordinates for the intersection bounding box
        y1 = max(min(bbox[0],r_bbox[2]), min(r_bbox[0],bbox[2]))
        x1 = max(min(bbox[1],r_bbox[3]), min(r_bbox[1],bbox[3]))
        y2 = min(max(bbox[0],r_bbox[2]), max(r_bbox[0],bbox[2]))
        x2 = min(max(bbox[1],r_bbox[3]), max(r_bbox[1],bbox[3]))

        # we add the area of intersection to the int_areas list
        if (x2 > x1) and (y2 > y1):
            int_areas.append((x2-x1)*(y2-y1))
        else:
            int_areas.append(0)

    # return -1 if there is no intersection (returning 0 is a bad idea because 0 is a valid index)
    if max(int_areas) == 0:
        return -1
    else:
    # otherwise, return index of maximum intersection area
        return int_areas.index(max(int_areas))

    Calculates intersection areas between a region and all other regions and returns the index of the maximum intersection area.

    Parameters:
                    regions (list): tuples of the form (y1,x1,y2,x2) representing the ROI bounding boxes
                    region (tuple): tuple of the form (y1,x1,y2,x2) representing the ROI to be checked against all others
                    
            Returns:
                    index (int): index of the maximum intersection area ROI on the regions list
                                    
    
Calculates intersection areas between a region and all other regions and returns the index of the maximum intersection area.
Calculates intersection areas between a region and all other regions and returns the index of the maximum intersection area .
def check_intersections(region, regions):
    int_areas = []
    bbox = region
    for r in regions:
        r_bbox = r
        if (r_bbox == bbox):
            int_areas.append(0)
            continue
        if bbox[0] >= r_bbox[2] or r_bbox[0] >= bbox[2]:
            int_areas.append(0) 
            continue
        if bbox[1] >= r_bbox[3] or r_bbox[1] >= bbox[3]:
            int_areas.append(0) 
            continue
        y1 = max(min(bbox[0],r_bbox[2]), min(r_bbox[0],bbox[2]))
        x1 = max(min(bbox[1],r_bbox[3]), min(r_bbox[1],bbox[3]))
        y2 = min(max(bbox[0],r_bbox[2]), max(r_bbox[0],bbox[2]))
        x2 = min(max(bbox[1],r_bbox[3]), max(r_bbox[1],bbox[3]))
        if (x2 > x1) and (y2 > y1):
            int_areas.append((x2-x1)*(y2-y1))
        else:
            int_areas.append(0)
    if max(int_areas) == 0:
        return -1
    else:
        return int_areas.index(max(int_areas))
def check_intersections ( region , regions ) : int_areas = [ ] bbox = region for r in regions : r_bbox = r if ( r_bbox == bbox ) : int_areas . append ( 0 ) continue if bbox [ 0 ] >= r_bbox [ 2 ] or r_bbox [ 0 ] >= bbox [ 2 ] : int_areas . append ( 0 ) continue if bbox [ 1 ] >= r_bbox [ 3 ] or r_bbox [ 1 ] >= bbox [ 3 ] : int_areas . append ( 0 ) continue y1 = max ( min ( bbox [ 0 ] , r_bbox [ 2 ] ) , min ( r_bbox [ 0 ] , bbox [ 2 ] ) ) x1 = max ( min ( bbox [ 1 ] , r_bbox [ 3 ] ) , min ( r_bbox [ 1 ] , bbox [ 3 ] ) ) y2 = min ( max ( bbox [ 0 ] , r_bbox [ 2 ] ) , max ( r_bbox [ 0 ] , bbox [ 2 ] ) ) x2 = min ( max ( bbox [ 1 ] , r_bbox [ 3 ] ) , max ( r_bbox [ 1 ] , bbox [ 3 ] ) ) if ( x2 > x1 ) and ( y2 > y1 ) : int_areas . append ( ( x2 - x1 ) * ( y2 - y1 ) ) else : int_areas . append ( 0 ) if max ( int_areas ) == 0 : return - 1 else : return int_areas . index ( max ( int_areas ) )
Calculates intersection areas between a region and all other regions and returns the index of the maximum intersection area.
Calculates intersection areas between a region and all other regions and returns the index of the maximum intersection area .
'''
    Calculates intersection areas between a region and all other regions and returns the index of the maximum intersection area.

    Parameters:
                    regions (list): tuples of the form (y1,x1,y2,x2) representing the ROI bounding boxes
                    region (tuple): tuple of the form (y1,x1,y2,x2) representing the ROI to be checked against all others
                    
            Returns:
                    index (int): index of the maximum intersection area ROI on the regions list
                                    
    ''' # the current region being checked is always on the regions list, so we ignore it # magical code that gives us coordinates for the intersection bounding box # we add the area of intersection to the int_areas list # return -1 if there is no intersection (returning 0 is a bad idea because 0 is a valid index) # otherwise, return index of maximum intersection area
region
tuple of the form (y1,x1,y2,x2) representing the ROI to be checked against all others
Returns.
tuple of the form ( y1 x1 y2 x2 ) representing the ROI to be checked against all others Returns .
regions
tuples of the form (y1,x1,y2,x2) representing the ROI bounding boxes
tuples of the form ( y1 x1 y2 x2 ) representing the ROI bounding boxes
index
index of the maximum intersection area ROI on the regions list
index of the maximum intersection area ROI on the regions list