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 12 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
88 changes: 88 additions & 0 deletions digital_image_processing/filters/laplacian_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# @Author : ojas-wani
# @File : laplacian_filter.py
# @Time : 10/04/2023

from cv2 import BORDER_DEFAULT, cvtColor, CV_64F, COLOR_BGR2GRAY, filter2D, GaussianBlur, imread, imshow, waitKey
import numpy as np


def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default') -> 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

Please provide type hint for the parameter: src

Please provide type hint for the parameter: ddepth

Please provide type hint for the parameter: ksize

Please provide type hint for the parameter: scale

Please provide type hint for the parameter: delta

Please provide type hint for the parameter: bordertype

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

Please provide type hint for the parameter: src

Please provide type hint for the parameter: ddepth

Please provide type hint for the parameter: ksize

Please provide type hint for the parameter: scale

Please provide type hint for the parameter: delta

Please provide type hint for the parameter: bordertype


"""
:param src: the source image, which should be a grayscale or color image.
:param ddepth: the desired depth of the destination image,
-1 or one of np.uint8, np.uint16, np.int16, np.float32 or np.float64.
:param ksize: the size of the kernel used to compute the Laplacian filter,
which can be 1, 3, 5 or 7.
:param scale: an optional scaling factor applied to the computed Laplacian values,
which can be used to enhance or reduce the effect of the filter.
:param delta: an optional value added to the computed Laplacian values,
which can be used to shift the output image intensity range.
:param bordertype: an optional flag that specifies how to handle the image borders,
which can be one of 'default', 'reflect', or 'constant'.

"""

# Convert the source image to a numpy array
src = np.array(src)

Choose a reason for hiding this comment

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

An error occurred while parsing the file: digital_image_processing/filters/laplacian_filter.py

Traceback (most recent call last):
  File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
    reports = lint_file(
              ^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 28:1.
parser error: error at 27:4: expected one of (, *, +, -, ..., AWAIT, DEDENT, False, NAME, NUMBER, None, True, [, break, continue, lambda, match, not, pass, ~

    src = np.array(src)
                      ^

# Get the shape and depth of the source image
src_depth = src.dtype

# If ddepth is -1, use the same depth as the source image
if ddepth == -1:
ddepth = src_depth

# 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, ddepth, kernel, delta, 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 = GaussianBlur(gray, (3, 3), 0, 0)

# Apply multiple Kernel to detect edges
laplacian_image = my_laplacian(blur_image, ddepth=CV_64F, ksize=3)

imshow("Original image", img)
imshow("Deteced edges using laplacian filter", laplacian_image)

waitKey(0)