본문 바로가기
프로그래밍 언어/Python

파이썬 cv2와 matplotlib 모듈을 이용한 이미지 읽고 표시하기

by pagehit 2021. 4. 21.
반응형

 

test.py

# cv2 module's imread to read an image as an ndarray.
# cv2 module's imwrite to write an image.
import cv2
import matplotlib.pyplot as plt 

img = cv2.imread('image1.png') 
# Converting img to grayscale (if needed).
img_grayscale = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 

# We process img_grayscale and obtain img_processed.
# The function image_processing can perform any image
# processing or computer vision operation
img_processed = image_processing(img_grayscale) 

# cv2.imwrite will take an ndarray and store it.
cv2.write('file_name.png', img_processed) 
# We import matplotlib.pyplot to display an image in grayscale.
plt.imshow(img_processed, 'gray')plt.show()

 

반응형

댓글