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

Fixed possible color collisions in the generated colormap #4007

Merged
merged 11 commits into from
Dec 13, 2021

Conversation

azhavoro
Copy link
Contributor

@azhavoro azhavoro commented Dec 9, 2021

Motivation and context

How has this been tested?

Checklist

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below)
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT

Comment on lines 72 to 75
sorted_colors = sorted(used_colors)
max_dist = max(zip(sorted_colors, sorted_colors[1:]), key=lambda c_pair: c_pair[1][0] - c_pair[0][0])

return ((max_dist[0][0] + max_dist[1][0]) // 2, max_dist[0][1], max_dist[0][2])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @azhavoro, Is it the final version of this patch? If it is, then I have a question:
Will this solution work correctly if all used colors have a same R-value? For example in case:

used_colors = [(100, 0, 0), (100, 50, 0), (100, 0, 50)]

this code will return (100, 0, 0) but this color is already use. I'm not sure that such situation is very likely, but it seems to me that we can extend this algorithm to other components of the color as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, fixed.

if color is None:
color = get_color_from_index(DEFAULT_COLORMAP_CAPACITY + offset)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this const is not used, so should be deleted

Copy link
Contributor

@sizov-kirill sizov-kirill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link
Contributor

@nmanovic nmanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nmanovic nmanovic merged commit 23c80c4 into develop Dec 13, 2021
@nmanovic nmanovic deleted the az/color_generation branch December 13, 2021 20:16
@azhavoro
Copy link
Contributor Author

@dvkruchinin Hi, could you prepare a test for this case?

@dvkruchinin
Copy link
Contributor

@dvkruchinin Hi, could you prepare a test for this case?

Hi, sure. A test will be prepared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants