LoginSignup
1
1

More than 1 year has passed since last update.

夏らしい画像で合成練習してみた

Posted at

はじめに

連日暑くて困っています。暑くてやる気が出ない。
暑さへの対処は暑さでどうにかしようと考え、何か夏らしき画像を重ね合わせて、スーパー夏っぽい画像が作れないか試してみました。

コード

夏らしいもので思いついたのがすいかだったので、今回はすいかに対象を絞りました。
スクレイピングで画像を取得して、足し合わせています。

#googleからキーワード:「すいか」で画像をスクレイピング
!pip install icrawler
from icrawler.builtin import GoogleImageCrawler

crawler = GoogleImageCrawler(
    feeder_threads=1,
    parser_threads=1,
    downloader_threads=4,
    storage={"root_dir": 'suika'})
crawler.crawl(keyword="すいか",
              max_num=500,
              file_idx_offset=0)

#画像のリサイズとRGB化(pngで拡張子統一)
import os
from PIL import Image

FromImgName = "/content/suika/"
ToImgName = "suika-re"
files = os.listdir(FromImgName)
for file in files:
    img = Image.open(os.path.join(FromImgName, file))
    img_resize = img.resize((300, 300)).convert('RGB')

    img_resize.save(os.path.join(ToImgName, file[:-3]+"png"))

#画像を合成する
import cv2
import glob
import numpy as np 

flist = glob.glob("suika-re/*.png")     
sums = cv2.imread(flist.pop()).astype(np.uint32)

#平均化
for fname in flist:
    sums += cv2.imread(fname)
cv2.imwrite("mean.png", (sums/(len(flist)+1)))

完成したのが下の画像。実の赤い部分が何となく見えるぐらいですね。
夏!というよりは、アート的な想像力を豊かにする画像ができました。
mean.png

まとめ

スクレイピングができるようになった。
すいかの画像を足し合わせたら、アート作品になった。

実はそこまですいか好きではない。

参照

https://tetoblog.org/2021/05/python-resize-bulk/
https://icrawler.readthedocs.io/en/latest/
https://campkougaku.com/2020/04/20/blend/

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1