-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Digital image processing doctests #1111
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
Closed
mrvnmchm
wants to merge
14
commits into
TheAlgorithms:master
from
mrvnmchm:digital_image_processing_doctests
Closed
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
eb3d472
Added Zeller's congruence algorithm
mrvnmchm e9083b8
Update args help
mrvnmchm a34259d
Merge pull request #1 from TheAlgorithms/master
mrvnmchm a889a39
Merge pull request #2 from TheAlgorithms/master
mrvnmchm ea915bb
Merge pull request #4 from TheAlgorithms/master
mrvnmchm efee7f9
change_contrast() doctest and pytest
mrvnmchm 4151619
add some canny tests
mrvnmchm 89f1682
add pytests for canny and start on filters
mrvnmchm e3b5ef7
add pytests to digital_image_processing
mrvnmchm 602761b
remove doctest hook and unnecessary comments
mrvnmchm 8b6c780
removed unused import cv2
mrvnmchm 767ef51
Merge pull request #5 from TheAlgorithms/master
mrvnmchm b98dbdc
remove unused imports 2.0
mrvnmchm 8d7b025
Merge branch 'digital_image_processing_doctests' of https://github.co…
mrvnmchm 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,45 @@ | ||
import argparse | ||
"""Zellers Congruence Birthday Algorithm | ||
Find out what day of the week you were born on, or any other date. | ||
""" | ||
|
||
def zeller(date_input): | ||
|
||
weekdays = { | ||
'0': 'Sunday', | ||
'1': 'Monday', | ||
'2': 'Tuesday', | ||
'3': 'Wednesday', | ||
'4': 'Thursday', | ||
'5': 'Friday', | ||
'6': 'Saturday' | ||
} | ||
|
||
m = int(date_input[0] + date_input[1]) | ||
d = int(date_input[3] + date_input[4]) | ||
y = int(date_input[6] + date_input[7] + date_input[8] + date_input[9]) | ||
|
||
if m <= 2: | ||
y = y - 1 | ||
m = m + 12 | ||
c = int(str(y)[:2]) | ||
k = int(str(y)[2:]) | ||
|
||
t = int(2.6*m - 5.39) | ||
u = int(c / 4) | ||
v = int(k / 4) | ||
x = d + k | ||
z = t + u + v + x | ||
w = z - (2 * c) | ||
|
||
f = round(w%7) | ||
|
||
for day in weekdays: | ||
if f == int(day): | ||
print("The date " + date_input + ", is a " + weekdays[day] + ".") | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description='Find out what day of the week you were born on, or any other date. Accepts birthday as a string in mm-dd-yyyy or mm/dd/yyyy format.') | ||
parser.add_argument('date_input', type=str, help='Date as a string (mm-dd-yyyy or mm/dd/yyyy)') | ||
args = parser.parse_args() | ||
zeller(args.date_input) |
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
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
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
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,67 @@ | ||
""" | ||
PyTest's for Digital Image Processing | ||
""" | ||
|
||
# add change_contrast | ||
from PIL import Image | ||
import digital_image_processing.change_contrast as cc | ||
# add canny | ||
import digital_image_processing.edge_detection.canny as canny | ||
import cv2 | ||
# add gen_gaussian | ||
from cv2 import imread, cvtColor, COLOR_BGR2GRAY, imshow, waitKey | ||
from numpy import array, pi, mgrid, exp, square, zeros, ravel, dot, uint8 | ||
import digital_image_processing.filters.gaussian_filter as gg | ||
# add convolve | ||
import digital_image_processing.filters.convolve as conv | ||
# add median | ||
import digital_image_processing.filters.median_filter as med | ||
# add sobel_filter | ||
import digital_image_processing.filters.sobel_filter as sob | ||
# add img | ||
mrvnmchm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
img = imread(r'digital_image_processing/image_data/lena.jpg') | ||
# add gray | ||
gray = cvtColor(img, COLOR_BGR2GRAY) | ||
|
||
# Test: change_contrast() | ||
def test_change_contrast(): | ||
# Image object | ||
with Image.open("digital_image_processing/image_data/lena.jpg") as img: | ||
# Work around assertion for response | ||
assert str(cc.change_contrast(img, 110)).startswith('<PIL.Image.Image image mode=RGB size=512x512 at') | ||
|
||
# Test: canny.gen_gaussian_kernel() | ||
def test_gen_gaussian_kernel(): | ||
# get ambiguous array | ||
resp = canny.gen_gaussian_kernel(9, sigma=1.4) | ||
# Assert ambiguous array | ||
assert resp.all() | ||
|
||
# Test: canny() | ||
def test_canny(): | ||
# read image in gray | ||
canny_img = imread('digital_image_processing/image_data/lena.jpg', 0) | ||
# assert ambiguos array for all == True | ||
assert canny_img.all() | ||
# Get canny array | ||
canny_array = canny.canny(canny_img) | ||
# assert canny array for at least one True | ||
assert canny_array.any() | ||
|
||
# Test: filters/gaussian_filter.py | ||
def test_gen_gaussian_kernel_filter(): | ||
# Filter 5x5 | ||
assert gg.gaussian_filter(gray, 5, sigma=0.9).all() | ||
|
||
def test_convolve_filter(): | ||
# laplace diagonals | ||
Laplace = array([[0.25, 0.5, 0.25], [0.5, -3, 0.5], [0.25, 0.5, 0.25]]) | ||
res = conv.img_convolve(gray, Laplace).astype(uint8) | ||
assert res.any() | ||
|
||
def test_median_filter(): | ||
assert med.median_filter(gray, 3).any() | ||
|
||
def test_sobel_filter(): | ||
grad, theta = sob.sobel_filter(gray) | ||
assert grad.any() and theta.any() |
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.