Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

OpenCV를 사용하여 이미지 업샘플링

<시간/>

이 프로그램에서는 이미지를 업샘플링합니다. 업 샘플링은 이미지의 2D 표현을 유지하면서 공간 해상도를 높이는 것입니다. 일반적으로 이미지의 작은 영역을 확대하는 데 사용됩니다. 이 작업을 완료하기 위해 openCV 라이브러리의 pyrup() 함수를 사용할 것입니다.

원본 이미지

OpenCV를 사용하여 이미지 업샘플링

알고리즘

Step 1: Read the image.
Step 2: Pass the image as a parameter to the pyrup() function.
Step 3: Display the output.

예시 코드

import cv2

image = cv2.imread('testimage.jpg')
print("Size of image before pyrUp: ", image.shape)

image = cv2.pyrUp(image)
print("Size of image after pyrUp: ", image.shape)
cv2.imshow('UpSample', image)

출력

Size of image before pyrUp: (350, 700, 3)
Size of image after pyrUp: (700, 1400, 3)

OpenCV를 사용하여 이미지 업샘플링

설명

pyrUp 함수를 사용하기 전과 후에 이미지의 크기를 관찰하면 크기가 증가한 것을 볼 수 있습니다. 즉, 이미지를 업샘플링한 것입니다.