Add code to generate mask images for training
Doc-UFCN needs specific mask images (one mask per image). The source code is already available in this project but it's dependant on Arkindex.
@NolanB already extracted the minimal source code for our training worker, so we should port this in a new module doc_ufcn.train.mask
.
This module should have 3 methods:
-
generate_mask(image_width, image_height, label_polygons, label_colors, output_path)
-
label_polygons
is a dict of list of polygons, where the key of each item is a label name -
label_colors
is a dict of RGB tuples
-
- dependant
resize_polygons
- dependant
split_polygons
# Example parameters
image_width = 500
image_height = 800
label_polygons = {
"text_line": [
[[0,0], [0, 100], ...
],
"picture": [
[[0,0], [0, 100], ...
],
}
label_colors = {
"text_line": (255, 0, 0), # red
"picture": (0, 0, 255), # blue
}
output_path = Path(path/to/file)
Rules:
- each label_polygons keys must have a matching label_colors
- check RGB structure (tuple or list of 3 integer items between 0 & 255)
- check polygons (tuple or list of list of 2 integer items, always positive)
- image width & height are positive integers