-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/utils/helpers.py
Outdated
return dominant_color | ||
|
||
dominant_color = get_dominant_color("https://cornellbigred.com/images/logos/harvardlogo.png?width=50") | ||
print("Dominant color:", dominant_color) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the test
src/utils/helpers.py
Outdated
from io import BytesIO | ||
from collections import Counter | ||
|
||
def get_dominant_color(image_url, threshold=200): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…ly different from each other
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}") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
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