logo

리매핑

리매핑 Remapping

  • 원래 이미지의 점들을 다른 좌표로 옮겨주는 것
src = cv.imread('basketball.webp')
height, width = src.shape[:2]  # 이미지의 높이, 너비
mapy, mapx = np.indices((height, width),dtype=np.float32)  # 원래의 좌표
mapx = width - mapx - 1  # 좌우 대칭
mapy = height - mapy - 1  # 상하 대칭
dst = cv.remap(src, mapx, mapy, cv.INTER_LINEAR)  # 점들의 좌표를 바꿈
# 보간 방법은 앞 장을 참고

극좌표계로 변환

mapy, mapx = np.indices((height, width), dtype=np.float32)  # 원래의 좌표
# -1~1로 정규화된 좌표로 변경
center_x, center_y = width // 2, height // 2  # 중심 좌표 설정
norm_mapx = (mapx - center_x) / (width // 2)
norm_mapy = (mapy - center_y) / (height // 2)
r, theta = cv.cartToPolar(norm_mapx, norm_mapy) # 극좌표계로 변환

극좌표계로 변환 이미지 1

볼록 오목 변환

exp = 1.5  # 볼록, 오목 지수 (오목 < 1 < 볼록)
scale = 1 # 적용 영역 반지름 (0 ~ 1)
r[r < scale] = r[r < scale] ** exp   # 왜곡 영역만 중심확대/축소 지수 적용

norm_mapx, norm_mapy = cv.polarToCart(r, theta)  # 직교좌표계로 변환
# 정규화된 좌표를 이미지 좌표로 변경
mapx = norm_mapx * (width // 2) + center_x
mapy = norm_mapy * (height // 2) + center_y
dst = cv.remap(src, mapx, mapy, cv.INTER_LINEAR)
Previous
ArUco 마커