소스 뷰어
import cv2
import numpy as np
import matplotlib.pyplot as plt

# 이미지 읽기 (OpenCV는 기본적으로 BGR로 이미지를 불러옵니다)
img_bgr = cv2.imread('example.jpg')

# NumPy를 사용하여 BGR을 RGB로 변경
img_rgb = img_bgr[:, :, ::-1]  # 채널 순서를 역으로 뒤집음 (BGR -> RGB)
#img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)

# 비교를 위해 원본과 RGB 이미지를 나란히 출력
plt.figure(figsize=(10, 5))  # 출력 크기 설정

# BGR 원본 이미지 출력
plt.subplot(1, 2, 1)  # 1행 2열의 첫 번째 위치에 이미지 표시
plt.imshow(img_bgr)  # BGR 이미지를 RGB로 변환하여 출력
plt.title('BGR Channel Image')
plt.axis('off')

# RGB로 변경한 이미지 출력
plt.subplot(1, 2, 2)  # 1행 2열의 두 번째 위치에 이미지 표시
plt.imshow(img_rgb)  # 이미 RGB로 변환된 이미지를 그대로 출력
plt.title('RGB Channel Image')
plt.axis('off')

# 화면에 이미지 표시
plt.tight_layout()
plt.show()
No description has been provided for this image