-
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?
Changes from all commits
cef7e3a
e979b26
550aba8
a98e1fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Contributing to Ithaca Transit Backend | ||
👍🎉 First off, congrats on getting put on this pod 😂🎉👍 | ||
|
||
The following is a set of guidelines for contributing to our backend. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request. | ||
|
||
# Versioning | ||
This is _extremely_ important as handling our backend can get quite messy. | ||
|
||
# Making PRs | ||
We want our PRs to be concise but informative. Some pointers as per our PR template: | ||
### Title | ||
Summarize what changes you've made in one sentence. For example: "Exclude staff from the check for follows". For stacked PRs, please indicate clearly in the title where in the stack you are. For example: "[Eatery Refactor][4/5] Converted all files to MVP model." | ||
### Overview | ||
Summarize generally what the purpose of this PR is. | ||
### Changes | ||
Include details of what your changes actually are and how it is intended to work. | ||
### Test Coverage | ||
Describe how you tested this feature: manual testing and/or unit testing. Please include repro steps and/or how to turn the feature on if applicable. In the context of this repo, add a plan for how you intend to test on [integration](https://github.com/cuappdev/integration), with your newly created issue linked. | ||
### Next Steps | ||
If this applies, describe how you plan on addressing future PRs if this is a part of a multi-PR change. | ||
### Related PRs or Issues | ||
If this applies, list related PRs against other branches or repositories. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Overview | ||
|
||
|
||
## Changes Made | ||
|
||
|
||
## Test Coverage | ||
|
||
|
||
## Next Steps | ||
|
||
|
||
## Related PRs or Issues | ||
|
||
|
||
## Screenshots | ||
<img src="image url here" width="300"/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import requests | ||
from PIL import Image | ||
from io import BytesIO | ||
from collections import Counter | ||
|
||
BASE_URL = "https://dxbhsrqyrr690.cloudfront.net/sidearm.nextgen.sites/cornellbigred.com" | ||
|
||
def get_dominant_color(relative_path, white_threshold=200, black_threshold=50): | ||
image_url = f"{BASE_URL}{relative_path}" | ||
|
||
response = requests.get(image_url) | ||
image = Image.open(BytesIO(response.content)).convert("RGBA") | ||
|
||
image = image.resize((50, 50)) | ||
image = image.quantize(colors=5).convert("RGBA") | ||
pixels = image.getdata() | ||
|
||
filtered_pixels = [ | ||
pixel for pixel in pixels | ||
if not (pixel[0] > white_threshold and pixel[1] > white_threshold and pixel[2] > white_threshold) and | ||
not (pixel[0] < black_threshold and pixel[1] < black_threshold and pixel[2] < black_threshold) | ||
] | ||
|
||
if filtered_pixels: | ||
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 commentThe 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 |
||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. remove test |
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