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

# lena.jpg 이미지를 로드합니다.
# OpenCV는 이미지를 BGR 형식으로 로드하므로 RGB로 변환해야 plt에서 제대로 보입니다.
image = cv2.imread('lena.jpg')
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

(h, w) = image_rgb.shape[:2]
# 변환 행렬 정의 (t_x=50, t_y=30)
t_x, t_y = 70, 50
translation_matrix = np.array([[1, 0, t_x], [0, 1, t_y]], dtype=np.float32)

# 평행 이동 적용
translated_image = cv2.warpAffine(image_rgb, translation_matrix, (w,h))

# 원본 이미지와 평행 이동된 이미지를 출력
plt.figure(figsize=(10, 5))
fs = fontsize= 20 # 폰트 사이즈
# 원본 이미지
plt.subplot(1, 2, 1)
plt.imshow(image_rgb)
plt.title("Original Image", fontsize=fs)
plt.axis("off")

# 평행 이동된 이미지
plt.subplot(1, 2, 2)
plt.imshow(translated_image)
plt.title("Translated Image (OpenCV)", fontsize=fs)
plt.axis("off")

plt.tight_layout()
plt.show()
No description has been provided for this image