본문 바로가기
OpenCV

OpenCV - Image Warpping

by winston1214 2020. 10. 11.
반응형

인공위성에서 받은 이미지 객체나다른 우주계획의 일원으로부터 보내져 온 일그러진 영상을 올바르게 만드는 데 사용하는 것이 바로 Image Warpping 이다. 고도가 너무 높아 이미지가 일그러지는 경우가 있기 때문에 이를 올바르게 만들기 위한 기술이다.

Image Warpping은 sin 함수와 cos 함수를 통해 일그러진 것을 정상적인 이미지로 돌린다.

 

- Vertical Wave

import cv2
import numpy as np
import math
img = cv2.imread('img/input.jpg',cv2.IMREAD_GRAYSCALE)
rows,cols = img.shape

# vertical wave
img_output = np.zeros(img.shape,dtype = img.dtype)
for i in range(rows):
    for j in range(cols):
        offset_x = int(25*math.sin(2*3.14*i/180))
        offset_y = 0
        if j+offset_x < rows:
            img_output[i,j] = img[i,(j+offset_x)%cols]
        else:
            img_output[i,j] = 0
plt_show(img_output)

이미지의 x값에 sin 처리를 하고 이미지의 행렬값을 조절하였다. 그 결과 한 쪽 세로 부분이 sin 함수 그래프처럼 바뀐 것을 볼 수 있다.

 

- Horizontal Wave

# Horizontal wave
img = cv2.imread('img/input.jpg',cv2.IMREAD_GRAYSCALE)
rows,cols = img.shape

img_output = np.zeros(img.shape,dtype = img.dtype)
for i in range(rows):
    for j in range(cols):
        offset_x = 0
        offset_y = int(16.0*math.sin(2*3.14*i/150))
        if j+offset_y < rows:
            img_output[i,j] = img[(i+offset_y)%rows,j]
        else:
            img_output[i,j] = 0
plt_show(img_output)

- Both Vertical and Horizontal Wave

# Both Horizontal and vertical
img = cv2.imread('img/input.jpg',cv2.IMREAD_GRAYSCALE)
rows,cols = img.shape
img_output = np.zeros(img.shape,dtype = img.dtype)
for i in range(rows):
    for j in range(cols):
        offset_x = int(20.0*math.sin(2*3.14*i/150))
        offset_y = int(20.0*math.cos(2*3.14*j/150))
        if i+offset_y < rows and j+offset_x <cols:
            img_output[i,j] = img[(i+offset_y)%rows,(j+offset_x)%cols]
        else:
            img_output[i,j] = 0
plt_show(img_output)

Both

- Concave Effect

# Concave effect
img = cv2.imread('img/input.jpg',cv2.IMREAD_GRAYSCALE)
rows,cols = img.shape
img_output = np.zeros(img.shape,dtype = img.dtype)
for i in range(rows):
    for j in range(cols):
        offset_x = int(128.0*math.sin(2*3.14*i/(2*cols)))
        offset_y = 0
        
        if j+offset_x < cols:
            img_output[i,j] = img[i,(j+offset_x)%cols]
        else:
            img_output[i,j] = 0
plt_show(img_output)

 

반응형

댓글