-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
added laplacian_filter file #9783
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
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
7672d1a
added laplacian_filter file
ojas-wani 642af23
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5e6100c
updated laplacian.py
ojas-wani 3819098
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5a5a84d
updated laplacian_py
ojas-wani 2cbbe3a
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani f233a54
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 19a7879
updated laplacian_filter.py
ojas-wani d8040f5
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani 6c5b418
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ea541e6
updated laplacian_filter.py
ojas-wani 86dc5a9
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani de92d3d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8325b64
updated laplacian_filter.py
ojas-wani e6fda58
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani cccf2a9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5f9331a
required changes to laplacian file
ojas-wani 35f8b7a
changed laplacian_filter.py
ojas-wani aa0da39
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d451d62
changed laplacian_filter.py
ojas-wani dabd6c9
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani 4a118f3
changed laplacian_filter.py
ojas-wani 39b3363
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8656afd
changed laplacian_filter.py
ojas-wani 552a873
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani 641c063
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2fd6024
changed laplacian_filter.py
ojas-wani 667055a
changed laplacian_filter.py
ojas-wani 0d83b21
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2af89bc
updated laplacian_filter.py
ojas-wani b2e2308
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani 1c72a65
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0ce40a2
update laplacian_filter.py
ojas-wani 34942b3
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani 891da5e
update laplacian_filter.py
ojas-wani f52f3b5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 24d265b
update laplacian_filter.py
ojas-wani 435efe6
changed laplacian_filter.py
ojas-wani e36fa6a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 84c0273
changed laplacian_filter.py
ojas-wani 9550244
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani 3718979
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e30c558
changed laplacian_filter.py
ojas-wani 5824fcb
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani 1bcbd84
changed laplacian_filter.py
ojas-wani 532e385
changed laplacian_filter.py
ojas-wani e09582f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2d184c5
Update laplacian_filter.py
cclauss 7159ffe
Add a test
cclauss 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,81 @@ | ||
# @Author : ojas-wani | ||
# @File : laplacian_filter.py | ||
# @Date : 10/04/2023 | ||
|
||
import numpy as np | ||
from cv2 import ( | ||
BORDER_DEFAULT, | ||
COLOR_BGR2GRAY, | ||
CV_64F, | ||
cvtColor, | ||
filter2D, | ||
imread, | ||
imshow, | ||
waitKey, | ||
) | ||
|
||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from digital_image_processing.filters.gaussian_filter import gaussian_filter | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:param src: the source image, which should be a grayscale or color image. | ||
:param ksize: the size of the kernel used to compute the Laplacian filter, | ||
which can be 1, 3, 5, or 7. | ||
|
||
>>> my_laplacian(src=np.array([]), ksize=0) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: ksize must be in (1, 3, 5, 7) | ||
""" | ||
kernels = { | ||
1: np.array([[0, -1, 0], [-1, 4, -1], [0, -1, 0]]), | ||
3: np.array([[0, 1, 0], [1, -4, 1], [0, 1, 0]]), | ||
5: np.array( | ||
[ | ||
[0, 0, -1, 0, 0], | ||
[0, -1, -2, -1, 0], | ||
[-1, -2, 16, -2, -1], | ||
[0, -1, -2, -1, 0], | ||
[0, 0, -1, 0, 0], | ||
] | ||
), | ||
7: np.array( | ||
[ | ||
[0, 0, 0, -1, 0, 0, 0], | ||
[0, 0, -2, -3, -2, 0, 0], | ||
[0, -2, -7, -10, -7, -2, 0], | ||
[-1, -3, -10, 68, -10, -3, -1], | ||
[0, -2, -7, -10, -7, -2, 0], | ||
[0, 0, -2, -3, -2, 0, 0], | ||
[0, 0, 0, -1, 0, 0, 0], | ||
] | ||
), | ||
} | ||
if ksize not in kernels: | ||
msg = f"ksize must be in {tuple(kernels)}" | ||
raise ValueError(msg) | ||
|
||
# Apply the Laplacian kernel using convolution | ||
return filter2D( | ||
src, CV_64F, kernels[ksize], 0, borderType=BORDER_DEFAULT, anchor=(0, 0) | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
# read original image | ||
img = imread(r"../image_data/lena.jpg") | ||
|
||
# turn image in gray scale value | ||
gray = cvtColor(img, COLOR_BGR2GRAY) | ||
|
||
# Applying gaussian filter | ||
blur_image = gaussian_filter(gray, 3, sigma=1) | ||
|
||
# Apply multiple Kernel to detect edges | ||
laplacian_image = my_laplacian(ksize=3, src=blur_image) | ||
|
||
imshow("Original image", img) | ||
imshow("Detected edges using laplacian filter", laplacian_image) | ||
|
||
waitKey(0) |
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.