이미지 처리
python 간단하게 배경 색 변경하기
wangkisa
2021. 5. 26. 15:03
참고 포스트: https://towardsdatascience.com/change-the-background-of-any-image-with-5-lines-of-code-23a0ef10ce9a
Change the Background of Any Image with 5 Lines of Code
Image segmentation has a lot of amazing applications that solve different computer vision problems. PixelLib is a library created to ensure easy integration of image segmentation in real life…
towardsdatascience.com
해당 원본 글을 참고해서 진행하였으며,
필요한 라이브러리 설치는 다음과 같습니다.
Install Tensorflow with:(PixelLib supports tensorflow 2.0 and above)
- pip3 install tensorflow
- pip3 install pixellib
- pip3 install pixellib — upgrade
여기서 'deeplabv3_xception_tf_dim_ordering_tf_kernels.h5' 파일을 모델로 불러와 사용하는데
해당 파일은 here 여기서 받아서 다운로드 합니다.
만약, 배경을 흰색(255, 255, 255)로 변경하고 싶은 경우에는 다음과 같이 하면
결과 이미지 경로에 파일이 저장하는 것으로 확인하였습니다.
import pixellib
from pixellib.tune_bg import alter_bg
change_bg = alter_bg()
change_bg.load_pascalvoc_model("deeplabv3_xception_tf_dim_ordering_tf_kernels.h5")
change_bg.color_bg({원본 이미지 경로}, colors=(255, 255, 255), output_image_name={결과 이미지 경로})
원본:
결과: