Skip to content

Commit

Permalink
Merge pull request #712 from smw-1211/Gradient-Image
Browse files Browse the repository at this point in the history
New project - Get the gradient form of an image
  • Loading branch information
Mrinank-Bhowmick authored Mar 5, 2024
2 parents 9a7f96a + e288ce0 commit 2581535
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions projects/Gradient-Image/gradient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#A pencil shaded image representation with better display of edges
import cv2 as cv
import numpy as np
#Code to read images

img = cv.imread('Photos/image.jpg') #change this path with the path of image passed as an input
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

## Just to check the images obtained in grayscale mode and compare with the original image.
#cv.imshow('image',img)
#cv.imshow('Gray Image', gray)

#Laplacian
lap = cv.Laplacian(gray, cv.CV_64F)
lap = np.uint8(np.absolute(lap))

cv.imshow('Laplacian Image',lap)

#Sobel Gradient magnitude
sobelx = cv.Sobel(gray, cv.CV_64F, 1, 0)
sobely = cv.Sobel(gray, cv.CV_64F, 0, 1)
combined_sobel = cv.bitwise_or(sobelx, sobely)
#cv.imshow('Sobel X',sobelx)
#cv.imshow('Sobel Y',sobely)
cv.imshow('Sobel Final',combined_sobel)

canny = cv.Canny(gray, 150, 175)
cv.imshow('Canny',canny)

cv.waitKey(0) #keyboard binding function that waits for a specific delay(0 here means to wait for infinite amount of time.)

0 comments on commit 2581535

Please sign in to comment.