Prewittフィルター
Prewittフィルターは、次のフィルターで表される。
x方向
$$F_x = \begin{bmatrix} -1 & 0 & 1 \\ -1 & 0 & 1 \\ -1 & 0 & 1 \end{bmatrix}$$
y方向
$$F_y = \begin{bmatrix} -1 & -1 & -1 \\ 0 & 0 & 0 \\ 1 & 1 & 1 \end{bmatrix}$$
Python+OpenCV
import cv2
import numpy as np
gray = cv2.imread('haruna_kankore.png', 0)
#水平方向微分
kernel_1_x = np.array([[-1, 0, 1],
[-1, 0, 1],
[-1, 0, 1]])
x_1 = cv2.filter2D(gray, -1, kernel_1_x)
cv2.imwrite('prewitt_x.png', x_1)
#垂直方向微分
kernel_1_y = np.array([[-1, -1, -1],
[0, 0, 0],
[1, 1, 1]])
y_1 = cv2.filter2D(gray, -1, kernel_1_y)
cv2.imwrite('prewitt_y.png', y_1)
出力結果
元画像
prewitt-縦方向エッジ
Sobel-横方向エッジ
