kitcar_ml.utils.data_generation package

Submodules

kitcar_ml.utils.data_generation.augmentation_utils module

Functions:

gaussian_noise(img, sigma, mean)

Add gaussian noise to image.

add_random_intensity_and_contrast(img, ...)

Add intensity/contrast to image.

adapt_contrast_and_mean(img, dev_bckg_img)

Adapt contrast/mean of img to background.

supersample(img, s)

Supersample (resize) given image.

revert_supersampling(img, s)

Revert previous supersampling (resize) of given image.

add_object_to_background(background_img, ...)

Blend artificial image into background image.

gaussian_noise(img: ndarray, sigma: float, mean: float) ndarray[source]

Add gaussian noise to image.

add_random_intensity_and_contrast(img: ndarray, sigma_all: float, mean_all: float, gauss_blur_all: float)[source]

Add intensity/contrast to image.

adapt_contrast_and_mean(img: ndarray, dev_bckg_img: float)[source]

Adapt contrast/mean of img to background.

supersample(img: ndarray, s: float) ndarray[source]

Supersample (resize) given image.

revert_supersampling(img: ndarray, s: float) ndarray[source]

Revert previous supersampling (resize) of given image.

add_object_to_background(background_img: ndarray, aug_img: ndarray, img_coords: ndarray, noise_sigma: float, noise_mean: float, gauss_blur_sign: int, bckg_img_stddev: float, hor_motion_blur_size: int) ndarray[source]

Blend artificial image into background image.

Parameters
  • background_img – Image without the current generation.

  • aug_img – Pattern that should be inserted into background image.

  • img_coords – Coordinates where to insert the aug_img.

  • noise_mean – Mean of the noise.

  • noise_sigma – Stddev of the noise.

  • gauss_blur_sign – Gaussian blur kernel size applied to aug_img.

  • bckg_img_stddev – Stddev of noise applied to the background img.

  • hor_motion_blur_size – Kernel size of motion blur applied in hor direction.

Returns

Background image with aug_img added to it.

kitcar_ml.utils.data_generation.data_generation_tool module

Functions:

run_tasks(func, input_images, num_workers)

main(image_dir[, config_path, ...])

run_tasks(func: Callable[[str], None], input_images: List[str], num_workers: int)[source]
main(image_dir: str, config_path: Optional[str] = None, path_dataset_generated: str = '.', augmentation_files: str = './images_to_be_inserted', seed: int = 1, ts_sizes_path: Optional[str] = None, camera_specs_path: Optional[str] = None, oversampling_rate: int = 1, num_workers: int = 4)[source]

kitcar_ml.utils.data_generation.generation_config module

Classes:

GenerationConfiguration(supersampling, ...)

class GenerationConfiguration(supersampling: int, max_number_of_objects: int, min_distance: float, max_distance: float, angle_x_max: float, angle_z_max: float, noise_sigma: float, noise_mean: float, gauss_blur_all: float, gauss_blur_sign: float, overlay_treshold: float, sigma_all: float, mean_all: float, crop_box: List[int], bbox_min_visibility: float, bbox_min_area: int, hor_motion_blur_size: float)[source]

Bases: InitOptions

Attributes:

supersampling

max_number_of_objects

min_distance

max_distance

angle_x_max

angle_z_max

noise_sigma

noise_mean

gauss_blur_all

gauss_blur_sign

overlay_treshold

sigma_all

mean_all

crop_box

bbox_min_visibility

bbox_min_area

hor_motion_blur_size

supersampling: int
max_number_of_objects: int
min_distance: float
max_distance: float
angle_x_max: float
angle_z_max: float
noise_sigma: float
noise_mean: float
gauss_blur_all: float
gauss_blur_sign: float
overlay_treshold: float
sigma_all: float
mean_all: float
crop_box: List[int]
bbox_min_visibility: float
bbox_min_area: int
hor_motion_blur_size: float

kitcar_ml.utils.data_generation.object_generation_utils module

Functions:

calculate_overlay(bb_old, bb_new)

clean_bbox(x_coords, y_coords, crop_box, ...)

Sort/Clip coordinates and filter invalid/overlayed bboxes.

sample_objects(number_of_objects, name_list, ...)

Try to create randomized objects that have valid bboxes.

add_objects_to_image(max_number_of_objects, ...)

Add multiple objects to image.

create_artificial_objects_in_image(image, ...)

Add artificial objects to the given image.

load_and_create_artificial_images(img_names, ...)

Load provided images and generate synthetic images out of them.

Classes:

GeneratedObject(img_coords, aug_idx, label)

calculate_overlay(bb_old, bb_new)[source]
clean_bbox(x_coords: Sequence[int], y_coords: Sequence[int], crop_box: Tuple[int, int, int, int], min_visibility, min_area, max_overlay, other_bboxes) Optional[Tuple[int, int, int, int]][source]

Sort/Clip coordinates and filter invalid/overlayed bboxes.

class GeneratedObject(img_coords: Sequence[int], aug_idx: int, label: str)[source]

Bases: object

Attributes:

img_coords

aug_idx

label

img_coords: Sequence[int]
aug_idx: int
label: str
sample_objects(number_of_objects: int, name_list: List[str], sample_generator: SampleGenerator, angle_x_max: float, angle_z_max: float, overlay_trshld: float, crop_box: float, bbox_min_visibility: float, bbox_min_area: int) List[GeneratedObject][source]

Try to create randomized objects that have valid bboxes.

add_objects_to_image(max_number_of_objects: int, name_list: List[str], aug_images: List[ndarray], input_image: ndarray, sample_generator: SampleGenerator, supersampling: float, angle_x_max: float, angle_z_max: float, noise_sigma: float, noise_mean: float, gauss_blur_sign: float, overlay_trshld: float, crop_box: float, bbox_min_visibility: float, bbox_min_area: int, hor_motion_blur_size: int) Tuple[ndarray, List[str]][source]

Add multiple objects to image.

Parameters
  • max_number_of_objects – # of inserted objects.

  • name_list – Names of available objects.

  • aug_images – Available generation images.

  • input_image – Image that should be altered.

  • sample_generator – Generator of sample points for generations.

  • supersampling – Supersampling factor.

  • angle_x_max – Maximum rotation of generation around x axis.

  • angle_z_max – Maximum rotation of generation in z axis (after x rotation).

  • noise_sigma – Stddev of noise applied to generation image.

  • noise_mean – Mean of noise applied to generation image.

  • gauss_blur_sign – Filter kernel size of gaussian blur.

  • overlay_trshld – Threshold of max. overlay between two generations.

  • crop_box – ROI.

  • min_pxl_size – Minimal size of generation in pixels.

  • bbox_min_visibility – Minimal portion of generated bbox that is visible.

  • bbox_min_area – Minimal area of generated bbox.

  • hor_motion_blur_size – Kernel size of motion blur applied in hor direction.

Returns

Augmented image and list of labels.

create_artificial_objects_in_image(image: List[ndarray], config: GenerationConfiguration, name_list, aug_images, sample_generator) Tuple[ndarray, List[str]][source]

Add artificial objects to the given image.

The objects are sampled from aug_images and added as labels to the dataset.

Parameters
  • image – Image.

  • config_data – Configurations; e.g. max number of objects in one image.

  • name_list – Class names of objects.

  • aug_images – Images of the objects (e.g. image of a stop sign)

  • sample_generator – Generator of positions in vehicle coordinates.

  • dataset – Dataset

  • naming_convention – Callable that returns a unique name for each index.

Returns

Altered image and labels.

load_and_create_artificial_images(img_names: List[str], dataset, config, name_list, aug_images, sample_generator)[source]

Load provided images and generate synthetic images out of them.

Parameters
  • img_names – Names(paths) to all images that should be used.

  • dataset – The dataset.

  • config – Configuration of the image generation.

  • name_list – Names of available generations.

  • aug_images – Available generation images.

  • sample_generator – Generator of sample points for generations.

kitcar_ml.utils.data_generation.sample_generator module

Classes:

SampleGenerator(camera_specs_path, ...)

class SampleGenerator(camera_specs_path, ts_sizes_path, min_distance, max_distance)[source]

Bases: object

Attributes:

camera_specs

Camera specification including calibration.

ts_sizes

Sizes of all traffic signs.

min_distance

Minimal distance to generated sign.

max_distance

Maximal distance to generated sign.

Methods:

sample_world_vec()

Sample vector to point in the fov.

_H(height)

Calculate transform from vehicle coords to img at a given height.

vehicle_point_to_img(vec)

Transform vector in vehicle coords to pixel.

sign_coords(sign_name, angle_x, angle_z)

Calculate rotated sign coordinates.

camera_specs: CameraSpecs

Camera specification including calibration.

ts_sizes: Dict[str, Tuple[float, float, float]]

Sizes of all traffic signs.

min_distance: float

Minimal distance to generated sign.

max_distance: float

Maximal distance to generated sign.

sample_world_vec() Vector[source]

Sample vector to point in the fov.

_H(height: float) matrix[source]

Calculate transform from vehicle coords to img at a given height.

vehicle_point_to_img(vec: Vector) ndarray[source]

Transform vector in vehicle coords to pixel.

sign_coords(sign_name: str, angle_x: float, angle_z: float) List[Vector][source]

Calculate rotated sign coordinates.

Parameters
  • sign_name – Name of the sign.

  • angle_x – Rotation around x axis.

  • angle_z – Rotation around z axis.

kitcar_ml.utils.data_generation.utils module

Functions:

read_augmentation_data(...)

Read augmentation images and file names.

create_dataset(path_dataset_generated, ...)

Create dataset.

write_annotations_to_dataset(dataset, name, ...)

read_augmentation_data(path_to_augmentation_images: str) Tuple[List[ndarray], List[str]][source]

Read augmentation images and file names.

create_dataset(path_dataset_generated: str, class_names: List[str]) LabeledDataset[source]

Create dataset.

Parameters
  • path_dataset_generated – Path to dataset directory.

  • class_names – Classes added to dataset.

write_annotations_to_dataset(dataset: LabeledDataset, name, sample_data)[source]

Module contents