From 7672d1a8adca9c8c9ba11aa35f8b6f88c8541d9e Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 00:17:42 -0700 Subject: [PATCH 01/36] added laplacian_filter file --- .../filters/laplacian_filter.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 digital_image_processing/filters/laplacian_filter.py diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py new file mode 100644 index 000000000000..7d095526e980 --- /dev/null +++ b/digital_image_processing/filters/laplacian_filter.py @@ -0,0 +1,65 @@ +# @Author : ojas-wani +# @File : laplacian_filter.py +# @Time : 10/04/2023 + +from cv2 import imread, cvtColor, COLOR_BGR2GRAY, filter2D, imread, imshow, waitKey, CV_64F, BORDER_DEFAULT +import numpy as np +from gaussian_filter import gaussian_filter + +def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, borderType='default') -> np.ndarray: + + """ + :param src: the source image, which should be a grayscale or color image. + :param ddepth: the desired depth of the destination image, which can be -1 to use the same depth as the source image, 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. A larger kernel size will produce more accurate results, but also more noise. + :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. + :[aram 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', 'replicate', 'reflect', or 'constant'. + + """ + + # Convert the source image to a numpy array + src = np.array(src) + + # Get the shape and depth of the source image + height, width = src.shape[:2] + 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"digital_image_processing/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(blur_image,ddepth=CV_64F, ksize=3) + + imshow("Original image", img) + imshow("Deteced edges using laplacian filter", laplacian_image) + + waitKey(0) From 642af2355f4d7e88e7c119b4669e81a94eebb7bb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:29:16 +0000 Subject: [PATCH 02/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../filters/laplacian_filter.py | 129 +++++++++++------- 1 file changed, 80 insertions(+), 49 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 7d095526e980..727a046e08e6 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,64 +2,95 @@ # @File : laplacian_filter.py # @Time : 10/04/2023 -from cv2 import imread, cvtColor, COLOR_BGR2GRAY, filter2D, imread, imshow, waitKey, CV_64F, BORDER_DEFAULT +from cv2 import ( + imread, + cvtColor, + COLOR_BGR2GRAY, + filter2D, + imread, + imshow, + waitKey, + CV_64F, + BORDER_DEFAULT, +) import numpy as np from gaussian_filter import gaussian_filter -def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, borderType='default') -> np.ndarray: - """ - :param src: the source image, which should be a grayscale or color image. - :param ddepth: the desired depth of the destination image, which can be -1 to use the same depth as the source image, 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. A larger kernel size will produce more accurate results, but also more noise. - :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. - :[aram 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', 'replicate', 'reflect', or 'constant'. - - """ - - # Convert the source image to a numpy array - src = np.array(src) - - # Get the shape and depth of the source image - height, width = src.shape[:2] - 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 +def my_laplacian( + src, ddepth=-1, ksize=3, scale=1, delta=0, borderType="default" +) -> np.ndarray: + """ + :param src: the source image, which should be a grayscale or color image. + :param ddepth: the desired depth of the destination image, which can be -1 to use the same depth as the source image, 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. A larger kernel size will produce more accurate results, but also more noise. + :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. + :[aram 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', 'replicate', 'reflect', or 'constant'. + + """ + + # Convert the source image to a numpy array + src = np.array(src) + + # Get the shape and depth of the source image + height, width = src.shape[:2] + 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"digital_image_processing/image_data/lena.jpg") - # read original image - img = imread(r"digital_image_processing/image_data/lena.jpg") + # turn image in gray scale value + gray = cvtColor(img, COLOR_BGR2GRAY) - # turn image in gray scale value - gray = cvtColor(img,COLOR_BGR2GRAY) + # Applying gaussian filter + blur_image = gaussian_filter(gray, 3, sigma=1) - # Applying gaussian filter - blur_image = gaussian_filter(gray,3, sigma=1) + # Apply multiple Kernel to detect edges + laplacian_image = my_laplacian(blur_image, ddepth=CV_64F, ksize=3) - # 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) - imshow("Original image", img) - imshow("Deteced edges using laplacian filter", laplacian_image) - - waitKey(0) + waitKey(0) From 5e6100c07e90cd93339ac1d44931b7cbc9c9c2e5 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 14:33:26 -0700 Subject: [PATCH 03/36] updated laplacian.py --- .../filters/laplacian_filter.py | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 727a046e08e6..70c350e190e2 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -7,7 +7,6 @@ cvtColor, COLOR_BGR2GRAY, filter2D, - imread, imshow, waitKey, CV_64F, @@ -18,15 +17,19 @@ def my_laplacian( - src, ddepth=-1, ksize=3, scale=1, delta=0, borderType="default" + src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype="default" ) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. - :param ddepth: the desired depth of the destination image, which can be -1 to use the same depth as the source image, 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. A larger kernel size will produce more accurate results, but also more noise. - :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. - :[aram 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', 'replicate', 'reflect', or 'constant'. + :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. A larger kernel size will produce more accurate results, but also more noise. + :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. + :[aram 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. """ @@ -71,26 +74,27 @@ def my_laplacian( # Apply the Laplacian kernel using convolution laplacian_result = filter2D( - src, ddepth, kernel, delta, borderType=BORDER_DEFAULT, anchor=(0, 0) + src, ddepth, kernel, delta, bordertype=BORDER_DEFAULT, anchor=(0, 0) ) return laplacian_result if __name__ == "__main__": - # read original image - img = imread(r"digital_image_processing/image_data/lena.jpg") - # turn image in gray scale value - gray = cvtColor(img, COLOR_BGR2GRAY) + # 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) + # Applying gaussian filter + blur_image = gaussian_filter(gray, 3, sigma=1) - # Apply multiple Kernel to detect edges - laplacian_image = my_laplacian(blur_image, ddepth=CV_64F, ksize=3) + # 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) + imshow("Original image", img) + imshow("Deteced edges using laplacian filter", laplacian_image) - waitKey(0) + waitKey(0) From 381909875b26e7beb812a01d2eb8af4e15ac005c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:34:27 +0000 Subject: [PATCH 04/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../filters/laplacian_filter.py | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 70c350e190e2..a4ae50bf83a2 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -21,13 +21,13 @@ def my_laplacian( ) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. - :param ddepth: the desired depth of the destination 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, + :param ksize: the size of the kernel used to compute the Laplacian filter, which can be 1, 3, 5 or 7. A larger kernel size will produce more accurate results, but also more noise. - :param scale: an optional scaling factor applied to the computed Laplacian values, + :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. - :[aram delta: an optional value added to the computed Laplacian values, + :[aram 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. @@ -81,20 +81,19 @@ def my_laplacian( if __name__ == "__main__": + # read original image + img = imread(r"../image_data/lena.jpg") - # read original image - img = imread(r"../image_data/lena.jpg") + # turn image in gray scale value + gray = cvtColor(img, COLOR_BGR2GRAY) - # turn image in gray scale value - gray = cvtColor(img, COLOR_BGR2GRAY) + # Applying gaussian filter + blur_image = gaussian_filter(gray, 3, sigma=1) - # Applying gaussian filter - blur_image = gaussian_filter(gray, 3, sigma=1) + # Apply multiple Kernel to detect edges + laplacian_image = my_laplacian(blur_image, ddepth=CV_64F, ksize=3) - # 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) - imshow("Original image", img) - imshow("Deteced edges using laplacian filter", laplacian_image) - - waitKey(0) + waitKey(0) From 5a5a84da4236506e4c6a53668de3247c2eae7d1d Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 14:46:24 -0700 Subject: [PATCH 05/36] updated laplacian_py --- .../filters/laplacian_filter.py | 127 +++++++----------- 1 file changed, 48 insertions(+), 79 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 70c350e190e2..83b48c2c4c10 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,82 +2,51 @@ # @File : laplacian_filter.py # @Time : 10/04/2023 -from cv2 import ( - imread, - cvtColor, - COLOR_BGR2GRAY, - filter2D, - imshow, - waitKey, - CV_64F, - BORDER_DEFAULT, -) +from cv2 import imread, cvtColor, COLOR_BGR2GRAY, filter2D, imshow, waitKey, CV_64F, BORDER_DEFAULT, GaussianBlur import numpy as np -from gaussian_filter import gaussian_filter - - -def my_laplacian( - src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype="default" -) -> np.ndarray: - """ - :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. A larger kernel size will produce more accurate results, but also more noise. - :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. - :[aram 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. - - """ - - # Convert the source image to a numpy array - src = np.array(src) - - # Get the shape and depth of the source image - height, width = src.shape[:2] - 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 + + +def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default') -> np.ndarray: + + """ + :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. A larger kernel size will produce more accurate results. + :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', 'replicate', 'reflect', or 'constant'. + + """ + + # Convert the source image to a numpy array + 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__": @@ -86,15 +55,15 @@ def my_laplacian( img = imread(r"../image_data/lena.jpg") # turn image in gray scale value - gray = cvtColor(img, COLOR_BGR2GRAY) + gray = cvtColor(img,COLOR_BGR2GRAY) # Applying gaussian filter - blur_image = gaussian_filter(gray, 3, sigma=1) + 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) + 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) From f233a54e56bcf27c15778c4039d0a9eb3875206e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:50:25 +0000 Subject: [PATCH 06/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../filters/laplacian_filter.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 544ff70a2954..37b6e13b5bcc 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -10,19 +10,19 @@ def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default' """ :param src: the source image, which should be a grayscale or color image. - :param ddepth: the desired depth of the destination 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, + :param ksize: the size of the kernel used to compute the Laplacian filter, which can be 1, 3, 5 or 7. A larger kernel size will produce more accurate results. - :param scale: an optional scaling factor applied to the computed Laplacian values, + :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, + :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, + :param bordertype: an optional flag that specifies how to handle the image borders, which can be one of 'default', 'replicate', 'reflect', or 'constant'. """ - + # Convert the source image to a numpy array src = np.array(src) @@ -64,5 +64,5 @@ def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default' imshow("Original image", img) imshow("Deteced edges using laplacian filter", laplacian_image) - + waitKey(0) From 19a7879c72526b8ed59ac3dbf999f1014c965d32 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 14:51:11 -0700 Subject: [PATCH 07/36] updated laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 544ff70a2954..5e730ab492bd 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -50,8 +50,9 @@ def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default' if __name__ == "__main__": - # read original image - img = imread(r"../image_data/lena.jpg") + + # read original image + img = imread(r"../image_data/lena.jpg") # turn image in gray scale value gray = cvtColor(img,COLOR_BGR2GRAY) From 6c5b4180fa36e3b2fac2a1b6adb5501f4863bddf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:51:53 +0000 Subject: [PATCH 08/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../filters/laplacian_filter.py | 138 +++++++++++------- 1 file changed, 84 insertions(+), 54 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 79c22e118b81..028ce27fda82 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,68 +2,98 @@ # @File : laplacian_filter.py # @Time : 10/04/2023 -from cv2 import imread, cvtColor, COLOR_BGR2GRAY, filter2D, imshow, waitKey, CV_64F, BORDER_DEFAULT, GaussianBlur +from cv2 import ( + imread, + cvtColor, + COLOR_BGR2GRAY, + filter2D, + imshow, + waitKey, + CV_64F, + BORDER_DEFAULT, + GaussianBlur, +) import numpy as np -def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default') -> np.ndarray: - - """ - :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. A larger kernel size will produce more accurate results. - :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', 'replicate', 'reflect', or 'constant'. - - """ - - # Convert the source image to a numpy array - 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 +def my_laplacian( + src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype="default" +) -> np.ndarray: + """ + :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. A larger kernel size will produce more accurate results. + :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', 'replicate', 'reflect', or 'constant'. + + """ + + # Convert the source image to a numpy array + 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") + # read original image + img = imread(r"../image_data/lena.jpg") - # turn image in gray scale value - gray = cvtColor(img,COLOR_BGR2GRAY) + # turn image in gray scale value + gray = cvtColor(img, COLOR_BGR2GRAY) - # Applying gaussian filter - blur_image = GaussianBlur(gray,(3,3),0,0) + # 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) + # 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) + imshow("Original image", img) + imshow("Deteced edges using laplacian filter", laplacian_image) - waitKey(0) + waitKey(0) From ea541e6e8f4a263c1f485292305cb35ec7183f7e Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:02:15 -0700 Subject: [PATCH 09/36] updated laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 79c22e118b81..68580ffe0bf9 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,7 +2,7 @@ # @File : laplacian_filter.py # @Time : 10/04/2023 -from cv2 import imread, cvtColor, COLOR_BGR2GRAY, filter2D, imshow, waitKey, CV_64F, BORDER_DEFAULT, GaussianBlur +from cv2 import BORDER_DEFAULT, cvtColor, CV_64F, COLOR_BGR2GRAY, filter2D, GaussianBlur, imread, imshow, waitKey import numpy as np @@ -13,13 +13,13 @@ def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default' :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. A larger kernel size will produce more accurate results. + 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', 'replicate', 'reflect', or 'constant'. + which can be one of 'default', 'reflect', or 'constant'. """ From de92d3df60a7a93c184384f341dfcca894f380a4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:03:12 +0000 Subject: [PATCH 10/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- digital_image_processing/filters/laplacian_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 48e1f9218e5b..f995c35a5b50 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,7 +2,7 @@ # @File : laplacian_filter.py # @Time : 10/04/2023 -from cv2 import BORDER_DEFAULT, cvtColor, CV_64F, COLOR_BGR2GRAY, filter2D, GaussianBlur, imread, imshow, waitKey +from cv2 import BORDER_DEFAULT, cvtColor, CV_64F, COLOR_BGR2GRAY, filter2D, GaussianBlur, imread, imshow, waitKey import numpy as np From 8325b6435994eff8ac4814f1558ac4b0999ae376 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:03:29 -0700 Subject: [PATCH 11/36] updated laplacian_filter.py --- .../filters/laplacian_filter.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 48e1f9218e5b..418b8d507fb5 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -8,18 +8,18 @@ def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default') -> np.ndarray: - """ - :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'. + """ + :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'. """ From cccf2a986342e3b35f5cf3d6beeaaa522ffc52d5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:04:06 +0000 Subject: [PATCH 12/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../filters/laplacian_filter.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 477131716fde..01b58aeea044 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,12 +2,23 @@ # @File : laplacian_filter.py # @Time : 10/04/2023 -from cv2 import BORDER_DEFAULT, cvtColor, CV_64F, COLOR_BGR2GRAY, filter2D, GaussianBlur, imread, imshow, waitKey +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: - +def my_laplacian( + src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype="default" +) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. :param ddepth: the desired depth of the destination image, From 5f9331a63b5b0c11e3716360bdd6b3c063fe2e15 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:35:17 -0700 Subject: [PATCH 13/36] required changes to laplacian file --- .../filters/laplacian_filter.py | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 477131716fde..4c5fb79ab486 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -1,38 +1,19 @@ # @Author : ojas-wani # @File : laplacian_filter.py -# @Time : 10/04/2023 +# @Date : 10/04/2023 -from cv2 import BORDER_DEFAULT, cvtColor, CV_64F, COLOR_BGR2GRAY, filter2D, GaussianBlur, imread, imshow, waitKey +from cv2 import BORDER_DEFAULT, CV_64F, COLOR_BGR2GRAY, cvtColor, filter2D, imread, imshow, waitKey +from gaussian_filter import gaussian_filter import numpy as np - -def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default') -> np.ndarray: +def my_laplacian(src:np.ndarray, ksize:int) -> np.ndarray: """ :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) - - # 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]]) @@ -63,7 +44,7 @@ def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default' # Apply the Laplacian kernel using convolution laplacian_result = filter2D( - src, ddepth, kernel, delta, borderType=BORDER_DEFAULT, anchor=(0, 0) + src, CV_64F, kernel, 0, borderType=BORDER_DEFAULT, anchor=(0, 0) ) return laplacian_result @@ -71,16 +52,16 @@ def my_laplacian(src, ddepth=-1, ksize=3, scale=1, delta=0, bordertype='default' if __name__ == "__main__": # read original image - img = imread(r"../image_data/lena.jpg") + img = imread(r"digital_image_processing/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) + blur_image = gaussian_filter(gray,3, sigma=1) # Apply multiple Kernel to detect edges - laplacian_image = my_laplacian(blur_image, ddepth=CV_64F, ksize=3) + laplacian_image = my_laplacian(blur_image, ksize=3) imshow("Original image", img) imshow("Deteced edges using laplacian filter", laplacian_image) From aa0da39aa1cfccdcda3401c8b4bf2a87c546b227 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:37:49 +0000 Subject: [PATCH 14/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../filters/laplacian_filter.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 4c5fb79ab486..1132770e5d7e 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,12 +2,21 @@ # @File : laplacian_filter.py # @Date : 10/04/2023 -from cv2 import BORDER_DEFAULT, CV_64F, COLOR_BGR2GRAY, cvtColor, filter2D, imread, imshow, waitKey +from cv2 import ( + BORDER_DEFAULT, + CV_64F, + COLOR_BGR2GRAY, + cvtColor, + filter2D, + imread, + imshow, + waitKey, +) from gaussian_filter import gaussian_filter import numpy as np -def my_laplacian(src:np.ndarray, ksize:int) -> np.ndarray: +def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: """ :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, @@ -58,7 +67,7 @@ def my_laplacian(src:np.ndarray, ksize:int) -> np.ndarray: gray = cvtColor(img, COLOR_BGR2GRAY) # Applying gaussian filter - blur_image = gaussian_filter(gray,3, sigma=1) + blur_image = gaussian_filter(gray, 3, sigma=1) # Apply multiple Kernel to detect edges laplacian_image = my_laplacian(blur_image, ksize=3) From d451d62d6e09210dc705efca065629f78fd100c8 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:40:19 -0700 Subject: [PATCH 15/36] changed laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 4c5fb79ab486..fb9513503845 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -6,7 +6,7 @@ from gaussian_filter import gaussian_filter import numpy as np -def my_laplacian(src:np.ndarray, ksize:int) -> np.ndarray: +def my_laplacian(ksize:int, src:np.ndarray) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. From 4a118f32531adbc8168e0c9a91b316879a5fe1c0 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:41:06 -0700 Subject: [PATCH 16/36] changed laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 139215e78038..a761c64883c4 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -15,8 +15,6 @@ from gaussian_filter import gaussian_filter import numpy as np -def my_laplacian(ksize:int, src:np.ndarray) -> np.ndarray: - def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. From 39b3363f0a267b5ec157e220a8723253b4cae3e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:41:42 +0000 Subject: [PATCH 17/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- digital_image_processing/filters/laplacian_filter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index a761c64883c4..1132770e5d7e 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -15,6 +15,7 @@ from gaussian_filter import gaussian_filter import numpy as np + def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. From 8656afdcafcae0b5acae4e6fe156e05bd93d3b84 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:43:54 -0700 Subject: [PATCH 18/36] changed laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index a761c64883c4..a00b03831057 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -15,11 +15,14 @@ from gaussian_filter import gaussian_filter import numpy as np + def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: + """ :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 From 641c063d6ca21535df97ee83c38cf6f8384131ad Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:44:32 +0000 Subject: [PATCH 19/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- digital_image_processing/filters/laplacian_filter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index a00b03831057..ecaa7ce3e769 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -17,12 +17,11 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: - """ :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 From 2fd602432464596cd9489dabaa1f2edf065e58b5 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:46:06 -0700 Subject: [PATCH 20/36] changed laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index a00b03831057..4435572e5f44 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -17,12 +17,12 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: - + """ :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 @@ -60,7 +60,6 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: return laplacian_result - if __name__ == "__main__": # read original image img = imread(r"digital_image_processing/image_data/lena.jpg") @@ -77,4 +76,4 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: imshow("Original image", img) imshow("Deteced edges using laplacian filter", laplacian_image) - waitKey(0) + waitKey(0) \ No newline at end of file From 0d83b21966e5403c2d4b90a2704f3d70149ee5c7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:47:41 +0000 Subject: [PATCH 21/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- digital_image_processing/filters/laplacian_filter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 4435572e5f44..ecaa7ce3e769 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -17,7 +17,6 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: - """ :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, @@ -60,6 +59,7 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: return laplacian_result + if __name__ == "__main__": # read original image img = imread(r"digital_image_processing/image_data/lena.jpg") @@ -76,4 +76,4 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: imshow("Original image", img) imshow("Deteced edges using laplacian filter", laplacian_image) - waitKey(0) \ No newline at end of file + waitKey(0) From 2af89bc409641595a75eafb662ada9bbf34b83e4 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:49:56 -0700 Subject: [PATCH 22/36] updated laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 4435572e5f44..37a553cf3936 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -4,8 +4,8 @@ from cv2 import ( BORDER_DEFAULT, - CV_64F, COLOR_BGR2GRAY, + CV_64F, cvtColor, filter2D, imread, @@ -15,8 +15,7 @@ from gaussian_filter import gaussian_filter import numpy as np - -def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: +def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. @@ -76,4 +75,4 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: imshow("Original image", img) imshow("Deteced edges using laplacian filter", laplacian_image) - waitKey(0) \ No newline at end of file + waitKey(0) From 1c72a658bc75d547985e3b84c6f6295ea294d2fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:51:14 +0000 Subject: [PATCH 23/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- digital_image_processing/filters/laplacian_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index ae497624e31d..e0b838519273 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -15,8 +15,8 @@ from gaussian_filter import gaussian_filter import numpy as np -def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: +def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: """ :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, From 0ce40a23f3719128f1e1f433ff0fc8bbe429a371 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:53:49 -0700 Subject: [PATCH 24/36] update laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index ae497624e31d..b22e16374153 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -4,8 +4,8 @@ from cv2 import ( BORDER_DEFAULT, - COLOR_BGR2GRAY, CV_64F, + COLOR_BGR2GRAY, cvtColor, filter2D, imread, @@ -15,8 +15,8 @@ from gaussian_filter import gaussian_filter import numpy as np -def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: +def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: """ :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, From 891da5e1e2c7a6632be192b5e199ec2cdb685286 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 15:56:21 -0700 Subject: [PATCH 25/36] update laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index b22e16374153..a837ca16ad14 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -15,7 +15,6 @@ from gaussian_filter import gaussian_filter import numpy as np - def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. @@ -71,7 +70,7 @@ def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: blur_image = gaussian_filter(gray, 3, sigma=1) # Apply multiple Kernel to detect edges - laplacian_image = my_laplacian(blur_image, ksize=3) + laplacian_image = my_laplacian(ksize=3, src=blur_image) imshow("Original image", img) imshow("Deteced edges using laplacian filter", laplacian_image) From f52f3b565a979a45dce2bcf46efd5c3b08d86c4c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:56:58 +0000 Subject: [PATCH 26/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- digital_image_processing/filters/laplacian_filter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index a837ca16ad14..2fad1040f028 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -15,6 +15,7 @@ from gaussian_filter import gaussian_filter import numpy as np + def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. From 24d265bb39a9eafe5137183a4b7ba3d244ed48ef Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 16:00:35 -0700 Subject: [PATCH 27/36] update laplacian_filter.py --- .../filters/laplacian_filter.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index a837ca16ad14..1e2d451a3b1f 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,20 +2,12 @@ # @File : laplacian_filter.py # @Date : 10/04/2023 -from cv2 import ( - BORDER_DEFAULT, - CV_64F, - COLOR_BGR2GRAY, - cvtColor, - filter2D, - imread, - imshow, - waitKey, -) -from gaussian_filter import gaussian_filter import numpy as np +from cv2 import (BORDER_DEFAULT, COLOR_BGR2GRAY, CV_64F, cvtColor, filter2D, + imread, imshow, waitKey) +from gaussian_filter import gaussian_filter -def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: +def my_laplacian(ksize: int, src) -> np.ndarray: """ :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, From e36fa6ac98a4b5a3c5f59f9f9ae4923ef4f1d288 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:02:22 +0000 Subject: [PATCH 28/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../filters/laplacian_filter.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 1e2d451a3b1f..803481ccd987 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -3,10 +3,19 @@ # @Date : 10/04/2023 import numpy as np -from cv2 import (BORDER_DEFAULT, COLOR_BGR2GRAY, CV_64F, cvtColor, filter2D, - imread, imshow, waitKey) +from cv2 import ( + BORDER_DEFAULT, + COLOR_BGR2GRAY, + CV_64F, + cvtColor, + filter2D, + imread, + imshow, + waitKey, +) from gaussian_filter import gaussian_filter + def my_laplacian(ksize: int, src) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. From 84c02735c651c5633819a2cf548478a5984376cd Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 16:04:06 -0700 Subject: [PATCH 29/36] changed laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 1e2d451a3b1f..25c8994f12a0 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -7,7 +7,7 @@ imread, imshow, waitKey) from gaussian_filter import gaussian_filter -def my_laplacian(ksize: int, src) -> np.ndarray: +def my_laplacian(src:np.ndarray, ksize: int) -> np.ndarray: """ :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, From 3718979f0035dfc8c6663ed0776de8e3f0a40d17 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:06:41 +0000 Subject: [PATCH 30/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- digital_image_processing/filters/laplacian_filter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index bccdf3c226d8..555d810c0c0d 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -15,7 +15,8 @@ ) from gaussian_filter import gaussian_filter -def my_laplacian(src:np.ndarray, ksize: int) -> np.ndarray: + +def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: """ :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, From e30c558a2e03d93ecd3f05cb2e1bd965ccd3bd84 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 16:09:15 -0700 Subject: [PATCH 31/36] changed laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index bccdf3c226d8..cba76783ced3 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -13,7 +13,7 @@ imshow, waitKey, ) -from gaussian_filter import gaussian_filter +from digital_image_processing.filters.gaussian_filter import gaussian_filter def my_laplacian(src:np.ndarray, ksize: int) -> np.ndarray: """ @@ -61,7 +61,7 @@ def my_laplacian(src:np.ndarray, ksize: int) -> np.ndarray: if __name__ == "__main__": # read original image - img = imread(r"digital_image_processing/image_data/lena.jpg") + img = imread(r"../image_data/lena.jpg") # turn image in gray scale value gray = cvtColor(img, COLOR_BGR2GRAY) From 1bcbd8480768c4ab718efca9c935b7157b19a4b9 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 16:13:20 -0700 Subject: [PATCH 32/36] changed laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 0739666faada..a3531a0e0b33 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -16,7 +16,7 @@ from digital_image_processing.filters.gaussian_filter import gaussian_filter -def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: +def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: """ :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, From 532e38571cbf8603c809ef0e6e20b46f9a214f59 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 16:15:23 -0700 Subject: [PATCH 33/36] changed laplacian_filter.py --- digital_image_processing/filters/laplacian_filter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index a3531a0e0b33..ce64e8215728 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -15,8 +15,7 @@ ) from digital_image_processing.filters.gaussian_filter import gaussian_filter - -def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: +def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: """ :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, From e09582f8ae44af7704e168d51138f9b4869d668e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:15:59 +0000 Subject: [PATCH 34/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- digital_image_processing/filters/laplacian_filter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index ce64e8215728..0739666faada 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -15,6 +15,7 @@ ) from digital_image_processing.filters.gaussian_filter import gaussian_filter + def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: """ :param src: the source image, which should be a grayscale or color image. From 2d184c5a1d26691c02d55029f76dea281858b561 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 6 Oct 2023 01:28:43 +0200 Subject: [PATCH 35/36] Update laplacian_filter.py --- .../filters/laplacian_filter.py | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 0739666faada..72b0895da5eb 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -13,6 +13,7 @@ imshow, waitKey, ) + from digital_image_processing.filters.gaussian_filter import gaussian_filter @@ -21,16 +22,11 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: :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( + 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], @@ -38,9 +34,8 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: [0, -1, -2, -1, 0], [0, 0, -1, 0, 0], ] - ) - elif ksize == 7: - kernel = np.array( + ), + 7: np.array( [ [0, 0, 0, -1, 0, 0, 0], [0, 0, -2, -3, -2, 0, 0], @@ -50,15 +45,17 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: [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 - laplacian_result = filter2D( - src, CV_64F, kernel, 0, borderType=BORDER_DEFAULT, anchor=(0, 0) + return filter2D( + src, CV_64F, kernels[ksize], 0, borderType=BORDER_DEFAULT, anchor=(0, 0) ) - return laplacian_result - if __name__ == "__main__": # read original image @@ -74,6 +71,6 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: laplacian_image = my_laplacian(ksize=3, src=blur_image) imshow("Original image", img) - imshow("Deteced edges using laplacian filter", laplacian_image) + imshow("Detected edges using laplacian filter", laplacian_image) waitKey(0) From 7159ffe3e0f3f8b7fa7159408446f659be2c99a9 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 6 Oct 2023 01:35:16 +0200 Subject: [PATCH 36/36] Add a test --- digital_image_processing/filters/laplacian_filter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 72b0895da5eb..69b9616e4d30 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -21,7 +21,12 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: """ :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. + 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]]),