Created
June 25, 2018 03:45
-
-
Save dj0/4f962bb4cea8ea9ecb71ce9dc60e174c to your computer and use it in GitHub Desktop.
pngのアルファチャンネルを2値化
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
from PIL import Image | |
# 修正したい画像の読み込み | |
img = Image.open('元画像.png') | |
width = img.size[0] | |
height = img.size[1] | |
for x in range(width): | |
for y in range(height): | |
pixel = img.getpixel((x, y)) | |
# アルファ値255以外を全部0にする | |
if(pixel[3] < 255): | |
img.putpixel((x, y), (0, 0, 0, 0)) | |
# 修正後画像を保存 | |
img.save('修正後画像.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment