pascal_voc_tools.Augmenter package¶
Submodules¶
pascal_voc_tools.Augmenter.bbox_util module¶
-
pascal_voc_tools.Augmenter.bbox_util.bbox_area(bbox)¶
-
pascal_voc_tools.Augmenter.bbox_util.clip_box(bbox, clip_box, alpha)¶ Clip the bounding boxes to the borders of an image
Parameters: - bbox (numpy.ndarray) – Numpy array containing bounding boxes of shape N X 4 where N is the number of bounding boxes and the bounding boxes are represented in the format x1 y1 x2 y2
- clip_box (numpy.ndarray) – An array of shape (4,) specifying the diagonal co-ordinates of the image The coordinates are represented in the format x1 y1 x2 y2
- alpha (float) – If the fraction of a bounding box left in the image after being clipped is less than alpha the bounding box is dropped.
Returns: Numpy array containing clipped bounding boxes of shape N X 4 where N is the number of bounding boxes left are being clipped and the bounding boxes are represented in the format x1 y1 x2 y2
Return type: numpy.ndarray
-
pascal_voc_tools.Augmenter.bbox_util.draw_rect(im, cords, color=None)¶ Draw the rectangle on the image
Parameters: - im (numpy.ndarray) – numpy image
- cords (numpy.ndarray) – Numpy array containing bounding boxes of shape N X 4 where N is the number of bounding boxes and the bounding boxes are represented in the format x1 y1 x2 y2
Returns: numpy image with bounding boxes drawn on it
Return type: numpy.ndarray
-
pascal_voc_tools.Augmenter.bbox_util.get_corners(bboxes)¶ Get corners of bounding boxes
Parameters: bboxes (numpy.ndarray) – Numpy array containing bounding boxes of shape N X 4 where N is the number of bounding boxes and the bounding boxes are represented in the format x1 y1 x2 y2 Returns: Numpy array of shape N x 8 containing N bounding boxes each described by their corner co-ordinates x1 y1 x2 y2 x3 y3 x4 y4 Return type: numpy.ndarray
-
pascal_voc_tools.Augmenter.bbox_util.get_enclosing_box(corners)¶ Get an enclosing box for ratated corners of a bounding box
Parameters: corners (numpy.ndarray) – Numpy array of shape N x 8 containing N bounding boxes each described by their corner co-ordinates x1 y1 x2 y2 x3 y3 x4 y4 Returns: Numpy array containing enclosing bounding boxes of shape N X 4 where N is the number of bounding boxes and the bounding boxes are represented in the format x1 y1 x2 y2 Return type: numpy.ndarray
-
pascal_voc_tools.Augmenter.bbox_util.letterbox_image(img, inp_dim)¶ resize image with unchanged aspect ratio using padding
Parameters: - img (numpy.ndarray) – Image
- inp_dim (tuple(int)) – shape of the reszied image
Returns: Resized image
Return type: numpy.ndarray
-
pascal_voc_tools.Augmenter.bbox_util.rotate_box(corners, angle, cx, cy, h, w)¶ Rotate the bounding box.
Parameters: - corners (numpy.ndarray) – Numpy array of shape N x 8 containing N bounding boxes each described by their corner co-ordinates x1 y1 x2 y2 x3 y3 x4 y4
- angle (float) – angle by which the image is to be rotated
- cx (int) – x coordinate of the center of image (about which the box will be rotated)
- cy (int) – y coordinate of the center of image (about which the box will be rotated)
- h (int) – height of the image
- w (int) – width of the image
Returns: Numpy array of shape N x 8 containing N rotated bounding boxes each described by their corner co-ordinates x1 y1 x2 y2 x3 y3 x4 y4
Return type: numpy.ndarray
-
pascal_voc_tools.Augmenter.bbox_util.rotate_im(image, angle)¶ Rotate the image.
Rotate the image such that the rotated image is enclosed inside the tightest rectangle. The area not occupied by the pixels of the original image is colored black.
Parameters: - image (numpy.ndarray) – numpy image
- angle (float) – angle by which the image is to be rotated
Returns: Rotated Image
Return type: numpy.ndarray
pascal_voc_tools.Augmenter.data_aug module¶
-
class
pascal_voc_tools.Augmenter.data_aug.HorizontalFlip¶ Bases:
objectRandomly horizontally flips the Image with the probability p
Parameters: p (float) – The probability with which the image is flipped Returns: - numpy.ndaaray – Flipped image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.RandomHSV(hue=None, saturation=None, brightness=None)¶ Bases:
objectHSV Transform to vary hue saturation and brightness
Hue has a range of 0-179 Saturation and Brightness have a range of 0-255. Chose the amount you want to change thhe above quantities accordingly.
Parameters: - hue (None or int or tuple (int)) – If None, the hue of the image is left unchanged. If int, a random int is uniformly sampled from (-hue, hue) and added to the hue of the image. If tuple, the int is sampled from the range specified by the tuple.
- saturation (None or int or tuple(int)) – If None, the saturation of the image is left unchanged. If int, a random int is uniformly sampled from (-saturation, saturation) and added to the hue of the image. If tuple, the int is sampled from the range specified by the tuple.
- brightness (None or int or tuple(int)) – If None, the brightness of the image is left unchanged. If int, a random int is uniformly sampled from (-brightness, brightness) and added to the hue of the image. If tuple, the int is sampled from the range specified by the tuple.
Returns: - numpy.ndaaray – Transformed image in the numpy format of shape HxWxC
- numpy.ndarray – Resized bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.RandomHorizontalFlip(p=0.5)¶ Bases:
objectRandomly horizontally flips the Image with the probability p
Parameters: p (float) – The probability with which the image is flipped Returns: - numpy.ndaaray – Flipped image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.RandomRotate(angle=10)¶ Bases:
objectRandomly rotates an image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: angle (float or tuple(float)) – if float, the image is rotated by a factor drawn randomly from a range (-angle, angle). If tuple, the angle is drawn randomly from values specified by the tuple Returns: - numpy.ndaaray – Rotated image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.RandomScale(scale=0.2, diff=False)¶ Bases:
objectRandomly scales an image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: scale (float or tuple(float)) – if float, the image is scaled by a factor drawn randomly from a range (1 - scale , 1 + scale). If tuple, the scale is drawn randomly from values specified by the tuple Returns: - numpy.ndaaray – Scaled image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.RandomShear(shear_factor=0.2)¶ Bases:
objectRandomly shears an image in horizontal direction
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: shear_factor (float or tuple(float)) – if float, the image is sheared horizontally by a factor drawn randomly from a range (-shear_factor, shear_factor). If tuple, the shear_factor is drawn randomly from values specified by the tuple Returns: - numpy.ndaaray – Sheared image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.RandomTranslate(translate=0.2, diff=False)¶ Bases:
objectRandomly Translates the image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: translate (float or tuple(float)) – if float, the image is translated by a factor drawn randomly from a range (1 - translate , 1 + translate). If tuple, translate is drawn randomly from values specified by thetuple Returns: - numpy.ndaaray – Translated image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.Resize(inp_dim)¶ Bases:
objectResize the image in accordance to image_letter_box function in darknet
The aspect ratio is maintained. The longer side is resized to the input size of the network, while the remaining space on the shorter side is filled with black color. This should be the last transform
Parameters: inp_dim (tuple(int)) – tuple containing the size to which the image will be resized. Returns: - numpy.ndaaray – Sheared image in the numpy format of shape HxWxC
- numpy.ndarray – Resized bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.Rotate(angle)¶ Bases:
objectRotates an image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: angle (float) – The angle by which the image is to be rotated Returns: - numpy.ndaaray – Rotated image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.Scale(scale_x=0.2, scale_y=0.2)¶ Bases:
objectScales the image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: - scale_x (float) – The factor by which the image is scaled horizontally
- scale_y (float) – The factor by which the image is scaled vertically
Returns: - numpy.ndaaray – Scaled image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.Sequence(augmentations, probs=1)¶ Bases:
objectInitialise Sequence object
Apply a Sequence of transformations to the images/boxes.
Parameters: - augemnetations (list) – List containing Transformation Objects in Sequence they are to be applied
- probs (int or list) – If int, the probability with which each of the transformation will be applied. If list, the length must be equal to augmentations. Each element of this list is the probability with which each corresponding transformation is applied
Returns: Sequence Object
Return type:
-
class
pascal_voc_tools.Augmenter.data_aug.Shear(shear_factor=0.2)¶ Bases:
objectShears an image in horizontal direction
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: shear_factor (float) – Factor by which the image is sheared in the x-direction Returns: - numpy.ndaaray – Sheared image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box
-
class
pascal_voc_tools.Augmenter.data_aug.Translate(translate_x=0.2, translate_y=0.2, diff=False)¶ Bases:
objectRandomly Translates the image
Bounding boxes which have an area of less than 25% in the remaining in the transformed image is dropped. The resolution is maintained, and the remaining area if any is filled by black color.
Parameters: translate (float or tuple(float)) – if float, the image is translated by a factor drawn randomly from a range (1 - translate , 1 + translate). If tuple, translate is drawn randomly from values specified by the tuple Returns: - numpy.ndaaray – Translated image in the numpy format of shape HxWxC
- numpy.ndarray – Tranformed bounding box co-ordinates of the format n x 4 where n is number of bounding boxes and 4 represents x1,y1,x2,y2 of the box