Created
May 4, 2024 12:34
-
-
Save showyou/fa1510487b71873cfa0d5e477cb43979 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# pip install pillow | |
# ref: https://tat-pytone.hatenablog.com/entry/2021/12/22/202936 | |
from PIL import Image | |
# 画像の読み出し | |
im1 = Image.open('input/tsuzuri1.jpg') | |
im2 = Image.open('input/nankyoku.jpg') | |
im2 = im2.resize((960, 1165)) | |
# グリーンバックの画像をHSV変換 | |
im1_hsv = im1.convert('HSV') | |
# HSV画像をチャンネル別に分割 | |
source = im1_hsv.split() | |
# Hが99から108の範囲を採用し画素値を255としてマスク画像を作成 | |
mask = source[0].point(lambda i: 80< i < 108 and 255) | |
# マスク画像の白にim2、マスク画像の黒部分にim1を割り当てて合成 | |
im = Image.composite(im2, im1, mask) | |
# 画像の保存 | |
im.save('tsuzuri_in_nankyoku.jpg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment