Skip to content

Instantly share code, notes, and snippets.

@dj0
Created June 25, 2018 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj0/4f962bb4cea8ea9ecb71ce9dc60e174c to your computer and use it in GitHub Desktop.
Save dj0/4f962bb4cea8ea9ecb71ce9dc60e174c to your computer and use it in GitHub Desktop.
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