-
Notifications
You must be signed in to change notification settings - Fork 212
Scripts to perform edge detection with Sobel filter #230
Scripts to perform edge detection with Sobel filter #230
Conversation
#This script can be used for edge-detection without the use of any inbuilt openCV libraries | ||
#Here the sobel filter is applied after blurring the image. | ||
|
||
kernelblur = np.array([1/16,1/8,1/16,1/8,1/4,1/8,1/16,1/8,1/16]).reshape(3,3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put space after comma
#Here the sobel filter is applied after blurring the image. | ||
|
||
kernelblur = np.array([1/16,1/8,1/16,1/8,1/4,1/8,1/16,1/8,1/16]).reshape(3,3) | ||
kernelsobelX = np.array([-1,-2,-1,0,0,0,1,2,1]).reshape(3,3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after comma
|
||
def sobel(img): | ||
height = img.shape[0] | ||
width= img.shape[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insert space before comma
resultant = [] | ||
for i in range(height-1): | ||
for j in range(width-1): | ||
in_x = pow(convoluted_X[i,j] ,2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give space after comma and remove space before comma
#The resultant will be sqrt(pow(gx**2) + pow(gy**2)) | ||
resultant = [] | ||
for i in range(height-1): | ||
for j in range(width-1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insert space around -
resultant = np.array(resultant).reshape(height-1, width-1) | ||
cv2_imshow(resultant) | ||
|
||
if __name__ == "__main__": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space around ==
Okay will make the changes immediately
…On Sat, Sep 5, 2020, 9:06 PM Disha Sinha ***@***.***> wrote:
***@***.**** approved this pull request.
------------------------------
In Image-Processing/Sobel-edge-detection/sobel-edge-detect.py
<#230 (comment)>
:
> @@ -0,0 +1,76 @@
+import numpy as np
+import cv2
+from google.colab.patches import cv2_imshow
+from math import sqrt, atan
+
+#This script can be used for edge-detection without the use of any inbuilt openCV libraries
+#Here the sobel filter is applied after blurring the image.
+
+kernelblur = np.array([1/16,1/8,1/16,1/8,1/4,1/8,1/16,1/8,1/16]).reshape(3,3)
put space after comma
------------------------------
In Image-Processing/Sobel-edge-detection/sobel-edge-detect.py
<#230 (comment)>
:
> @@ -0,0 +1,76 @@
+import numpy as np
+import cv2
+from google.colab.patches import cv2_imshow
+from math import sqrt, atan
+
+#This script can be used for edge-detection without the use of any inbuilt openCV libraries
+#Here the sobel filter is applied after blurring the image.
+
+kernelblur = np.array([1/16,1/8,1/16,1/8,1/4,1/8,1/16,1/8,1/16]).reshape(3,3)
+kernelsobelX = np.array([-1,-2,-1,0,0,0,1,2,1]).reshape(3,3)
Space after comma
------------------------------
In Image-Processing/Sobel-edge-detection/sobel-edge-detect.py
<#230 (comment)>
:
> +
+ #Convolution is applied here
+ apply_filter = []
+ for i in range(1, height):
+ for j in range(1, width):
+ temp = pixels[i:i+3, j:j+3]
+ product = np.multiply(temp, kernel)
+ apply_filter.append(sum(sum(product)))
+
+ #The pixels are converted back to the image
+ apply_filter = np.array(apply_filter).reshape(height-1, width-1)
+ return(apply_filter)
+
+def sobel(img):
+ height = img.shape[0]
+ width= img.shape[1]
insert space before comma
------------------------------
In Image-Processing/Sobel-edge-detection/sobel-edge-detect.py
<#230 (comment)>
:
> + #The image is blurred, so the noise is removed
+ blur = convolute(img, kernelblur, height, width)
+
+ height = height - 1
+ width = width - 1
+
+ #The sobel filter is applied in the X and Y direction separately
+ convoluted_Y = convolute(blur, kernelsobelX, height, width)
+ convoluted_X = convolute(blur, kernelsobelY, height, width)
+
+ #Every pixel in convoluted_X can be called gx, in convoluted_Y can be called gy,
+ #The resultant will be sqrt(pow(gx**2) + pow(gy**2))
+ resultant = []
+ for i in range(height-1):
+ for j in range(width-1):
+ in_x = pow(convoluted_X[i,j] ,2)
Give space after comma and remove space before comma
------------------------------
In Image-Processing/Sobel-edge-detection/sobel-edge-detect.py
<#230 (comment)>
:
> +
+ #The image is blurred, so the noise is removed
+ blur = convolute(img, kernelblur, height, width)
+
+ height = height - 1
+ width = width - 1
+
+ #The sobel filter is applied in the X and Y direction separately
+ convoluted_Y = convolute(blur, kernelsobelX, height, width)
+ convoluted_X = convolute(blur, kernelsobelY, height, width)
+
+ #Every pixel in convoluted_X can be called gx, in convoluted_Y can be called gy,
+ #The resultant will be sqrt(pow(gx**2) + pow(gy**2))
+ resultant = []
+ for i in range(height-1):
+ for j in range(width-1):
insert space around -
------------------------------
In Image-Processing/Sobel-edge-detection/sobel-edge-detect.py
<#230 (comment)>
:
> + convoluted_Y = convolute(blur, kernelsobelX, height, width)
+ convoluted_X = convolute(blur, kernelsobelY, height, width)
+
+ #Every pixel in convoluted_X can be called gx, in convoluted_Y can be called gy,
+ #The resultant will be sqrt(pow(gx**2) + pow(gy**2))
+ resultant = []
+ for i in range(height-1):
+ for j in range(width-1):
+ in_x = pow(convoluted_X[i,j] ,2)
+ in_y = pow(convoluted_Y[i,j] , 2)
+ gradient = sqrt(in_x + in_y)
+ reusultant.append(grad)
+ resultant = np.array(resultant).reshape(height-1, width-1)
+ cv2_imshow(resultant)
+
+if __name__ == "__main__":
Space around ==
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#230 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AM3BEYLXDJIW6P3ZB3ZPFC3SEJLHPANCNFSM4QPPWHSA>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the changes stated below and you are good to go
Yep, all done |
This script performs edge detection using the Sobel filter, (no inbuilt functions from the openCV library are used)
Issue relates to #93