소스 뷰어
import cv2, numpy as np, matplotlib.pyplot as plt
# example.jpg 이미지 불러오기 (흑백으로 변환)
input_image = cv2.imread('example.jpg', cv2.IMREAD_GRAYSCALE)
# 커널 정의(엣지 검출)
kernel = np.array([
[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]
])
# 컨볼루션 수행
convoluted_image = cv2.filter2D(input_image, -1, kernel)
# matplotlib을 이용한 출력
plt.figure(figsize=(10, 5))
# 원본 이미지 출력
plt.subplot(1, 2, 1)
plt.imshow(input_image, cmap='gray')
plt.title('Original Image')
plt.axis('off')
# 컨볼루션된 이미지 출력
plt.subplot(1, 2, 2)
plt.imshow(convoluted_image, cmap='gray')
plt.title('OpenCV Convoluted Image (Sharpening)')
plt.axis('off')
# 그래프 출력
plt.tight_layout()
plt.show()