You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

25 lines
747 B

# 実験課題5
# 3.5 エッジ処理
import cv2
image_path = 'sample.jpg'
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
if img is not None:
# Sobel
sobel_x = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=3)
sobel_y = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=3)
sobel_x_abs = cv2.convertScaleAbs(sobel_x)
sobel_y_abs = cv2.convertScaleAbs(sobel_y)
sobel_combined = cv2.addWeighted(sobel_x_abs, 0.5, sobel_y_abs, 0.5, 0)
cv2.imwrite('3_5_sobel.jpg', sobel_combined)
# Laplacian
laplacian = cv2.Laplacian(img, cv2.CV_64F)
laplacian_abs = cv2.convertScaleAbs(laplacian)
cv2.imwrite('3_5_laplacian.jpg', laplacian_abs)
# Canny
canny = cv2.Canny(img, 50, 150)
cv2.imwrite('3_5_canny.jpg', canny)