Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moe updates #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -142,6 +142,25 @@
"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": "Apply motion blur?",
"value": false,
Expand Down
17 changes: 15 additions & 2 deletions transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
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('--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")
Expand Down Expand Up @@ -74,6 +76,8 @@
num_objects = args.objects
allow_overlap = args.allow_overlap
allow_rotate = args.allow_rotate
apply_resize = args.apply_resize
resize_percentage = args.resize_percentage
crop_object_outside_area = args.crop_object_outside_area
apply_motion_blur = args.apply_motion_blur
blur_direction = args.motion_blur_direction
Expand Down Expand Up @@ -330,6 +334,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):
Expand Down Expand Up @@ -363,8 +369,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:
Expand Down Expand Up @@ -474,6 +485,8 @@ 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),
'apply_motion_blur': str(args.apply_motion_blur),
'motion_blur_direction': str(args.motion_blur_direction),
'object_area': str(args.object_area),
Expand Down