<jupyter_start><jupyter_text><jupyter_code>!pip install augmixations
import cv2
import numpy as np
from matplotlib import pyplot as plt
from augmixations import Cutout<jupyter_output><empty_output><jupyter_text>Help functions<jupyter_code>def show_img(image, figsize=(4, 6), title=None):
    img = image.copy()
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    plt.figure(figsize=figsize)
    plt.title(title)
    plt.imshow(img)
    plt.axis(False)
    plt.show()

def create_img_with_circle(img_h=500, img_w=500, xc=250, yc=250,r=100, color=(150, 150, 150)):
    label = 'circle'
    img = np.ones((img_h, img_w, 3), dtype=np.uint8)*255
    img = cv2.circle(img, (xc, yc), r, color, -1)
    return img, np.array([np.array([xc -  r, xc - r, xc + r, xc + r])]), np.array([label])

def draw_boxes(new_img, boxes, labels):
    frame = new_img.copy()
    
    for (x1, y1, x2, y2), label in zip(boxes, labels): 
        thickness = 2
        font_scale = 1
    
        frame = cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 3)
        frame = cv2.putText(frame, label, (int(x1), int(y1 - 15)), cv2.FONT_HERSHEY_SIMPLEX ,  
                                   font_scale, (0, 0, 255), thickness, cv2.LINE_AA) 
        
    return frame<jupyter_output><empty_output><jupyter_text>Create images<jupyter_code>img, boxes, labels = create_img_with_circle()
marked_img = draw_boxes(img, boxes, labels)
show_img(marked_img)<jupyter_output><empty_output><jupyter_text>Simple usage<jupyter_code>cutmix = Cutout()
new_img, new_boxes, new_labels = cutmix(
                            img, 
                            boxes,
                            labels,
                           )

marked_img = draw_boxes(new_img, new_boxes, new_labels)
show_img(marked_img)<jupyter_output><empty_output><jupyter_text>Advanced usage (with configs)<jupyter_code>cr_config = {
    'crop_x': (None, None),
    'crop_y': (None, None),
    'rect_h': (50, 400),
    'rect_w': (50, 400),
    'transparency': (0.0, 0.5),
    'hole_nums': (2, 5),
}

pb_config = {
    'transp_box_visibility': 0.1,
    'max_overlap_area_ratio': 0.75,
    'min_height_result_ratio': 0.25,
    'min_width_result_ratio': 0.25,
    'max_height_intersection': 0.9,
    'max_width_intersection': 0.9,
}
cutout = Cutout(cr_config, pb_config)
new_img, new_boxes, new_labels = cutout(img, boxes, labels)

marked_img = draw_boxes(new_img, new_boxes, new_labels)
show_img(marked_img)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1389114541023558, 'fraction_numerical': 0.039398862713241264, 'mean_word_length': 3.429856115107914, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '434773', 'license': 'MIT', 'n_tokens_mistral': 1023, 'n_tokens_neox': 952, 'n_words': 182, 'path': 'examples/cutout_example.ipynb', 'repo_name': 'TheDenk/augmixations', 'size': '2462'}