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

Added function to find the dominant color of a given image and added formatting markdown files #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

TushigBili
Copy link

Overview

For score, we need the opponent's dominant color on the banner for a game, so we wrote a function that finds the dominant color in an image given a URL. Additionally, we added markdown files that outline the format of pull requests on the repository and a general outline contributors should follow when making changes to the repository.

Changes Made

Added a function to helpers.py in the utils folder
Added markdown files to the .github folder

Copy link

@Aayush-Agnihotri Aayush-Agnihotri left a comment

Choose a reason for hiding this comment

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

LGTM

return dominant_color

dominant_color = get_dominant_color("https://cornellbigred.com/images/logos/harvardlogo.png?width=50")
print("Dominant color:", dominant_color)

Choose a reason for hiding this comment

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

remove the test

from io import BytesIO
from collections import Counter

def get_dominant_color(image_url, threshold=200):

Choose a reason for hiding this comment

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

Does this account for colors that are slightly different from each other? Like if there are 10 pixels with (1, 0, 0), 10 with (2, 0, 0), and 11 with (0, 1, 0), should the dominant color still be (0, 1, 0) even though there are more colors that are really similar to each other which make up more of the image?

Copy link
Author

Choose a reason for hiding this comment

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

Oh, true! I've added a color quantization change to group similar colors together to account for slightly different shades, allowing the dominant color to better reflect the overall image composition.

return dominant_color

dominant_color = get_dominant_color('/images/logos/Princeton_Tigers.png?width=80&height=80&mode=max')
print(f"Dominant color: {dominant_color}")

Choose a reason for hiding this comment

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

remove test

pixel_count = Counter(filtered_pixels)
dominant_color = pixel_count.most_common(1)[0][0]
else:
dominant_color = (0, 0, 0)

Choose a reason for hiding this comment

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

if there is no dominant_color found, it will return a RGB value, but if there is one found, it will return a RGBA value, which might cause issues

image = Image.open(BytesIO(response.content)).convert("RGBA")

image = image.resize((50, 50))
image = image.quantize(colors=5).convert("RGBA")

Choose a reason for hiding this comment

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

Did quantizing to 5 colors work the best? I'm wondering if quantizing to more colors might work better but this seems fine as it is right now

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.

2 participants