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

파이썬 PIL과 matplotlib을 이용해 이미지를 읽고 쓰기

by pagehit 2021. 4. 21.
반응형

 

test.py

# PIL module to read and save an image.
from PIL import Image
import matplotlib.pyplot as plt 

# Opening image and converting it into grayscale.
img = Image.open('image2.png').convert('L')

# convert PIL Image object to numpy array
img = np.array(img) 
# We process img_grayscale and obtain img_processed
img_processed = image_processing(img) 

# Converting ndarray to a PIL Image.
img_out = Image.fromarray(img_processed) 

# Save the image to a file.
img_out.save('file_name.png') 

# Display the image in grayscale
plt.imshow(img_processed, 'gray')plt.show()

 

반응형

댓글