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

# 이미지 로드
image_rgb = plt.imread('lena.jpg')

# 평행 이동 거리 정의
t_x, t_y = 50, 30  # x축으로 50픽셀, y축으로 30픽셀 이동

# 원본 이미지 크기
height, width, channels = image_rgb.shape

# 이동된 이미지를 저장할 빈 배열 생성
translated_image = np.zeros_like(image_rgb)

# 슬라이싱을 이용하여 유효한 영역만 이동
translated_image[t_y: , t_x: ] = image_rgb[ : height - t_y, : width - t_x]

# 결과를 Matplotlib으로 출력
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 (Numpy)", fontsize=fs)
plt.axis("off")

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