mmdet/datasets/pipelines/transforms.py
def _mosaic_combine(self, loc, center_position_xy, img_shape_wh):
        """Calculate global coordinate of mosaic image and local coordinate of
        cropped sub-image.

        Args:
            loc (str): Index for the sub-image, loc in ('top_left',
              'top_right', 'bottom_left', 'bottom_right').
            center_position_xy (Sequence[float]): Mixing center for 4 images,
                (x, y).
            img_shape_wh (Sequence[int]): Width and height of sub-image

        Returns:
            tuple[tuple[float]]: Corresponding coordinate of pasting and
                cropping
                - paste_coord (tuple): paste corner coordinate in mosaic image.
                - crop_coord (tuple): crop corner coordinate in mosaic image.
        """

        assert loc in ('top_left', 'top_right', 'bottom_left', 'bottom_right')
        if loc == 'top_left':
            # index0 to top left part of image
            x1, y1, x2, y2 = max(center_position_xy[0] - img_shape_wh[0], 0), \
                             max(center_position_xy[1] - img_shape_wh[1], 0), \
                             center_position_xy[0], \
                             center_position_xy[1]
            crop_coord = img_shape_wh[0] - (x2 - x1), img_shape_wh[1] - (
                    y2 - y1), img_shape_wh[0], img_shape_wh[1]

        elif loc == 'top_right':
            # index1 to top right part of image
            x1, y1, x2, y2 = center_position_xy[0], \
                             max(center_position_xy[1] - img_shape_wh[1], 0), \
                             min(center_position_xy[0] + img_shape_wh[0],
                                 self.img_scale[1] * 2), \
                             center_position_xy[1]
            crop_coord = 0, img_shape_wh[1] - (y2 - y1), min(
                img_shape_wh[0], x2 - x1), img_shape_wh[1]

        elif loc == 'bottom_left':
            # index2 to bottom left part of image
            x1, y1, x2, y2 = max(center_position_xy[0] - img_shape_wh[0], 0), \
                             center_position_xy[1], \
                             center_position_xy[0], \
                             min(self.img_scale[0] * 2, center_position_xy[1] +
                                 img_shape_wh[1])
            crop_coord = img_shape_wh[0] - (x2 - x1), 0, img_shape_wh[0], min(
                y2 - y1, img_shape_wh[1])

        else:
            # index3 to bottom right part of image
            x1, y1, x2, y2 = center_position_xy[0], \
                             center_position_xy[1], \
                             min(center_position_xy[0] + img_shape_wh[0],
                                 self.img_scale[1] * 2), \
                             min(self.img_scale[0] * 2, center_position_xy[1] +
                                 img_shape_wh[1])
            crop_coord = 0, 0, min(img_shape_wh[0],
                                   x2 - x1), min(y2 - y1, img_shape_wh[1])

        paste_coord = x1, y1, x2, y2
        return paste_coord, crop_coord
Calculate global coordinate of mosaic image and local coordinate of
        cropped sub-image.

        Args:
            loc (str): Index for the sub-image, loc in ('top_left',
              'top_right', 'bottom_left', 'bottom_right').
            center_position_xy (Sequence[float]): Mixing center for 4 images,
                (x, y).
            img_shape_wh (Sequence[int]): Width and height of sub-image

        Returns:
            tuple[tuple[float]]: Corresponding coordinate of pasting and
                cropping
                - paste_coord (tuple): paste corner coordinate in mosaic image.
                - crop_coord (tuple): crop corner coordinate in mosaic image.
        
Calculate global coordinate of mosaic image and local coordinate of
cropped sub-image.
Calculate global coordinate of mosaic image and local coordinate of cropped sub - image .
def _mosaic_combine(self, loc, center_position_xy, img_shape_wh):
        assert loc in ('top_left', 'top_right', 'bottom_left', 'bottom_right')
        if loc == 'top_left':
            x1, y1, x2, y2 = max(center_position_xy[0] - img_shape_wh[0], 0), \
                             max(center_position_xy[1] - img_shape_wh[1], 0), \
                             center_position_xy[0], \
                             center_position_xy[1]
            crop_coord = img_shape_wh[0] - (x2 - x1), img_shape_wh[1] - (
                    y2 - y1), img_shape_wh[0], img_shape_wh[1]
        elif loc == 'top_right':
            x1, y1, x2, y2 = center_position_xy[0], \
                             max(center_position_xy[1] - img_shape_wh[1], 0), \
                             min(center_position_xy[0] + img_shape_wh[0],
                                 self.img_scale[1] * 2), \
                             center_position_xy[1]
            crop_coord = 0, img_shape_wh[1] - (y2 - y1), min(
                img_shape_wh[0], x2 - x1), img_shape_wh[1]
        elif loc == 'bottom_left':
            x1, y1, x2, y2 = max(center_position_xy[0] - img_shape_wh[0], 0), \
                             center_position_xy[1], \
                             center_position_xy[0], \
                             min(self.img_scale[0] * 2, center_position_xy[1] +
                                 img_shape_wh[1])
            crop_coord = img_shape_wh[0] - (x2 - x1), 0, img_shape_wh[0], min(
                y2 - y1, img_shape_wh[1])
        else:
            x1, y1, x2, y2 = center_position_xy[0], \
                             center_position_xy[1], \
                             min(center_position_xy[0] + img_shape_wh[0],
                                 self.img_scale[1] * 2), \
                             min(self.img_scale[0] * 2, center_position_xy[1] +
                                 img_shape_wh[1])
            crop_coord = 0, 0, min(img_shape_wh[0],
                                   x2 - x1), min(y2 - y1, img_shape_wh[1])
        paste_coord = x1, y1, x2, y2
        return paste_coord, crop_coord
def _mosaic_combine ( self , loc , center_position_xy , img_shape_wh ) : assert loc in ( 'top_left' , 'top_right' , 'bottom_left' , 'bottom_right' ) if loc == 'top_left' : x1 , y1 , x2 , y2 = max ( center_position_xy [ 0 ] - img_shape_wh [ 0 ] , 0 ) , max ( center_position_xy [ 1 ] - img_shape_wh [ 1 ] , 0 ) , center_position_xy [ 0 ] , center_position_xy [ 1 ] crop_coord = img_shape_wh [ 0 ] - ( x2 - x1 ) , img_shape_wh [ 1 ] - ( y2 - y1 ) , img_shape_wh [ 0 ] , img_shape_wh [ 1 ] elif loc == 'top_right' : x1 , y1 , x2 , y2 = center_position_xy [ 0 ] , max ( center_position_xy [ 1 ] - img_shape_wh [ 1 ] , 0 ) , min ( center_position_xy [ 0 ] + img_shape_wh [ 0 ] , self . img_scale [ 1 ] * 2 ) , center_position_xy [ 1 ] crop_coord = 0 , img_shape_wh [ 1 ] - ( y2 - y1 ) , min ( img_shape_wh [ 0 ] , x2 - x1 ) , img_shape_wh [ 1 ] elif loc == 'bottom_left' : x1 , y1 , x2 , y2 = max ( center_position_xy [ 0 ] - img_shape_wh [ 0 ] , 0 ) , center_position_xy [ 1 ] , center_position_xy [ 0 ] , min ( self . img_scale [ 0 ] * 2 , center_position_xy [ 1 ] + img_shape_wh [ 1 ] ) crop_coord = img_shape_wh [ 0 ] - ( x2 - x1 ) , 0 , img_shape_wh [ 0 ] , min ( y2 - y1 , img_shape_wh [ 1 ] ) else : x1 , y1 , x2 , y2 = center_position_xy [ 0 ] , center_position_xy [ 1 ] , min ( center_position_xy [ 0 ] + img_shape_wh [ 0 ] , self . img_scale [ 1 ] * 2 ) , min ( self . img_scale [ 0 ] * 2 , center_position_xy [ 1 ] + img_shape_wh [ 1 ] ) crop_coord = 0 , 0 , min ( img_shape_wh [ 0 ] , x2 - x1 ) , min ( y2 - y1 , img_shape_wh [ 1 ] ) paste_coord = x1 , y1 , x2 , y2 return paste_coord , crop_coord
Calculate global coordinate of mosaic image and local coordinate of
cropped sub-image.
Calculate global coordinate of mosaic image and local coordinate of cropped sub - image .
"""Calculate global coordinate of mosaic image and local coordinate of
        cropped sub-image.

        Args:
            loc (str): Index for the sub-image, loc in ('top_left',
              'top_right', 'bottom_left', 'bottom_right').
            center_position_xy (Sequence[float]): Mixing center for 4 images,
                (x, y).
            img_shape_wh (Sequence[int]): Width and height of sub-image

        Returns:
            tuple[tuple[float]]: Corresponding coordinate of pasting and
                cropping
                - paste_coord (tuple): paste corner coordinate in mosaic image.
                - crop_coord (tuple): crop corner coordinate in mosaic image.
        """ # index0 to top left part of image # index1 to top right part of image # index2 to bottom left part of image # index3 to bottom right part of image
Corresponding coordinate of pasting and
cropping
paste_coord (tuple): paste corner coordinate in mosaic image.
crop_coord (tuple): crop corner coordinate in mosaic image.
Corresponding coordinate of pasting and cropping paste_coord ( tuple ) : paste corner coordinate in mosaic image . crop_coord ( tuple ) : crop corner coordinate in mosaic image .
tuple[tuple[float]]
self
loc
Index for the sub-image, loc in ('top_left',
'top_right', 'bottom_left', 'bottom_right').
Index for the sub - image loc in ( ' top_left ' ' top_right ' ' bottom_left ' ' bottom_right ' ) .
center_position_xy
Mixing center for 4 images,
(x, y).
Mixing center for 4 images ( x y ) .
img_shape_wh
Width and height of sub-image
Width and height of sub - image