From c422f19c443f40587155138acc09a63a778a5e6a Mon Sep 17 00:00:00 2001 From: Moe Sani Date: Tue, 26 Nov 2024 09:52:24 +0000 Subject: [PATCH 1/3] minor fix --- parameters.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parameters.json b/parameters.json index 62cd342..de304e4 100644 --- a/parameters.json +++ b/parameters.json @@ -67,7 +67,7 @@ "value": "[voltagetester,100],[tape,50],[ringcrimp,25],[else,75]", "type": "string", "help": "Comma-separated list of pixel widths for each label in the format [label,width]. By default any non-mentioned labels will not be resized, you can change this by passing [else,75]", - "param": "custom-raw-resize", + "param": "custom-raw-resize-pixels", "showIf": { "parameter": "resize-raw-objects", "operator": "eq", From ce4a6efb1661e0d2ec43b9daf77e234f8091edb5 Mon Sep 17 00:00:00 2001 From: Moe Sani Date: Tue, 26 Nov 2024 16:45:18 +0000 Subject: [PATCH 2/3] added resizing feature --- parameters.json | 26 ++++++++++++++++++++++++++ transform.py | 20 ++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/parameters.json b/parameters.json index de304e4..ac7fd50 100644 --- a/parameters.json +++ b/parameters.json @@ -142,6 +142,32 @@ "help": "Whether to apply random rotation to objects", "param": "allow-rotate" }, + { + "name": "Apply resize", + "value": false, + "type": "boolean", + "help": "Whether to change the size of the objects", + "param": "apply-resize" + }, + { + "name": "Object size randomisation percantage", + "value": 50, + "type": "float", + "help": "How much change should be applied to object size? (in percentage)", + "param": "resize-percentage", + "showIf": { + "parameter": "apply-resize", + "operator": "eq", + "value": "true" + } + }, + { + "name": "Allow shadow?", + "value": false, + "type": "boolean", + "help": "Whether to change brightness to simulate shadow", + "param": "allow-shadow" + }, { "name": "Apply motion blur?", "value": false, diff --git a/transform.py b/transform.py index 8b2c939..d214641 100644 --- a/transform.py +++ b/transform.py @@ -35,6 +35,9 @@ parser.add_argument('--objects', type=int, required=True, help="Maximum number of objects to generate") parser.add_argument('--allow-overlap', type=int, required=True, help="Whether objects are allowed to overlap") parser.add_argument('--allow-rotate', type=int, required=True, help="Whether to apply random rotation to objects") +parser.add_argument('--apply-resize', type=int, required=True, help="Whether to change the size of the objects") +parser.add_argument('--resize-percentage', type=int, required=False, help="How much change should be applied to object size? (in percentage)") +parser.add_argument('--allow-shadow', type=int, required=True, help="Whether to change brightness to simulate shadow") parser.add_argument('--apply-motion-blur', type=int, required=True, help="Whether to apply blur to objects to simulate motion") parser.add_argument('--motion-blur-direction', type=int, required=False, help="What direction apply blur to objects to simulate motion (-1 for random)", default=-1) parser.add_argument('--object-area', type=str, required=True, help="x1,y1,x2,y2 coordinates of the valid area to place objects in the composite image") @@ -74,6 +77,9 @@ num_objects = args.objects allow_overlap = args.allow_overlap allow_rotate = args.allow_rotate +apply_resize = args.apply_resize +resize_percentage = args.resize_percentage +allow_shadow = args.allow_shadow crop_object_outside_area = args.crop_object_outside_area apply_motion_blur = args.apply_motion_blur blur_direction = args.motion_blur_direction @@ -330,6 +336,8 @@ def adjust_bounding_boxes(objects, width, height, crop_box, strength=0.5): print('Objects to be generated:', args.objects) print('Allow overlap:', args.allow_overlap) print('Object area:', object_area) +# print('MOE DEBUG: bg_images: ', bg_images) +# print('MOE DEBUG: obj_images: ', obj_images) print('') for i in range(base_images_number): @@ -363,8 +371,13 @@ def adjust_bounding_boxes(objects, width, height, crop_box, strength=0.5): if allow_rotate: object_image.rotate(random.uniform(0, 360)) - object_width = object_image.width - object_height = object_image.height + if apply_resize: + random_percentage = random.uniform(resize_percentage, 100) + object_width = int(object_image.width * (random_percentage / 100)) + object_height = int(object_image.height * (random_percentage / 100)) + else: + object_width = object_image.width + object_height = object_image.height object_image.resize(object_width, object_height) if apply_motion_blur: @@ -474,6 +487,9 @@ def adjust_bounding_boxes(objects, width, height, crop_box, strength=0.5): 'generated_by': 'composite-image-generator', 'allow_overlap': str(args.allow_overlap), 'allow_rotate': str(args.allow_rotate), + 'apply_resize': str(args.apply_resize), + 'resize_percentage': str(args.resize_percentage), + 'allow_shadow': str(args.allow_shadow), 'apply_motion_blur': str(args.apply_motion_blur), 'motion_blur_direction': str(args.motion_blur_direction), 'object_area': str(args.object_area), From 498f512c7b3e00c9f4f2892b92bcffde859820de Mon Sep 17 00:00:00 2001 From: Moe Sani Date: Tue, 17 Dec 2024 09:14:37 +0000 Subject: [PATCH 3/3] removed the shadows --- parameters.json | 7 ------- transform.py | 3 --- 2 files changed, 10 deletions(-) diff --git a/parameters.json b/parameters.json index ac7fd50..795fa15 100644 --- a/parameters.json +++ b/parameters.json @@ -161,13 +161,6 @@ "value": "true" } }, - { - "name": "Allow shadow?", - "value": false, - "type": "boolean", - "help": "Whether to change brightness to simulate shadow", - "param": "allow-shadow" - }, { "name": "Apply motion blur?", "value": false, diff --git a/transform.py b/transform.py index d214641..76f078e 100644 --- a/transform.py +++ b/transform.py @@ -37,7 +37,6 @@ parser.add_argument('--allow-rotate', type=int, required=True, help="Whether to apply random rotation to objects") parser.add_argument('--apply-resize', type=int, required=True, help="Whether to change the size of the objects") parser.add_argument('--resize-percentage', type=int, required=False, help="How much change should be applied to object size? (in percentage)") -parser.add_argument('--allow-shadow', type=int, required=True, help="Whether to change brightness to simulate shadow") parser.add_argument('--apply-motion-blur', type=int, required=True, help="Whether to apply blur to objects to simulate motion") parser.add_argument('--motion-blur-direction', type=int, required=False, help="What direction apply blur to objects to simulate motion (-1 for random)", default=-1) parser.add_argument('--object-area', type=str, required=True, help="x1,y1,x2,y2 coordinates of the valid area to place objects in the composite image") @@ -79,7 +78,6 @@ allow_rotate = args.allow_rotate apply_resize = args.apply_resize resize_percentage = args.resize_percentage -allow_shadow = args.allow_shadow crop_object_outside_area = args.crop_object_outside_area apply_motion_blur = args.apply_motion_blur blur_direction = args.motion_blur_direction @@ -489,7 +487,6 @@ def adjust_bounding_boxes(objects, width, height, crop_box, strength=0.5): 'allow_rotate': str(args.allow_rotate), 'apply_resize': str(args.apply_resize), 'resize_percentage': str(args.resize_percentage), - 'allow_shadow': str(args.allow_shadow), 'apply_motion_blur': str(args.apply_motion_blur), 'motion_blur_direction': str(args.motion_blur_direction), 'object_area': str(args.object_area),