如何让图像通过由概率权重确定的许多函数?

问题描述

我有一个标志。我现在正在做的是为所有这些函数设置概率权重,并且徽标一次只出现在其中一个,具体取决于其概率值。这是我的代码

augmentation_func = [(random_rotation,[brand_logo]),(blurring,(compression,(portion_covering,[brand_logo,brand_logo_width,brand_logo_height]),(perspective_transform,[logo_image,(overlaying,[logo_path]),(logo_background,[logo_path])]

        (augs,args),= random.choices(augmentation_func,weights=[10,5,15,20,15])

        new_logo = random_resize(augs(*args),gameplay)

然而,这还不够。标志应该能够通过多种功能。例如。徽标可能会通过 random_rotation()perspective_transformation()overlaying()。它是否会通过一个函数应该取决于它的概率权重。这是我的想法:

enter image description here

如何调整我的代码,以便徽标根据权重经历许多转换函数

解决方法

每个操作发生的机会是否独立于其他操作?那么 random.choice() 不是正确的解决方案,因为它只选择了一项。相反,对于每个项目,以其相应的概率选择它。例如:

if random.randrange(0,100) < 10:
    # Crop the image (in place) at a 10% chance.
    # The chance of cropping is independent
    # of the chances of any other operation.
    brand_logo = cropping(brand_logo)
    
if random.randrange(0,100) < 15:
    # Rotate the image (in place) at a 15% chance.
    # The chance of rotating is independent
    # of the chances of any other operation.
    brand_logo = rotating(brand_logo)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...