LoginSignup
2
2

画像からプロンプトを考えて最も似ている画像を生成した人が勝ちのゲーム

Last updated at Posted at 2023-12-10

はじめに

がちもとさんアドベントカレンダー11日目の記事です。
画像からプロンプトを考えて最も似ている画像を生成した人が勝ちのゲームをやっていきます

ゲームの流れ

1.お題の画像を用意する
2.画像を見てプロンプトを考える
3.ChatGPT4(DALLE)で画像生成する
4.お題の画像と生成した画像の類似度で競う(ChatGPT4のCodeInterpreterで計算してもらう)

やってみよう

1.お題を出す人は、ChatGPTに画像を生成してもらいましょう(ご自身で用意していただいてもかまいません)

image.png

これに決めました。photo of a bustling city street at sunset with people walking, vendors selling food, and tall buildings in the background

DALL·E 2023-12-11 01.51.49 - photo of a bustling city street at sunset with people walking, vendors selling food, and tall buildings in the background.png

2.画像を見てプロンプトを考えます。

私が考えたプロンプトはこちら 「都市で祭りが開かれていて、屋台が道路沿いに並んでいる。手前は横断中の人がいる。夕日」

3.ChatGPT4(DALLE)に画像を生成してもらいます。

image.png

かなりいい感じに生成できたんじゃないでしょうか?w

4.ChatGPT4(CodeInterpreter)に画像をアップロードして類似度を出してもらいましょう。Code Interpreterが出した類似度を求めるプログラムはこちらです。

similarity.py
from PIL import Image
import numpy as np
from skimage.metrics import structural_similarity as ssim
import cv2

# Load the images
image1_path = '/mnt/data/DALL·E 2023-12-11 01.51.49 - photo of a bustling city street at sunset with people walking, vendors selling food, and tall buildings in the background.png'
image2_path = '/mnt/data/DALL·E 2023-12-11 01.55.34 - photo of a city festival with stalls lined up along the road. In the foreground, a person is crossing the street. The setting sun casts a warm glow ov.png'

image1 = Image.open(image1_path)
image2 = Image.open(image2_path)

# Convert the images to grayscale
image1_gray = image1.convert('L')
image2_gray = image2.convert('L')

# Convert the images to numpy arrays
image1_array = np.array(image1_gray)
image2_array = np.array(image2_gray)

# Resize images to match each other
image1_resized = cv2.resize(image1_array, (image2_array.shape[1], image2_array.shape[0]))

# Calculate SSIM
similarity_index = ssim(image1_resized, image2_array)

print(similarity_index)
お題 0.343 0.373
DALL·E 2023-12-11 01.51.49 - photo of a bustling city street at sunset with people walking, vendors selling food, and tall buildings in the background.png DALL·E 2023-12-11 01.55.34 - photo of a city festival with stalls lined up along the road. In the foreground, a person is crossing the street. The setting sun casts a warm glow ov.png DALL·E 2023-12-11 01.55.56 - photo of a lively city celebration. Numerous stalls offering various goods and food are set up beside a road. In the immediate foreground, an individu.png

最も大きい類似度を出せた人が勝ちです!
アイスブレイクとかでやってみてくださいね~

2
2
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
2
2