cv2.resize(): 크기 조절 함수

2023. 3. 28. 23:02OpenCV

cv2.resize(src, dstSize, fx, fy, interpolation): 크기 변환

  • src: 입력 이미지
  • dstSize: 절대 크기
  • fx, fy: 상대 크기
  • interpolation: 보간법

예시

image = cv2.imread("fruits.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

plt.figure(figsize=(20, 20))

plt.subplot(2, 2, 1)
plt.title("Original")
plt.imshow(image)

# 원래 크기의 3/4로 resize
image_scaled = cv2.resize(image, None, fx=0.75, fy=0.75)

plt.subplot(2, 2, 2)
plt.title("Scaling - Linear Interpolation")
plt.imshow(image_scaled)

# 원래 크기의 2배로 resize
img_scaled = cv2.resize(image, None, fx=2, fy=2, interpolation = cv2.INTER_CUBIC)

plt.subplot(2, 2, 3)
plt.title("Scaling - Cubic Interpolation")
plt.imshow(img_scaled)

# 정확한 치수를 설정하여 크기를 조정
img_scaled = cv2.resize(image, (900, 400), interpolation = cv2.INTER_AREA)

plt.subplot(2, 2, 4)
plt.title("Scaling - Skewed Size")
plt.imshow(img_scaled)