pe.api.image.draw_text_api module
- class pe.api.image.draw_text_api.DrawText(font_root_path, font_variation_degrees, font_size_variation_degrees, rotation_degree_variation_degrees, stroke_width_variation_degrees, text_list=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], width=28, height=28, background_color=(0, 0, 0), text_color=(255, 255, 255), font_size_list=range(10, 30), stroke_width_list=[0, 1, 2], rotation_degree_list=range(-30, 31))[source]
Bases:
API
The API that uses the PIL library to generate synthetic images with text on them.
- __init__(font_root_path, font_variation_degrees, font_size_variation_degrees, rotation_degree_variation_degrees, stroke_width_variation_degrees, text_list=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], width=28, height=28, background_color=(0, 0, 0), text_color=(255, 255, 255), font_size_list=range(10, 30), stroke_width_list=[0, 1, 2], rotation_degree_list=range(-30, 31))[source]
Constructor.
- Parameters:
font_root_path (str) – The root path that contains the font files in .ttf format
font_variation_degrees (float or list[float]) – The variation degrees for font utilized at each PE iteration. If a single value is provided, the same variation degree will be used for all iterations. The value means the probability of changing the font to a random font.
font_size_variation_degrees (int or list[int]) – The variation degrees for font size utilized at each PE iteration. If a single value is provided, the same variation degree will be used for all iterations. The value means the maximum possible variation in font size.
rotation_degree_variation_degrees (int or list[int]) – The variation degrees for rotation degree utilized at each PE iteration. If a single value is provided, the same variation degree will be used for all iterations. The value means the maximum possible variation in rotation degree.
stroke_width_variation_degrees (int or list[int]) – The variation degrees for stroke width utilized at each PE iteration. If a single value is provided, the same variation degree will be used for all iterations. The value means the maximum possible variation in stroke width.
text_list (list or dict, optional) – The texts to be used in the synthetic images. It can be a dictionary that maps label_names to a list of strings, meaning the texts to be used for each label_name. If a list is provided, the same texts will be used for all label_names. Defaults to [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]
width (int, optional) – The width of the synthetic images, defaults to 28
height (int, optional) – The height of the synthetic images, defaults to 28
background_color (tuple, optional) – The background color of the synthetic images, defaults to (0, 0, 0)
text_color (tuple, optional) – The text color of the synthetic images, defaults to (255, 255, 255)
font_size_list (list, optional) – The feasible set of font sizes to be used in the synthetic images, defaults to range(10, 30)
stroke_width_list (list, optional) – The feasible set of stroke widths to be used in the synthetic images, defaults to [0, 1, 2]
rotation_degree_list (list, optional) – The feasible set of rotation degrees to be used in the synthetic images, defaults to range(-30, 31, 1)
- _create_image(font_size, font_file, text, stroke_width, rotation_degree)[source]
Create an image with text on it.
- Parameters:
font_size (int) – The font size
font_file (str) – The font file
text (str) – The text
stroke_width (int) – The stroke width
rotation_degree (int) – The rotation degree
- Returns:
The image with text on it
- Return type:
np.ndarray
- _get_random_image(label_name)[source]
Get a random image and its parameters.
- Parameters:
label_name (str) – The label name
- Returns:
The image and its parameters
- Return type:
tuple[np.ndarray, dict]
- _get_variation_image(font_size, font_file, text, stroke_width, rotation_degree, font_size_variation_degree, font_variation_degree, stroke_width_variation_degree, rotation_degree_variation_degree)[source]
Get a variation image and its parameters.
- Parameters:
font_size (int) – The font size
font_file (str) – The font file
text (str) – The text
stroke_width (int) – The stroke width
rotation_degree (int) – The rotation degree
font_size_variation_degree (int) – The degree of variation in font size
font_variation_degree (float) – The degree of variation in font
stroke_width_variation_degree (int) – The degree of variation in stroke width
rotation_degree_variation_degree (int) – The degree of variation in rotation degree
- Returns:
The image of the avatar and its parameters
- Return type:
tuple[np.ndarray, dict]
- random_api(label_info, num_samples)[source]
Generating random synthetic data.
- Parameters:
label_info (omegaconf.dictconfig.DictConfig) – The info of the label
num_samples (int) – The number of random samples to generate
- Returns:
The data object of the generated synthetic data
- Return type:
- variation_api(syn_data)[source]
Creating variations of the synthetic data.
- Parameters:
syn_data (
pe.data.Data
) – The data object of the synthetic data- Returns:
The data object of the variation of the input synthetic data
- Return type: