python
from google.colab import files
from google.colab import drive
drive.mount('/content/drive')
python
import cv2 #opencv
import matplotlib.pyplot as plt
%matplotlib inline
python
img = plt.imread("/content/drive/My Drive/Colab Notebooks/img/Lenna.bmp")
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
python
#Original image
plt.subplot(2,3,1)
plt.axis('off')
plt.title("Original", fontsize=10)
plt.imshow(gray)
#Laplacian
plt.subplot(2,3,4)
plt.axis('off')
plt.title("Laplacian", fontsize=10)
dst = cv2.Laplacian(gray,ddepth = -1)
plt.imshow(dst)
#Sobel
plt.subplot(2,3,5)
plt.axis('off')
plt.title("Sobel", fontsize=10)
dst = cv2.Sobel(gray,ddepth = -1,dx = 0,dy = 1) #dx,Determine the number of differential characters with dy.
plt.imshow(dst)
#Sobel
plt.subplot(2,3,6)
plt.axis('off')
plt.title("Canny", fontsize=10)
dst = cv2.Canny(gray,threshold1 = 64,threshold2 = 128)
#The smaller thresholds 1 and 2 are used for joining edges.
#Larger ones are used for initial detection of stronger edges.
plt.imshow(dst)
plt.show()
Recommended Posts