Scharrフィルタ

V2.4.11, V3.0.0
In [9]:
# -*- 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)

#ソーベルフィルタリング
scharr_x  = cv2.Scharr(gauss,cv2.CV_64F,1,0)
scharr_y  = cv2.Scharr(gauss,cv2.CV_64F,0,1)

#画像表示
plt.figure(figsize=(8,12))
plt.subplot(311)
plt.imshow(gray,cmap = 'gray')
plt.subplot(312)
plt.imshow(scharr_x,cmap = 'gray')
plt.subplot(313)
plt.imshow(scharr_y,cmap = 'gray')
Out[9]:
<matplotlib.image.AxesImage at 0xedbd590>
inserted by FC2 system