Skip to content

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 49 commits into from
Oct 5, 2023
Merged
Changes from 45 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7672d1a
added laplacian_filter file
ojas-wani Oct 5, 2023
642af23
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
5e6100c
updated laplacian.py
ojas-wani Oct 5, 2023
3819098
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
5a5a84d
updated laplacian_py
ojas-wani Oct 5, 2023
2cbbe3a
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
f233a54
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
19a7879
updated laplacian_filter.py
ojas-wani Oct 5, 2023
d8040f5
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
6c5b418
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
ea541e6
updated laplacian_filter.py
ojas-wani Oct 5, 2023
86dc5a9
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
de92d3d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
8325b64
updated laplacian_filter.py
ojas-wani Oct 5, 2023
e6fda58
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
cccf2a9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
5f9331a
required changes to laplacian file
ojas-wani Oct 5, 2023
35f8b7a
changed laplacian_filter.py
ojas-wani Oct 5, 2023
aa0da39
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
d451d62
changed laplacian_filter.py
ojas-wani Oct 5, 2023
dabd6c9
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
4a118f3
changed laplacian_filter.py
ojas-wani Oct 5, 2023
39b3363
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
8656afd
changed laplacian_filter.py
ojas-wani Oct 5, 2023
552a873
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
641c063
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
2fd6024
changed laplacian_filter.py
ojas-wani Oct 5, 2023
667055a
changed laplacian_filter.py
ojas-wani Oct 5, 2023
0d83b21
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
2af89bc
updated laplacian_filter.py
ojas-wani Oct 5, 2023
b2e2308
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
1c72a65
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
0ce40a2
update laplacian_filter.py
ojas-wani Oct 5, 2023
34942b3
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
891da5e
update laplacian_filter.py
ojas-wani Oct 5, 2023
f52f3b5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
24d265b
update laplacian_filter.py
ojas-wani Oct 5, 2023
435efe6
changed laplacian_filter.py
ojas-wani Oct 5, 2023
e36fa6a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
84c0273
changed laplacian_filter.py
ojas-wani Oct 5, 2023
9550244
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
3718979
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
e30c558
changed laplacian_filter.py
ojas-wani Oct 5, 2023
5824fcb
Merge branch 'laplacian-filter' of https://github.com/ojas-wani/Pytho…
ojas-wani Oct 5, 2023
1bcbd84
changed laplacian_filter.py
ojas-wani Oct 5, 2023
532e385
changed laplacian_filter.py
ojas-wani Oct 5, 2023
e09582f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2023
2d184c5
Update laplacian_filter.py
cclauss Oct 5, 2023
7159ffe
Add a test
cclauss Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions digital_image_processing/filters/laplacian_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# @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,
)
from digital_image_processing.filters.gaussian_filter import gaussian_filter


def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file digital_image_processing/filters/laplacian_filter.py, please provide doctest for the function my_laplacian

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file digital_image_processing/filters/laplacian_filter.py, please provide doctest for the function my_laplacian

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file digital_image_processing/filters/laplacian_filter.py, please provide doctest for the function my_laplacian

"""
: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.

"""

# Create a Laplacian kernel matrix according to the ksize
if ksize == 1:
kernel = np.array([[0, -1, 0], [-1, 4, -1], [0, -1, 0]])
elif ksize == 3:
kernel = np.array([[0, 1, 0], [1, -4, 1], [0, 1, 0]])
elif ksize == 5:
kernel = 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],
]
)
elif ksize == 7:
kernel = 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],
]
)

# Apply the Laplacian kernel using convolution
laplacian_result = filter2D(
src, CV_64F, kernel, 0, borderType=BORDER_DEFAULT, anchor=(0, 0)
)

return laplacian_result


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("Deteced edges using laplacian filter", laplacian_image)

waitKey(0)