From 7672d1a8adca9c8c9ba11aa35f8b6f88c8541d9e Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Thu, 5 Oct 2023 00:17:42 -0700 Subject: [PATCH 01/75] 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/75] [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/75] 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/75] [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/75] 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/75] [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/75] 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/75] [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/75] 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/75] [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/75] 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/75] [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/75] 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/75] [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/75] 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/75] 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/75] [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/75] 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/75] [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/75] 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/75] [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/75] 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/75] [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/75] 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/75] 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/75] [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/75] 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/75] [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/75] 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/75] [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/75] 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/75] 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/75] 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 b1b6219f39edeb98b5417d8ba5c73c234a10b9e2 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 10:48:21 -0700 Subject: [PATCH 34/75] add matrix_multiplication.py --- maths/matrix_multiplication_recursion.py | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 maths/matrix_multiplication_recursion.py diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py new file mode 100644 index 000000000000..1d018ace3468 --- /dev/null +++ b/maths/matrix_multiplication_recursion.py @@ -0,0 +1,75 @@ +# @Author : ojas-wani +# @File : matrix_multiplication_recursion.py +# @Date : 10/06/2023 + + +""" +Introduction: + +This Python script demonstrates matrix multiplication using a recursive algorithm. +Matrix multiplication is a fundamental operation in linear algebra and computer science. +""" + + +def matrix_multiply_recursive(matrix_a: list, matrix_b: list): + """ + :param matrix_a: Input matrices. + :param matrix_b: Input matrices where length of matrices is + as same as number of columns matrix_a. + + """ + + # Check if matrices can be multiplied + if len(matrix_a[0]) != len(matrix_b): + raise ValueError("Invalid matrix dimensions") + + # Initialize the result matrix with zeros + result = [[0 for _ in range(len(matrix_b[0]))] + for _ in range(len(matrix_a))] + + # Recursive multiplication of matrices + def multiply(i, j, k, matrix_a, matrix_b, result): + """ + :param matrix_a: Input matrices. + :param matrix_b: Input matrices where length of matrices is + as same as number of columns matrix_a. + :param result: Result matrix + :param i: Indices used for iteration during multiplication. + :param j: Indices used for iteration during multiplication. + :param k: Indices used for iteration during multiplication. + """ + + if i >= len(matrix_a): + return + if j >= len(matrix_b[0]): + return multiply(matrix_a, matrix_b, result, i + 1, 0, 0) + if k >= len(matrix_b): + return multiply(matrix_a, matrix_b, result, i, j + 1, 0) + result[i][j] += matrix_a[i][k] * matrix_b[k][j] + multiply(matrix_a, matrix_b, result, i, j, k + 1) + + # Perform matrix multiplication + multiply(matrix_a, matrix_b, result, 0, 0, 0) + return result + + +if __name__ == "__main__": + + # Input matrixes + matrix_a = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], + [13, 14, 15, 16] + ] + matrix_b = [ + [5, 8, 1, 2], + [6, 7, 3, 0], + [4, 5, 9, 1], + [2, 6, 10, 14] + ] + + result_matrix = matrix_multiply_recursive(matrix_a, matrix_b) + for row in result_matrix: + print(row) From 44cd4873a3166357a6645c6da14c63ce7bd0ff32 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 17:54:10 +0000 Subject: [PATCH 35/75] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../filters/laplacian_filter.py | 7 +------ maths/matrix_multiplication_recursion.py | 19 ++++++------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 193ffaacb594..d7464d2c113c 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -17,6 +17,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. @@ -33,7 +34,6 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: 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], @@ -41,10 +41,8 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: [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], @@ -54,7 +52,6 @@ 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: @@ -67,7 +64,6 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: ) - if __name__ == "__main__": # read original image img = imread(r"../image_data/lena.jpg") @@ -85,5 +81,4 @@ def my_laplacian(src: np.ndarray, ksize: int) -> np.ndarray: imshow("Detected edges using laplacian filter", laplacian_image) - waitKey(0) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 1d018ace3468..6be372ec3781 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -6,7 +6,7 @@ """ Introduction: -This Python script demonstrates matrix multiplication using a recursive algorithm. +This Python script demonstrates matrix multiplication using a recursive algorithm. Matrix multiplication is a fundamental operation in linear algebra and computer science. """ @@ -14,7 +14,7 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list): """ :param matrix_a: Input matrices. - :param matrix_b: Input matrices where length of matrices is + :param matrix_b: Input matrices where length of matrices is as same as number of columns matrix_a. """ @@ -24,14 +24,13 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list): raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] - for _ in range(len(matrix_a))] + result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] # Recursive multiplication of matrices def multiply(i, j, k, matrix_a, matrix_b, result): """ :param matrix_a: Input matrices. - :param matrix_b: Input matrices where length of matrices is + :param matrix_b: Input matrices where length of matrices is as same as number of columns matrix_a. :param result: Result matrix :param i: Indices used for iteration during multiplication. @@ -54,21 +53,15 @@ def multiply(i, j, k, matrix_a, matrix_b, result): if __name__ == "__main__": - # Input matrixes matrix_a = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], - [13, 14, 15, 16] - ] - matrix_b = [ - [5, 8, 1, 2], - [6, 7, 3, 0], - [4, 5, 9, 1], - [2, 6, 10, 14] + [13, 14, 15, 16], ] + matrix_b = [[5, 8, 1, 2], [6, 7, 3, 0], [4, 5, 9, 1], [2, 6, 10, 14]] result_matrix = matrix_multiply_recursive(matrix_a, matrix_b) for row in result_matrix: From ab314c60da69e6bd1fadc9c40462effad60b48c3 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 10:55:41 -0700 Subject: [PATCH 36/75] update matrix_multiplication --- maths/matrix_multiplication_recursion.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 6be372ec3781..d1701349dd88 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -11,7 +11,7 @@ """ -def matrix_multiply_recursive(matrix_a: list, matrix_b: list): +def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is @@ -27,7 +27,7 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list): result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] # Recursive multiplication of matrices - def multiply(i, j, k, matrix_a, matrix_b, result): + def multiply(i_loop, j_loop, k_loop, matrix_a, matrix_b, result): """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is @@ -38,14 +38,14 @@ def multiply(i, j, k, matrix_a, matrix_b, result): :param k: Indices used for iteration during multiplication. """ - if i >= len(matrix_a): + if i_loop >= len(matrix_a): return - if j >= len(matrix_b[0]): - return multiply(matrix_a, matrix_b, result, i + 1, 0, 0) - if k >= len(matrix_b): - return multiply(matrix_a, matrix_b, result, i, j + 1, 0) - result[i][j] += matrix_a[i][k] * matrix_b[k][j] - multiply(matrix_a, matrix_b, result, i, j, k + 1) + if j_loop >= len(matrix_b[0]): + return multiply(matrix_a, matrix_b, result, i_loop + 1, 0, 0) + if k_loop >= len(matrix_b): + return multiply(matrix_a, matrix_b, result, i_loop, j_loop + 1, 0) + result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] + multiply(matrix_a, matrix_b, result, i_loop, j_loop, k_loop + 1) # Perform matrix multiplication multiply(matrix_a, matrix_b, result, 0, 0, 0) From 2cf909075444f95663e32f42f49f15b6975a26fc Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 10:57:31 -0700 Subject: [PATCH 37/75] update matrix_multiplication --- maths/matrix_multiplication_recursion.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index d1701349dd88..4fc6287189f3 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -24,10 +24,11 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] + result = [[0 for _ in range(len(matrix_b[0]))] + for _ in range(len(matrix_a))] # Recursive multiplication of matrices - def multiply(i_loop, j_loop, k_loop, matrix_a, matrix_b, result): + def multiply(i_loop: int, j_loop: int, k_loop: int, matrix_a: list, matrix_b: list, result: list) -> function: """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is @@ -44,7 +45,8 @@ def multiply(i_loop, j_loop, k_loop, matrix_a, matrix_b, result): return multiply(matrix_a, matrix_b, result, i_loop + 1, 0, 0) if k_loop >= len(matrix_b): return multiply(matrix_a, matrix_b, result, i_loop, j_loop + 1, 0) - result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] + result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * \ + matrix_b[k_loop][j_loop] multiply(matrix_a, matrix_b, result, i_loop, j_loop, k_loop + 1) # Perform matrix multiplication From 2e4151cfd9b48a339e49009cf3edfc596a192091 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 17:58:06 +0000 Subject: [PATCH 38/75] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/matrix_multiplication_recursion.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 4fc6287189f3..9634f5d256a6 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -24,11 +24,17 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] - for _ in range(len(matrix_a))] + result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] # Recursive multiplication of matrices - def multiply(i_loop: int, j_loop: int, k_loop: int, matrix_a: list, matrix_b: list, result: list) -> function: + def multiply( + i_loop: int, + j_loop: int, + k_loop: int, + matrix_a: list, + matrix_b: list, + result: list, + ) -> function: """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is @@ -45,8 +51,7 @@ def multiply(i_loop: int, j_loop: int, k_loop: int, matrix_a: list, matrix_b: li return multiply(matrix_a, matrix_b, result, i_loop + 1, 0, 0) if k_loop >= len(matrix_b): return multiply(matrix_a, matrix_b, result, i_loop, j_loop + 1, 0) - result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * \ - matrix_b[k_loop][j_loop] + result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] multiply(matrix_a, matrix_b, result, i_loop, j_loop, k_loop + 1) # Perform matrix multiplication From 9765feac8168ffe8447791f1e583effbc4f494d8 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 10:59:14 -0700 Subject: [PATCH 39/75] make changes --- maths/matrix_multiplication_recursion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 4fc6287189f3..db704f556696 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -28,7 +28,8 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: for _ in range(len(matrix_a))] # Recursive multiplication of matrices - def multiply(i_loop: int, j_loop: int, k_loop: int, matrix_a: list, matrix_b: list, result: list) -> function: + def multiply(i_loop: int, j_loop: int, k_loop: int, matrix_a: list, + matrix_b: list, result: list) -> multiply: """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is From 8bd1970c06965b45b5b8c2d28cebd87d10dbdd52 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 18:01:11 +0000 Subject: [PATCH 40/75] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/matrix_multiplication_recursion.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index ce3327f3a9e0..9634f5d256a6 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -68,12 +68,7 @@ def multiply( [13, 14, 15, 16], [13, 14, 15, 16], ] - matrix_b = [ - [5, 8, 1, 2], - [6, 7, 3, 0], - [4, 5, 9, 1], - [2, 6, 10, 14] - ] + matrix_b = [[5, 8, 1, 2], [6, 7, 3, 0], [4, 5, 9, 1], [2, 6, 10, 14]] result_matrix = matrix_multiply_recursive(matrix_a, matrix_b) for row in result_matrix: From 250211937996e231b4d4e7e5a765160a733668f8 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 11:01:46 -0700 Subject: [PATCH 41/75] update --- maths/matrix_multiplication_recursion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index ce3327f3a9e0..306549c78081 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -34,7 +34,7 @@ def multiply( matrix_a: list, matrix_b: list, result: list, - ) -> function: + ) -> multiply: """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is From 909331b97081a907d0f52773642aa28e92827fd0 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 11:03:22 -0700 Subject: [PATCH 42/75] update --- maths/matrix_multiplication_recursion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index f0b0485b1212..36cea959dbb8 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -34,7 +34,7 @@ def multiply( matrix_a: list, matrix_b: list, result: list, - ) -> multiply: + ) -> multiply(): """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is From e05b5243a562f787c18f8dbff7b154f8da9b5a80 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 11:09:23 -0700 Subject: [PATCH 43/75] updates --- maths/matrix_multiplication_recursion.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 36cea959dbb8..be6c32a9218c 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -34,7 +34,7 @@ def multiply( matrix_a: list, matrix_b: list, result: list, - ) -> multiply(): + ) -> None: """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is @@ -48,11 +48,11 @@ def multiply( if i_loop >= len(matrix_a): return if j_loop >= len(matrix_b[0]): - return multiply(matrix_a, matrix_b, result, i_loop + 1, 0, 0) + return multiply(i_loop + 1, 0, 0, matrix_a, matrix_b, result) if k_loop >= len(matrix_b): return multiply(matrix_a, matrix_b, result, i_loop, j_loop + 1, 0) result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] - multiply(matrix_a, matrix_b, result, i_loop, j_loop, k_loop + 1) + multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) # Perform matrix multiplication multiply(matrix_a, matrix_b, result, 0, 0, 0) From 39d0871e682603785a5d6eadb37f61c46eda5376 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 11:21:46 -0700 Subject: [PATCH 44/75] resolve conflict --- 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 d7464d2c113c..9777759fad55 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -18,7 +18,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 5203d8bf277dd0051227992751a69992ca94a492 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 11:53:54 -0700 Subject: [PATCH 45/75] add doctest --- maths/matrix_multiplication_recursion.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index be6c32a9218c..d1199b8c80c5 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -24,7 +24,8 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] + result = [[0 for _ in range(len(matrix_b[0]))] + for _ in range(len(matrix_a))] # Recursive multiplication of matrices def multiply( @@ -43,6 +44,20 @@ def multiply( :param i: Indices used for iteration during multiplication. :param j: Indices used for iteration during multiplication. :param k: Indices used for iteration during multiplication. + + >>> matrix_a = [[1, 2], [3, 4]] + >>> matrix_b = [[5, 6], [7, 8]] + >>> result = [[0, 0], [0, 0]] + >>> multiply(0, 0, 0, matrix_a, matrix_b, result) + >>> result + [[19, 22], [43, 50]] + + >>> matrix_a = [[1, 2], [3, 4]] + >>> matrix_b = [[5, 6, 7], [8, 9, 10]] + >>> result = [[0, 0, 0], [0, 0, 0]] + >>> multiply(0, 0, 0, matrix_a, matrix_b, result) + >>> result + [[21, 24, 27], [47, 54, 61]] """ if i_loop >= len(matrix_a): @@ -51,7 +66,8 @@ def multiply( return multiply(i_loop + 1, 0, 0, matrix_a, matrix_b, result) if k_loop >= len(matrix_b): return multiply(matrix_a, matrix_b, result, i_loop, j_loop + 1, 0) - result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] + result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * \ + matrix_b[k_loop][j_loop] multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) # Perform matrix multiplication From 620ba2c92e363f3bbb1a011f74b44982584718fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 18:54:32 +0000 Subject: [PATCH 46/75] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/matrix_multiplication_recursion.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index d1199b8c80c5..80d0c8ee3578 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -24,8 +24,7 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] - for _ in range(len(matrix_a))] + result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] # Recursive multiplication of matrices def multiply( @@ -44,7 +43,7 @@ def multiply( :param i: Indices used for iteration during multiplication. :param j: Indices used for iteration during multiplication. :param k: Indices used for iteration during multiplication. - + >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] >>> result = [[0, 0], [0, 0]] @@ -66,8 +65,7 @@ def multiply( return multiply(i_loop + 1, 0, 0, matrix_a, matrix_b, result) if k_loop >= len(matrix_b): return multiply(matrix_a, matrix_b, result, i_loop, j_loop + 1, 0) - result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * \ - matrix_b[k_loop][j_loop] + result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) # Perform matrix multiplication From c6c5cfda1ec02eb9d8b4b2b214720169627ae433 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 11:56:59 -0700 Subject: [PATCH 47/75] make changes --- digital_image_processing/filters/laplacian_filter.py | 4 +--- maths/matrix_multiplication_recursion.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 9777759fad55..591d114e0924 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,7 +2,6 @@ # @File : laplacian_filter.py # @Date : 10/04/2023 -import numpy as np from cv2 import ( BORDER_DEFAULT, COLOR_BGR2GRAY, @@ -14,9 +13,8 @@ waitKey, ) - from digital_image_processing.filters.gaussian_filter import gaussian_filter - +import numpy as np def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: """ diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index d1199b8c80c5..7b46d2102e03 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -44,7 +44,7 @@ def multiply( :param i: Indices used for iteration during multiplication. :param j: Indices used for iteration during multiplication. :param k: Indices used for iteration during multiplication. - + >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] >>> result = [[0, 0], [0, 0]] From 8bfeeb219fe7e724decafa1b104f579a2b7e895e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 18:58:32 +0000 Subject: [PATCH 48/75] [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 591d114e0924..1b2ca8dcece8 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -16,6 +16,7 @@ from digital_image_processing.filters.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 bf6d95a4e76b909c428fd2e54ccc388d0306778e Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:01:57 -0700 Subject: [PATCH 49/75] update laplacian.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 1b2ca8dcece8..207927b7f9ff 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,13 +2,12 @@ # @File : laplacian_filter.py # @Date : 10/04/2023 +import cv2 from cv2 import ( BORDER_DEFAULT, COLOR_BGR2GRAY, - CV_64F, cvtColor, filter2D, - imread, imshow, waitKey, ) @@ -59,13 +58,13 @@ def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: # Apply the Laplacian kernel using convolution return filter2D( - src, CV_64F, kernels[ksize], 0, borderType=BORDER_DEFAULT, anchor=(0, 0) + src, cv2.CV_64F, kernels[ksize], 0, borderType=BORDER_DEFAULT, anchor=(0, 0) ) if __name__ == "__main__": # read original image - img = imread(r"../image_data/lena.jpg") + img = cv2.imread(r"../image_data/lena.jpg") # turn image in gray scale value gray = cvtColor(img, COLOR_BGR2GRAY) From e42fafc0d256e5205933514f439c176eaf3c66b8 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:04:20 -0700 Subject: [PATCH 50/75] add doctests --- maths/matrix_multiplication_recursion.py | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 80d0c8ee3578..a78654788c66 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -17,6 +17,19 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: :param matrix_b: Input matrices where length of matrices is as same as number of columns matrix_a. + >>> matrix_a = [[1, 2], [3, 4]] + >>> matrix_b = [[5, 6], [7, 8]] + >>> result = [[0, 0], [0, 0]] + >>> multiply(0, 0, 0, matrix_a, matrix_b, result) + >>> result + [[19, 22], [43, 50]] + + >>> matrix_a = [[1, 2], [3, 4]] + >>> matrix_b = [[5, 6, 7], [8, 9, 10]] + >>> result = [[0, 0, 0], [0, 0, 0]] + >>> multiply(0, 0, 0, matrix_a, matrix_b, result) + >>> result + [[21, 24, 27], [47, 54, 61]] """ # Check if matrices can be multiplied @@ -44,19 +57,6 @@ def multiply( :param j: Indices used for iteration during multiplication. :param k: Indices used for iteration during multiplication. - >>> matrix_a = [[1, 2], [3, 4]] - >>> matrix_b = [[5, 6], [7, 8]] - >>> result = [[0, 0], [0, 0]] - >>> multiply(0, 0, 0, matrix_a, matrix_b, result) - >>> result - [[19, 22], [43, 50]] - - >>> matrix_a = [[1, 2], [3, 4]] - >>> matrix_b = [[5, 6, 7], [8, 9, 10]] - >>> result = [[0, 0, 0], [0, 0, 0]] - >>> multiply(0, 0, 0, matrix_a, matrix_b, result) - >>> result - [[21, 24, 27], [47, 54, 61]] """ if i_loop >= len(matrix_a): From d87b51f7aace198d9e8f49554b6e4f07d12f43c8 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:07:52 -0700 Subject: [PATCH 51/75] more doctest added --- .../filters/laplacian_filter.py | 2 +- maths/matrix_multiplication_recursion.py | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 207927b7f9ff..e5cd947b701b 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -16,7 +16,7 @@ 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. :param ksize: the size of the kernel used to compute the Laplacian filter, diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index a78654788c66..62fec7005a62 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -30,6 +30,7 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: >>> multiply(0, 0, 0, matrix_a, matrix_b, result) >>> result [[21, 24, 27], [47, 54, 61]] + """ # Check if matrices can be multiplied @@ -37,7 +38,8 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] + result = [[0 for _ in range(len(matrix_b[0]))] + for _ in range(len(matrix_a))] # Recursive multiplication of matrices def multiply( @@ -57,6 +59,20 @@ def multiply( :param j: Indices used for iteration during multiplication. :param k: Indices used for iteration during multiplication. + >>> matrix_a = [[1, 2], [3, 4]] + >>> matrix_b = [[5, 6], [7, 8]] + >>> result = [[0, 0], [0, 0]] + >>> multiply(0, 0, 0, matrix_a, matrix_b, result) + >>> result + [[19, 22], [43, 50]] + + >>> matrix_a = [[1, 2], [3, 4]] + >>> matrix_b = [[5, 6, 7], [8, 9, 10]] + >>> result = [[0, 0, 0], [0, 0, 0]] + >>> multiply(0, 0, 0, matrix_a, matrix_b, result) + >>> result + [[21, 24, 27], [47, 54, 61]] + """ if i_loop >= len(matrix_a): @@ -65,7 +81,8 @@ def multiply( return multiply(i_loop + 1, 0, 0, matrix_a, matrix_b, result) if k_loop >= len(matrix_b): return multiply(matrix_a, matrix_b, result, i_loop, j_loop + 1, 0) - result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] + result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * \ + matrix_b[k_loop][j_loop] multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) # Perform matrix multiplication From ac92bef48972ef44f1cfddf8261115ba2c2fe35d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 19:08:32 +0000 Subject: [PATCH 52/75] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/matrix_multiplication_recursion.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 62fec7005a62..69843e654ef0 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -38,8 +38,7 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] - for _ in range(len(matrix_a))] + result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] # Recursive multiplication of matrices def multiply( @@ -81,8 +80,7 @@ def multiply( return multiply(i_loop + 1, 0, 0, matrix_a, matrix_b, result) if k_loop >= len(matrix_b): return multiply(matrix_a, matrix_b, result, i_loop, j_loop + 1, 0) - result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * \ - matrix_b[k_loop][j_loop] + result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) # Perform matrix multiplication From 1422b875e82b88ae497b5500c85d195b60df607e Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:12:18 -0700 Subject: [PATCH 53/75] try to resolve ruff error --- digital_image_processing/filters/laplacian_filter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index e5cd947b701b..36a79a5e96db 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -1,7 +1,6 @@ # @Author : ojas-wani # @File : laplacian_filter.py # @Date : 10/04/2023 - import cv2 from cv2 import ( BORDER_DEFAULT, From 21f6956f52155ce0c55867550c7221f9d63c720d Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:12:42 -0700 Subject: [PATCH 54/75] try to reslve ruff error --- 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 36a79a5e96db..220fc449e31d 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -8,7 +8,7 @@ cvtColor, filter2D, imshow, - waitKey, + waitKey ) from digital_image_processing.filters.gaussian_filter import gaussian_filter From f4db7d9ecaf847a2c0cd1f41b015abb96274d8f2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 19:13:26 +0000 Subject: [PATCH 55/75] [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 | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/digital_image_processing/filters/laplacian_filter.py b/digital_image_processing/filters/laplacian_filter.py index 220fc449e31d..773925b461cc 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,14 +2,7 @@ # @File : laplacian_filter.py # @Date : 10/04/2023 import cv2 -from cv2 import ( - BORDER_DEFAULT, - COLOR_BGR2GRAY, - cvtColor, - filter2D, - imshow, - waitKey -) +from cv2 import BORDER_DEFAULT, COLOR_BGR2GRAY, cvtColor, filter2D, imshow, waitKey from digital_image_processing.filters.gaussian_filter import gaussian_filter import numpy as np From cc0b4aa3e5f286dcb940c3a09de06ea1a8fc5e83 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:19:50 -0700 Subject: [PATCH 56/75] update doctest --- maths/matrix_multiplication_recursion.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 69843e654ef0..3f69a80009f5 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -20,14 +20,14 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] >>> result = [[0, 0], [0, 0]] - >>> multiply(0, 0, 0, matrix_a, matrix_b, result) + >>> matrix_multiply_recursive(matrix_a, matrix_b) >>> result [[19, 22], [43, 50]] >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6, 7], [8, 9, 10]] >>> result = [[0, 0, 0], [0, 0, 0]] - >>> multiply(0, 0, 0, matrix_a, matrix_b, result) + >>> matrix_multiply_recursive(matrix_a, matrix_b) >>> result [[21, 24, 27], [47, 54, 61]] @@ -62,15 +62,11 @@ def multiply( >>> matrix_b = [[5, 6], [7, 8]] >>> result = [[0, 0], [0, 0]] >>> multiply(0, 0, 0, matrix_a, matrix_b, result) - >>> result - [[19, 22], [43, 50]] >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6, 7], [8, 9, 10]] >>> result = [[0, 0, 0], [0, 0, 0]] >>> multiply(0, 0, 0, matrix_a, matrix_b, result) - >>> result - [[21, 24, 27], [47, 54, 61]] """ From d4e7c774c9d63b2b2016d7bc14a9eadee6fba12b Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:22:36 -0700 Subject: [PATCH 57/75] attemp - resolve ruff error --- 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 773925b461cc..9b0434f00c43 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -8,7 +8,7 @@ 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. :param ksize: the size of the kernel used to compute the Laplacian filter, From 057a2b42b1e49590c0476d73c523a72ce504a9c6 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:36:10 -0700 Subject: [PATCH 58/75] resolve build error --- maths/matrix_multiplication_recursion.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 3f69a80009f5..e0faf25ed44f 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -38,7 +38,8 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] + result = [[0 for _ in range(len(matrix_b[0]))] + for _ in range(len(matrix_a))] # Recursive multiplication of matrices def multiply( @@ -48,7 +49,7 @@ def multiply( matrix_a: list, matrix_b: list, result: list, - ) -> None: + ) -> any: """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is @@ -75,12 +76,13 @@ def multiply( if j_loop >= len(matrix_b[0]): return multiply(i_loop + 1, 0, 0, matrix_a, matrix_b, result) if k_loop >= len(matrix_b): - return multiply(matrix_a, matrix_b, result, i_loop, j_loop + 1, 0) - result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] + return multiply(i_loop, j_loop + 1, 0, matrix_a, matrix_b, result) + result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * \ + matrix_b[k_loop][j_loop] multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) # Perform matrix multiplication - multiply(matrix_a, matrix_b, result, 0, 0, 0) + multiply(0, 0, 0, matrix_a, matrix_b, result) return result From 734052837924fece1e605289233850479187b9b0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 19:36:49 +0000 Subject: [PATCH 59/75] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/matrix_multiplication_recursion.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index e0faf25ed44f..19ad66ea2a7e 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -38,8 +38,7 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] - for _ in range(len(matrix_a))] + result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] # Recursive multiplication of matrices def multiply( @@ -77,8 +76,7 @@ def multiply( return multiply(i_loop + 1, 0, 0, matrix_a, matrix_b, result) if k_loop >= len(matrix_b): return multiply(i_loop, j_loop + 1, 0, matrix_a, matrix_b, result) - result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * \ - matrix_b[k_loop][j_loop] + result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) # Perform matrix multiplication From 8ef62445e7be0f812af477d1696763b6c97f5674 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:43:10 -0700 Subject: [PATCH 60/75] resolve build issue --- maths/matrix_multiplication_recursion.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index e0faf25ed44f..7bf4ec99627e 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -19,14 +19,12 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] - >>> result = [[0, 0], [0, 0]] >>> matrix_multiply_recursive(matrix_a, matrix_b) >>> result [[19, 22], [43, 50]] >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6, 7], [8, 9, 10]] - >>> result = [[0, 0, 0], [0, 0, 0]] >>> matrix_multiply_recursive(matrix_a, matrix_b) >>> result [[21, 24, 27], [47, 54, 61]] @@ -61,12 +59,10 @@ def multiply( >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] - >>> result = [[0, 0], [0, 0]] >>> multiply(0, 0, 0, matrix_a, matrix_b, result) >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6, 7], [8, 9, 10]] - >>> result = [[0, 0, 0], [0, 0, 0]] >>> multiply(0, 0, 0, matrix_a, matrix_b, result) """ @@ -87,6 +83,7 @@ def multiply( if __name__ == "__main__": + # Input matrixes matrix_a = [ [1, 2, 3, 4], From 9a486c966c365f4696cf84ff8655f3f98ebde11b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 19:43:43 +0000 Subject: [PATCH 61/75] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/matrix_multiplication_recursion.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index fe18b3bd12d4..19c0cd1a14b8 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -81,7 +81,6 @@ def multiply( if __name__ == "__main__": - # Input matrixes matrix_a = [ [1, 2, 3, 4], From 306bba0ea0b79c1aa62c97e0966e8152d258ce69 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 12:59:34 -0700 Subject: [PATCH 62/75] update build --- maths/matrix_multiplication_recursion.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 19c0cd1a14b8..9520415190fc 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -19,13 +19,11 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] - >>> matrix_multiply_recursive(matrix_a, matrix_b) >>> result [[19, 22], [43, 50]] >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6, 7], [8, 9, 10]] - >>> matrix_multiply_recursive(matrix_a, matrix_b) >>> result [[21, 24, 27], [47, 54, 61]] From 09674b1d852baa42a3e46f836d571eef81737b41 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 13:28:26 -0700 Subject: [PATCH 63/75] doctest update --- maths/matrix_multiplication_recursion.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 9520415190fc..a39189d4dad5 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -19,13 +19,12 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] - >>> result - [[19, 22], [43, 50]] + >>> matrix_multiply_recursive(matrix_a, matrix_b) + >>> [[19, 22], [43, 50]] >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6, 7], [8, 9, 10]] - >>> result - [[21, 24, 27], [47, 54, 61]] + >>> [[21, 24, 27], [47, 54, 61]] """ From 09aca9f67eb4372296a28cf4c2d8746525d089ee Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 13:28:45 -0700 Subject: [PATCH 64/75] update doctest --- maths/matrix_multiplication_recursion.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index a39189d4dad5..1f0ced3f00b8 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -19,7 +19,6 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] - >>> matrix_multiply_recursive(matrix_a, matrix_b) >>> [[19, 22], [43, 50]] >>> matrix_a = [[1, 2], [3, 4]] From 7b314643c1b27092409589bf233b75c57927e79e Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 13:33:16 -0700 Subject: [PATCH 65/75] update doctest --- maths/matrix_multiplication_recursion.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 1f0ced3f00b8..1de3e7926cc3 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -19,10 +19,12 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] + >>> matrix_multiply_recursive(matrix_a, matrix_b) >>> [[19, 22], [43, 50]] >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6, 7], [8, 9, 10]] + >>> matrix_multiply_recursive(matrix_a, matrix_b) >>> [[21, 24, 27], [47, 54, 61]] """ From 46837d074a46d1b999646a89b69ab6104c98cc6a Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 13:38:03 -0700 Subject: [PATCH 66/75] update doctest --- maths/matrix_multiplication_recursion.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/maths/matrix_multiplication_recursion.py b/maths/matrix_multiplication_recursion.py index 1de3e7926cc3..1aecb3b1b794 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/maths/matrix_multiplication_recursion.py @@ -19,13 +19,9 @@ def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6], [7, 8]] - >>> matrix_multiply_recursive(matrix_a, matrix_b) - >>> [[19, 22], [43, 50]] >>> matrix_a = [[1, 2], [3, 4]] >>> matrix_b = [[5, 6, 7], [8, 9, 10]] - >>> matrix_multiply_recursive(matrix_a, matrix_b) - >>> [[21, 24, 27], [47, 54, 61]] """ From 87e37dd82eb0ab7f45cb1108e5069cd1bea74094 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sat, 7 Oct 2023 13:48:06 -0700 Subject: [PATCH 67/75] fix ruff error --- 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 9b0434f00c43..122d6a0e5add 100644 --- a/digital_image_processing/filters/laplacian_filter.py +++ b/digital_image_processing/filters/laplacian_filter.py @@ -2,10 +2,10 @@ # @File : laplacian_filter.py # @Date : 10/04/2023 import cv2 +import numpy as np from cv2 import BORDER_DEFAULT, COLOR_BGR2GRAY, cvtColor, filter2D, imshow, waitKey from digital_image_processing.filters.gaussian_filter import gaussian_filter -import numpy as np def my_laplacian(ksize: int, src: np.ndarray) -> np.ndarray: From 5a044dd53acba9df37d3edfaa7de7e6f4e6d6c18 Mon Sep 17 00:00:00 2001 From: ojas-wani Date: Sun, 8 Oct 2023 02:05:40 -0700 Subject: [PATCH 68/75] file location changed --- {maths => matrix}/matrix_multiplication_recursion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename {maths => matrix}/matrix_multiplication_recursion.py (96%) diff --git a/maths/matrix_multiplication_recursion.py b/matrix/matrix_multiplication_recursion.py similarity index 96% rename from maths/matrix_multiplication_recursion.py rename to matrix/matrix_multiplication_recursion.py index 1aecb3b1b794..88c34c5d24b9 100644 --- a/maths/matrix_multiplication_recursion.py +++ b/matrix/matrix_multiplication_recursion.py @@ -40,7 +40,7 @@ def multiply( matrix_a: list, matrix_b: list, result: list, - ) -> any: + ) -> None: """ :param matrix_a: Input matrices. :param matrix_b: Input matrices where length of matrices is @@ -67,7 +67,7 @@ def multiply( if k_loop >= len(matrix_b): return multiply(i_loop, j_loop + 1, 0, matrix_a, matrix_b, result) result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] - multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) + return multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) # Perform matrix multiplication multiply(0, 0, 0, matrix_a, matrix_b, result) From d7fc69645a73079f8c894080df0773e03c734103 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 8 Oct 2023 11:20:39 +0200 Subject: [PATCH 69/75] Delete digital_image_processing/filters/laplacian_filter.py --- .../filters/laplacian_filter.py | 74 ------------------- 1 file changed, 74 deletions(-) delete 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 deleted file mode 100644 index 122d6a0e5add..000000000000 --- a/digital_image_processing/filters/laplacian_filter.py +++ /dev/null @@ -1,74 +0,0 @@ -# @Author : ojas-wani -# @File : laplacian_filter.py -# @Date : 10/04/2023 -import cv2 -import numpy as np -from cv2 import BORDER_DEFAULT, COLOR_BGR2GRAY, cvtColor, filter2D, imshow, waitKey - -from digital_image_processing.filters.gaussian_filter import gaussian_filter - - -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, - - 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, cv2.CV_64F, kernels[ksize], 0, borderType=BORDER_DEFAULT, anchor=(0, 0) - ) - - -if __name__ == "__main__": - # read original image - img = cv2.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) From 5650d8b1f49b8a41e21228d12f258597b4dc059e Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 17 Oct 2023 08:17:44 +0200 Subject: [PATCH 70/75] Create laplacian_filter.py --- .../filters/laplacian_filter.py | 81 +++++++++++++++++++ 1 file changed, 81 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..69b9616e4d30 --- /dev/null +++ b/digital_image_processing/filters/laplacian_filter.py @@ -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, +) + +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. + :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) From a3052c2471e0a29d9f224b9e050e96802c450f3d Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 17 Oct 2023 10:34:33 +0200 Subject: [PATCH 71/75] Update matrix_multiplication_recursion.py --- matrix/matrix_multiplication_recursion.py | 167 +++++++++++++++------- 1 file changed, 113 insertions(+), 54 deletions(-) diff --git a/matrix/matrix_multiplication_recursion.py b/matrix/matrix_multiplication_recursion.py index 88c34c5d24b9..8b471a662eaf 100644 --- a/matrix/matrix_multiplication_recursion.py +++ b/matrix/matrix_multiplication_recursion.py @@ -4,62 +4,114 @@ """ -Introduction: - -This Python script demonstrates matrix multiplication using a recursive algorithm. -Matrix multiplication is a fundamental operation in linear algebra and computer science. +Perform matrix multiplication using a recursive algorithm. +https://en.wikipedia.org/wiki/Matrix_multiplication """ - - -def matrix_multiply_recursive(matrix_a: list, matrix_b: list) -> list: +# type Matrix = list[list[int]] # psf/black currenttly fails on this line +Matrix = list[list[int]] + +matrix_1_to_4 = [ + [1, 2], + [3, 4], +] + +matrix_5_to_8 = [ + [5, 6], + [7, 8], +] + +matrix_5_to_9_wide = [ + [5, 6], + [7, 8, 9], +] + +matrix_5_to_9_high = [ + [5, 6], + [7, 8], + [9], +] + +matrix_count_up = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], +] + +matrix_unordered = [ + [5, 8, 1, 2], + [6, 7, 3, 0], + [4, 5, 9, 1], + [2, 6, 10, 14], +] +matrices = ( + matrix_1_to_4, + matrix_5_to_8, + matrix_5_to_9_wide, + matrix_5_to_9_high, + matrix_count_up, + matrix_unordered, +) + + +def is_square(matrix: Matrix) -> bool: + len_matrix = len(matrix) + return all(len(row) == len_matrix for row in matrix) + + +def matrix_multiply_recursive(matrix_a: Matrix, matrix_b: Matrix) -> Matrix: """ - :param matrix_a: Input matrices. - :param matrix_b: Input matrices where length of matrices is - as same as number of columns matrix_a. - - >>> matrix_a = [[1, 2], [3, 4]] - >>> matrix_b = [[5, 6], [7, 8]] - - >>> matrix_a = [[1, 2], [3, 4]] - >>> matrix_b = [[5, 6, 7], [8, 9, 10]] - + :param matrix_a: A square Matrix. + :param matrix_b: Another square Matrix with the same dimensions as matrix_a. + :return: Result of matrix_a * matrix_b. + :raises ValueError: If the matrices cannot be multiplied. + + >>> matrix_multiply_recursive([], []) + [] + >>> matrix_multiply_recursive(matrix_1_to_4, matrix_5_to_8) + [[19, 22], [43, 50]] + >>> matrix_multiply_recursive(matrix_count_up, matrix_unordered) + [[37, 61, 74, 61], [105, 165, 166, 129], [173, 269, 258, 197], [241, 373, 350, 265]] + >>> matrix_multiply_recursive(matrix_1_to_4, matrix_5_to_9_wide) + Traceback (most recent call last): + ... + ValueError: Invalid matrix dimensions + >>> matrix_multiply_recursive(matrix_1_to_4, matrix_5_to_9_high) + Traceback (most recent call last): + ... + ValueError: Invalid matrix dimensions + >>> matrix_multiply_recursive(matrix_1_to_4, matrix_count_up) + Traceback (most recent call last): + ... + ValueError: Invalid matrix dimensions """ - - # Check if matrices can be multiplied - if len(matrix_a[0]) != len(matrix_b): + if not matrix_a or not matrix_b: + return [] + if not all( + (len(matrix_a) == len(matrix_b), is_square(matrix_a), is_square(matrix_b)) + ): raise ValueError("Invalid matrix dimensions") # Initialize the result matrix with zeros - result = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))] + result = [[0] * len(matrix_b[0]) for _ in range(len(matrix_a))] # Recursive multiplication of matrices def multiply( i_loop: int, j_loop: int, k_loop: int, - matrix_a: list, - matrix_b: list, - result: list, + matrix_a: Matrix, + matrix_b: Matrix, + result: Matrix, ) -> None: """ - :param matrix_a: Input matrices. - :param matrix_b: Input matrices where length of matrices is - as same as number of columns matrix_a. + :param matrix_a: A square Matrix. + :param matrix_b: Another square Matrix with the same dimensions as matrix_a. :param result: Result matrix - :param i: Indices used for iteration during multiplication. - :param j: Indices used for iteration during multiplication. - :param k: Indices used for iteration during multiplication. - - >>> matrix_a = [[1, 2], [3, 4]] - >>> matrix_b = [[5, 6], [7, 8]] - >>> multiply(0, 0, 0, matrix_a, matrix_b, result) - - >>> matrix_a = [[1, 2], [3, 4]] - >>> matrix_b = [[5, 6, 7], [8, 9, 10]] - >>> multiply(0, 0, 0, matrix_a, matrix_b, result) - + :param i: Index used for iteration during multiplication. + :param j: Index used for iteration during multiplication. + :param k: Index used for iteration during multiplication. """ - if i_loop >= len(matrix_a): return if j_loop >= len(matrix_b[0]): @@ -69,22 +121,29 @@ def multiply( result[i_loop][j_loop] += matrix_a[i_loop][k_loop] * matrix_b[k_loop][j_loop] return multiply(i_loop, j_loop, k_loop + 1, matrix_a, matrix_b, result) - # Perform matrix multiplication + # Perform the recursive matrix multiplication multiply(0, 0, 0, matrix_a, matrix_b, result) return result if __name__ == "__main__": - # Input matrixes - matrix_a = [ - [1, 2, 3, 4], - [5, 6, 7, 8], - [9, 10, 11, 12], - [13, 14, 15, 16], - [13, 14, 15, 16], - ] - matrix_b = [[5, 8, 1, 2], [6, 7, 3, 0], [4, 5, 9, 1], [2, 6, 10, 14]] - - result_matrix = matrix_multiply_recursive(matrix_a, matrix_b) - for row in result_matrix: - print(row) + from doctest import testmod + + failure_count, test_count = testmod() + if not failure_count: + matrix_a = matrices[0] + for matrix_b in matrices[1:]: + print("Multiplying:") + for row in matrix_a: + print(row) + print("By:") + for row in matrix_b: + print(row) + print("Result:") + try: + for row in matrix_multiply_recursive(matrix_a, matrix_b): + print(row) + except ValueError as e: + print(f"{e!r}") + print() + matrix_a = matrix_b From 7d28a5c9137ab1f299ec6f59478327679e457fc9 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 17 Oct 2023 10:42:20 +0200 Subject: [PATCH 72/75] Update matrix_multiplication_recursion.py --- matrix/matrix_multiplication_recursion.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/matrix/matrix_multiplication_recursion.py b/matrix/matrix_multiplication_recursion.py index 8b471a662eaf..875fd1972707 100644 --- a/matrix/matrix_multiplication_recursion.py +++ b/matrix/matrix_multiplication_recursion.py @@ -20,17 +20,17 @@ [7, 8], ] -matrix_5_to_9_wide = [ - [5, 6], - [7, 8, 9], -] - matrix_5_to_9_high = [ [5, 6], [7, 8], [9], ] +matrix_5_to_9_wide = [ + [5, 6], + [7, 8, 9], +] + matrix_count_up = [ [1, 2, 3, 4], [5, 6, 7, 8], @@ -47,14 +47,22 @@ matrices = ( matrix_1_to_4, matrix_5_to_8, - matrix_5_to_9_wide, matrix_5_to_9_high, + matrix_5_to_9_wide, matrix_count_up, matrix_unordered, ) def is_square(matrix: Matrix) -> bool: + """ + >>> is_square([]) + True + >>> is_square(matrix_1_to_4) + True + >>> is_square(matrix_5_to_8_high) + False + """ len_matrix = len(matrix) return all(len(row) == len_matrix for row in matrix) @@ -111,6 +119,8 @@ def multiply( :param i: Index used for iteration during multiplication. :param j: Index used for iteration during multiplication. :param k: Index used for iteration during multiplication. + >>> 0 > 1 # Doctests in inner functions are never run + True """ if i_loop >= len(matrix_a): return From b72b27fc54a5ed663c2cee50a5f7ea031d6ff412 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 17 Oct 2023 10:57:27 +0200 Subject: [PATCH 73/75] Update matrix_multiplication_recursion.py --- matrix/matrix_multiplication_recursion.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/matrix/matrix_multiplication_recursion.py b/matrix/matrix_multiplication_recursion.py index 875fd1972707..379e6587084a 100644 --- a/matrix/matrix_multiplication_recursion.py +++ b/matrix/matrix_multiplication_recursion.py @@ -60,13 +60,20 @@ def is_square(matrix: Matrix) -> bool: True >>> is_square(matrix_1_to_4) True - >>> is_square(matrix_5_to_8_high) + >>> is_square(matrix_5_to_9_high) False """ len_matrix = len(matrix) return all(len(row) == len_matrix for row in matrix) +def matrix_multiply(matrix_a: Matrix, matrix_b: Matrix) -> Matrix: + return [ + [sum(a * b for a, b in zip(row, col)) for col in zip(*matrix_b)] + for row in matrix_a + ] + + def matrix_multiply_recursive(matrix_a: Matrix, matrix_b: Matrix) -> Matrix: """ :param matrix_a: A square Matrix. @@ -151,8 +158,10 @@ def multiply( print(row) print("Result:") try: - for row in matrix_multiply_recursive(matrix_a, matrix_b): + result = matrix_multiply_recursive(matrix_a, matrix_b) + for row in result: print(row) + assert result == matrix_multiply(matrix_a, matrix_b) except ValueError as e: print(f"{e!r}") print() From 25131f6de81c293c33c70c581a1cf2364886be82 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 17 Oct 2023 11:18:02 +0200 Subject: [PATCH 74/75] Update matrix_multiplication_recursion.py --- matrix/matrix_multiplication_recursion.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/matrix/matrix_multiplication_recursion.py b/matrix/matrix_multiplication_recursion.py index 379e6587084a..e2e2f7e2faea 100644 --- a/matrix/matrix_multiplication_recursion.py +++ b/matrix/matrix_multiplication_recursion.py @@ -68,6 +68,10 @@ def is_square(matrix: Matrix) -> bool: def matrix_multiply(matrix_a: Matrix, matrix_b: Matrix) -> Matrix: + """ + >>> matrix_multiply(matrix_1_to_4, matrix_5_to_8) + [[19, 22], [43, 50]] + """ return [ [sum(a * b for a, b in zip(row, col)) for col in zip(*matrix_b)] for row in matrix_a @@ -166,3 +170,13 @@ def multiply( print(f"{e!r}") print() matrix_a = matrix_b + + print("Benchmark:") + from functools import partial + from timeit import timeit + + short_timeit = partial(timeit, globals=globals(), number=100_000) + for func in ("matrix_multiply", "matrix_multiply_recursive"): + print( + f"{func:>25}(): {short_timeit(f'{func}(matrix_count_up, matrix_unordered)')}" + ) From 278149bbd40134655ee731d939511a7d3a5c3ab1 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 17 Oct 2023 11:22:00 +0200 Subject: [PATCH 75/75] Update matrix_multiplication_recursion.py --- matrix/matrix_multiplication_recursion.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/matrix/matrix_multiplication_recursion.py b/matrix/matrix_multiplication_recursion.py index e2e2f7e2faea..287142480ce7 100644 --- a/matrix/matrix_multiplication_recursion.py +++ b/matrix/matrix_multiplication_recursion.py @@ -175,8 +175,6 @@ def multiply( from functools import partial from timeit import timeit - short_timeit = partial(timeit, globals=globals(), number=100_000) + mytimeit = partial(timeit, globals=globals(), number=100_000) for func in ("matrix_multiply", "matrix_multiply_recursive"): - print( - f"{func:>25}(): {short_timeit(f'{func}(matrix_count_up, matrix_unordered)')}" - ) + print(f"{func:>25}(): {mytimeit(f'{func}(matrix_count_up, matrix_unordered)')}")