はじめに
がちもとさんアドベントカレンダー11日目の記事です。
画像からプロンプトを考えて最も似ている画像を生成した人が勝ちのゲームをやっていきます
ゲームの流れ
1.お題の画像を用意する
2.画像を見てプロンプトを考える
3.ChatGPT4(DALLE)で画像生成する
4.お題の画像と生成した画像の類似度で競う(ChatGPT4のCodeInterpreterで計算してもらう)
やってみよう
1.お題を出す人は、ChatGPTに画像を生成してもらいましょう(ご自身で用意していただいてもかまいません)
これに決めました。photo of a bustling city street at sunset with people walking, vendors selling food, and tall buildings in the background
2.画像を見てプロンプトを考えます。
私が考えたプロンプトはこちら 「都市で祭りが開かれていて、屋台が道路沿いに並んでいる。手前は横断中の人がいる。夕日」
3.ChatGPT4(DALLE)に画像を生成してもらいます。
かなりいい感じに生成できたんじゃないでしょうか?w
4.ChatGPT4(CodeInterpreter)に画像をアップロードして類似度を出してもらいましょう。Code Interpreterが出した類似度を求めるプログラムはこちらです。
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 |
---|---|---|
最も大きい類似度を出せた人が勝ちです!
アイスブレイクとかでやってみてくださいね~