All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Objective: Apply Prewitt and Laplacian filter on the image Libraries used: Opencv Open Source computer vision library. cross-platform supported. can perform through c, c++, and python. numpy Mathematical library to work in the domain of Linear algebra, Fourier transform, and matrices. Image Filtering…
Epuri Yoga Narasimha
updated on 09 Jul 2022
Objective: Apply Prewitt and Laplacian filter on the image
Libraries used:
Image Filtering in Image Processing is an important task, computing the local n at each position
Using filtering, we can enhance the image like Denoise, increase contrast and extract information like edges, lines ...
Detection of the edges and their orientations.
Theory :
Discrete First order Forward Difference along x and y:
Gx≈f(x+1,y)-f(x,y)Gx≈f(x+1,y)−f(x,y)
Gy≈f(x,y+1)-f(x,y)Gy≈f(x,y+1)−f(x,y)
Derivative mask of prewitt (1st order ) for 2D image:
[-101-101-101]⎡⎢⎣−101−101−101⎤⎥⎦
[-1-1-1000111]
Derivative mak of Laplacian (2nd order):
[0101-41010] (or) [0-10-14-10-10]
Second-order approximation of Taylor Series :
d2dx2f(x,y)=ddxdfdx=ddx[f(x+1,y)-f(x,y)]=ddxf(x+1,y)-ddxf(x,y)
=[f(x+1,y)-f(x,y)]-[f(x,y)-f(x-1,y)]
=f(x+1,y)-2f(x,y)+f(x-1,y)=[1-21]
d2dy2f(x,y)=ddydfdy=ddy[f(x,y+1)-f(x,y)]=ddyf(x,y+1)-ddyf(x,y)
=[f(x,y+1)-f(x,y)]-[f(x,y)-f(x,y-1)]
=f(x,y+1)-2f(x,y)+f(x,y-1)=[1,-2,1]
Derivative mask of Laplacian captures both horizontal and vertical second-order derivative information.
An Edge Detector is called Optimal, if performs Good Detection and Good Localization.
Note :
In ML and Image Processing, a convolution just defines the sliding of kernel over a feature map or image, flipping or no flipping normally not taken very seriously.
Thus in ML or image Processing someone moght talk of convolution and in actual sense it its cross-correlation (or) correlation upon close inspection.
In CNN, we call actully it a convolution, but it is actually cross-correlation.
Fig : Filtering operation.
Functions Used:
Some Function Explanations :
Possible values of borderType are :
Code :
import cv2
import numpy as np
# inputs
image = cv2.imread(r"C:UsersnarasOneDriveDesktopAytonomous Vehiclesskill lyncChallenge_2.png", 1)
image = cv2.resize(image, (700, 500))
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# function definations
def perwitt_filter(image):
vert_filter = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]])
horz_filter = np.array([[-1, -1, -1], [0, 0, 0], [1, 1, 1]])
vert_filtered = cv2.filter2D(image, -1, vert_filter)
horz_filtered = cv2.filter2D(image, -1, horz_filter)
abs_grad_x = cv2.convertScaleAbs(vert_filtered)
abs_grad_y = cv2.convertScaleAbs(horz_filtered)
final_image = cv2.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0)
return final_image
def laplacian_filter(image):
filter1 = np.array([[0, 1, 0], [1, -4, 1], [0, 1, 0]])
filtered = cv2.filter2D(image, -1, filter1)
final_image = cv2.convertScaleAbs(filtered)
return final_image
def LoG(image):
gauss_image = cv2.GaussianBlur(image, (5, 5), 3)
return laplacian_filter(gauss_image)
# function calls
perwitt_image = perwitt_filter(gray_image)
laplacian_image = laplacian_filter(gray_image)
log_image = laplacian_filter(gray_image)
# Display the images
cv2.imshow("perwitt filtered image", perwitt_image)
cv2.imshow("laplacian filtered image", laplacian_image)
cv2.imshow("LOG filtered image", log_image)
cv2.imshow("laplacian and LOG", np.hstack((laplacian_image, log_image)))
cv2.waitKey(0)
cv2.destroyAllWindows()
Results :
From Figure 1 & 3, Prewitt gives thicker edges due to very sensitive to the noise.
By appling the gaussian smoothing filter, the noise get dispersed more, using prewitt filter, got better edges.
In First Order Derivative masks, we consider threshold so higher chances for thicker edges.
But in Second Order Derivative masks, we say it is edges if the value is zero.
Laplacian filter provides good results than prewitt.
Applying LoG (Laplacian of Gaussian) filter, got more enhanced edges.
Conclusion :
1. Laplacian provides good defined edges than prewitt, even noise present.
2. After appying gaussian both providing good defined edges.
3. Prewitt is more simpler in implementation than Laplacian operation.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 4
Objective 1. Detect lanes using Hough Transform Method. Steps in lane Detection 1. Detect Edges using Canny Edge Detection Method. 2. Capture the Region of Interest in Image. 3. Detect lines using Hough Transform. 4. Calculate the actual left and right lanes from all lines. 6. Find the coordinates of the lines. 7. Display…
21 Feb 2023 05:22 AM IST
Lane Detection using Hough Transform
Objective 1. Detect lanes using Hough Transform Method. Steps in lane Detection 1. Detect Edges using Canny Edge Detection Method. 2. Capture the Region of Interest in Image. 3. Detect lines using Hough Transform. 4. Calculate the actual left and right lanes from all lines. 6. Find the coordinates of the lines. 7. Display…
21 Feb 2023 05:20 AM IST
Edge Detection and Hough Transform
Objective: Detecting Edges using Canny Edge Detector. Understand and display the outputs of all steps in the canny Edge Detection process. Effect on the output on changing the parameters of the Non-Maximum Suppression. Understand Hough Transform and Lane Detection using Hough Transform. Steps Follow in the Discussion:…
28 Dec 2022 09:58 PM IST
week 2 : Image Filtering
Objective: Apply Prewitt and Laplacian filter on the image Libraries used: Opencv Open Source computer vision library. cross-platform supported. can perform through c, c++, and python. numpy Mathematical library to work in the domain of Linear algebra, Fourier transform, and matrices. Image Filtering…
09 Jul 2022 06:36 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.