-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Added sepia tone #1877
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
Merged
Merged
Added sepia tone #1877
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
632891e
Add sepia tone
l3str4nge 4c4df38
Add unit test
l3str4nge 9c402f0
technic --> technique
l3str4nge 0bc58ab
Update digital_image_processing/sepia.py
l3str4nge 1c1c7a7
Update digital_image_processing/sepia.py
l3str4nge 696d816
Fixed errors after commit changes
l3str4nge 52a3e8f
Fixed errors
l3str4nge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Implemented an algorithm using opencv to tone an image with sepia technique | ||
""" | ||
|
||
from cv2 import imread, imshow, waitKey, destroyAllWindows | ||
|
||
|
||
def make_sepia(img, factor: int): | ||
""" Function create sepia tone. Source: https://en.wikipedia.org/wiki/Sepia_(color) """ | ||
pixel_h, pixel_v = img.shape[0], img.shape[1] | ||
|
||
def to_grayscale(blue, green, red): | ||
""" | ||
Helper function to create pixel's greyscale representation | ||
Src: https://pl.wikipedia.org/wiki/YUV | ||
""" | ||
return 0.2126 * red + 0.587 * green + 0.114 * blue | ||
|
||
def normalize(value): | ||
""" Helper function to normalize R/G/B value -> return 255 if value > 255""" | ||
return value if value <= 255 else 255 | ||
|
||
for i in range(pixel_h): | ||
for j in range(pixel_v): | ||
greyscale = int(to_grayscale(*img[i][j])) | ||
img[i][j] = [ | ||
normalize(greyscale), | ||
normalize(greyscale + factor), | ||
normalize(greyscale + 2 * factor), | ||
] | ||
|
||
return img | ||
|
||
|
||
if __name__ == "__main__": | ||
# read original image | ||
img = imread("image_data/lena.jpg", 1) | ||
img1 = imread("image_data/lena.jpg", 1) | ||
img2 = imread("image_data/lena.jpg", 1) | ||
img3 = imread("image_data/lena.jpg", 1) | ||
|
||
# convert with sepia with different factor's value | ||
sepia_10 = make_sepia(img, 10) | ||
sepia_20 = make_sepia(img1, 20) | ||
sepia_30 = make_sepia(img2, 30) | ||
sepia_40 = make_sepia(img3, 40) | ||
l3str4nge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# show result images | ||
imshow("Original image with sepia (factor: 10)", img) | ||
imshow("Original image with sepia (factor: 20)", img1) | ||
imshow("Original image with sepia (factor: 30)", img2) | ||
imshow("Original image with sepia (factor: 40)", img3) | ||
waitKey(0) | ||
destroyAllWindows() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.