3채널(RGB)영상을 Grayscale(단일 채널)영상으로 불러오기.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # Image gray scaling import cv2 #Load input image image = cv2.imread('./images/input.jpg') cv2.imshow('Original', image) cv2.waitKey() # We used cvtColor, to convert to grayscale gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.imshow('Grayscale', gray_image) cv2.waitKey() cv2.destroyAllWindows() | cs |
이건 입력된 영상
이건 grayscale로 변환된 영상.
입력된 영상(RGB)과 변환된 영상(Grayscale)에 대한 정보를 출력해보자.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #Let's take a closer look at color spaces # Import module and image import cv2 import numpy as np image = cv2.imread('./images/input.jpg') # Look at the individual color levels for the first pixel (0, 0) # BGR values for the first 0, 0 pixel B, G, R = image[10, 50] print(B, G, R) print(image.shape) gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) print(gray_img[10, 50]) print(gray_img.shape) | cs |
해당 파이썬 코드를 실행하면 아래와 같은 결과 출력.
# Original 영상 정보
13 19 32
(830, 1245, 3)
# Grayscale 영상 정보
22
(830, 1245)
반응형
'OpenCV_with_Python' 카테고리의 다른 글
OpenCV Python3 tutorial_2 (0) | 2018.04.06 |
---|---|
OpenCV Python3 tutorial_1 (0) | 2018.04.06 |