-
Notifications
You must be signed in to change notification settings - Fork 1
Changing Object Color
Trey Woodlief edited this page May 30, 2022
·
1 revision
In the implementation (Section 4) of the paper, we discuss two classes of mutation, Changing Object Color (Section 4.2) and Adding Entities (Section 4.3). This page discusses additional algorithmic details for the implementation of the Changing Object Color mutation.
The main algorithm is implemented in image_mutator.py
in the function change_instance_color(semantic_label, poly_id, color_shift, dec_lit, inc_sat)
, available here.
The function parameters are:
-
semantic_label
- astring
indicating the semantic label of the entity to recolor. This must be a class recognized by the underlying dataset. The default value iscar
as used in the study. -
poly_id
- the unique identifier of the entity to recolor. This identifier corresponds to the identifier used in the underlying dataset. This parameter defaults toNone
, in which case the algorithm will select an entity semi-randomly. Specifying this parameter is mainly used to reproduce a previously performed mutation. -
color_shift
- the amount to change the color of the original entity. This parameter defaults toNone
, in which case the algorithm will randomly select an amount. Units are specified in degrees of Hue from the HSL color space. Specifying this parameter is mainly used to reproduce a previously performed mutation. -
dec_lit
- the amount to decrease the lightness of the entity after performing the color shift. This parameter defaults toNone
, in which case the algorithm will determine if this is needed and how much to apply (see below). Units are specified in amount of lightness from the HSL color space. Specifying this parameter is mainly used to reproduce a previously performed mutation. -
inc_sat
- the amount to increase the saturation of the entity after performing the color shift. This parameter defaults toNone
, in which case the algorithm will determine if this is needed and how much to apply (see below). Units are specified in amount of saturation from the HSL color space. Specifying this parameter is mainly used to reproduce a previously performed mutation.
- Randomly select the entity to recolor if not already provided (here)
- Select amount to change hue if not provided. Amount selected is between [45, 135]. (here). The reason for changing by at least 45 degrees is to ensure that the new color is sufficiently different from the old color. Not changing by more than 135 ensures that successive applications of this mutation (not studied in our experiments) will not "wrap" around to the same color immediately.
- Conformity Checking. Because of how the HSL color space handles very bright colors, changing the hue of a very bright (or white) car may not visibly change the color. To compensate, if the average lightness of the entity is greater than 100. If so, the lightness of those pixels with lightness over 100 is decreased by a random amount between 20 and 50 so that the color change will be visible. However, this decrease in lightness can cause colors to appear faded due to the way that the bright color was originally encoded. To combat this, the saturation of pixels whose saturation is less than 50 and lightness is greater than 100 is then increased by a random amount between 10 and 40.