ソーベルフィルタ

V2.4.11, V3.0.0
In [3]:
# -*- coding: utf-8 -*-
import cv2

#Ipythonで表示用の設定
import matplotlib.pyplot as plt
%matplotlib inline

#画像読込
in_img = cv2.imread("lena.jpg")

#GRAY画像に変換
gray  = cv2.cvtColor(in_img, cv2.COLOR_BGR2GRAY)

#ガウスフィルタリング
gauss = cv2.GaussianBlur(gray,(3,3),0)

#ソーベルフィルタリング
sobelx  = cv2.Sobel(gauss,cv2.CV_64F,1,0,ksize=5)
sobely  = cv2.Sobel(gauss,cv2.CV_64F,0,1,ksize=5)
sobelxy = cv2.Sobel(gauss,cv2.CV_64F,1,1,ksize=5)

#画像表示
plt.figure(figsize=(8,8))
plt.subplot(221)
plt.imshow(gray,cmap = 'gray')
plt.subplot(222)
plt.imshow(sobelx,cmap = 'gray')
plt.subplot(223)
plt.imshow(sobely,cmap = 'gray')
plt.subplot(224)
plt.imshow(sobelxy,cmap = 'gray')
Out[3]:
<matplotlib.image.AxesImage at 0xa0be3f0>
inserted by FC2 system