Learn practical skills, build real-world projects, and advance your career

assignment3

Use the "Run" button to execute the code.

import cv2
image = cv2.imread('sunset.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('Original image',image)
cv2.imshow('Gray image', gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Opening the image
# (R prefixed to string in order to deal with '\' in paths)
image = Image.open(r"sunset.jpg")

# Blurring image by sending the ImageFilter.
# GaussianBlur predefined kernel argument
image = image.filter(ImageFilter.GaussianBlur)

# Displaying the image
image.show()
import cv2
import numpy as np
import matplotlib.pyplot as plot
image = cv2.imread("sunset.jpg",0)
# Below code convert image gradient in both x and y direction
lap = cv2.Laplacian(image,cv2.CV_64F,ksize=3) 
lap = np.uint8(np.absolute(lap))
# Below code convert image gradient in x direction
sobelx= cv2.Sobel(image,0, dx=1,dy=0)
sobelx= np.uint8(np.absolute(sobelx))
# Below code convert image gradient in y direction
sobely= cv2.Sobel(image,0, dx=0,dy=1)
sobely = np.uint8(np.absolute(sobely))
results = [lap,sobelx,sobely]
images =["Gradient Image","Gradient In X direction","Gradient In Y direction"]
for i in range(3):
    plot.title(results[i])
    plot.subplot(1,3,i+1)
    plot.imshow(results[i],"plasma")
    plot.xticks([])
    plot.yticks([])
plot.show()
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('sunset.jpg',0)
laplacian = cv.Laplacian(img,cv.CV_64F)
sobelx = cv.Sobel(img,cv.CV_64F,1,0,ksize=5)
sobely = cv.Sobel(img,cv.CV_64F,0,1,ksize=5)
plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray')
plt.title('Original'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray')
plt.title('Laplacian'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray')
plt.title('Sobel X'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray')
plt.title('Sobel Y'), plt.xticks([]), plt.yticks([])
plt.show()