Instantly share code, notes, and snippets.

Embed
What would you like to do?
pngのアルファチャンネルを2値化
# -*- 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