이미지 처리 (feat. Pillow/PIL)

괴도소녀·2021년 7월 7일
1

python

목록 보기
9/11

python의 이미지 처리 대표적인 library로는

  • matplotlib
  • PIL(Pillow)

등이 있다.

여기선 PIL(Pillow)를 사용할 것이다.
우선 Pillow가 설치되어있는지 확인하자.

pip list | grep Pillow

설치가 되어있지 않다면 설치하는 작업을 해주자

pip install Pillow

open

이제 Pillow package를 import 해주고,
이미지를 불러와보자.

from PIL import Image

img = Image.open("/data/toronto.jpg")
img

resize

불러온 이미지를 resize메소드를 통해 크기를 변경할 수 있다.

resize_img = img.resize((70,100))
resize_img

crop

이미지를 crop할 수도 있다.

cropped_img = img.crop((20, 20, 100, 100))
cropped_img

save

이미지를 원하는 경로에 저장할 수도 있다.

cropped_img.save("./data/cropped_toronto.jpg")

가장 간단한 메소드들만 살펴봤다.
조금더 자세하게 Pillow(PIL)에 대해 알고싶다면,
밑에 참고사이트에 들어가서 공부하길 바란다.


참고 사이트

Pillow tutorial
tensorflow

0개의 댓글