0Pricing
AI Prompt Engineering · レッスン

複数画像の比較プロンプト

2 枚以上の画像について、相違点、類似点、時間経過による変化を比較します。

「複数画像の比較プロンプト」はCoddyKit上の無料AI Prompt Engineeringレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAI Prompt Engineering学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 AI Prompt Engineeringコースには全4レッスンが含まれています。

複数画像プロンプト

Visionモデルは、1回のAPI呼び出しで複数の画像を処理できます。これにより、強力な比較タスクが可能になります。

  • ビフォー/アフター分析(商品写真、部屋のリフォーム、医療画像)
  • 製品バリエーションの比較(色の選択肢、サイズの比較)
  • 品質の比較(掲載に最適な写真の選択)
  • 変化の検出(ドキュメントの2つのバージョン、タイムスタンプ付きの2枚の画像)

複数画像プロンプトでは、モデルが各画像を識別し、どのような関係を分析すべきか理解できるよう、慎重に構成する必要があります。

1回の呼び出しで複数の画像を送信

APIは、コンテンツ項目のリストとして複数の画像を受け付けます。各画像には明確なラベルを付けます。

import anthropic, base64

client = anthropic.Anthropic(api_key='YOUR_API_KEY')

def compare_images(image_path_1, image_path_2, comparison_prompt):
    def encode(path):
        with open(path, 'rb') as f:
            return base64.standard_b64encode(f.read()).decode('utf-8')

    r = client.messages.create(
        model='claude-opus-4-5', max_tokens=600,
        messages=[{'role': 'user', 'content': [
            {'type': 'text', 'text': 'IMAGE 1:'},
            {'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/jpeg', 'data': encode(image_path_1)}},
            {'type': 'text', 'text': 'IMAGE 2:'},
            {'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/jpeg', 'data': encode(image_path_2)}},
            {'type': 'text', 'text': comparison_prompt}
        ]}]
    )
    return r.content[0].text

print('Multi-image comparison function defined.')

2つの製品を比較するプロンプト

消費者向けアプリケーションで2つの製品画像を比較します。

product_comparison_prompt = '''
Compare the two product images above (Image 1 and Image 2).

Analyze each of the following dimensions:

1. SIMILARITIES: What features, design elements, or characteristics do both products share?

2. DIFFERENCES: What are the key visual differences? Focus on:
   - Color and finish
   - Size and proportions (estimate if possible)
   - Design style (minimalist, ornate, modern, traditional)
   - Materials (if discernible)
   - Quality indicators

3. QUALITY ASSESSMENT: Which image appears to show a higher-quality product, and why?
   Rate each product 1-10 for apparent quality.

4. USE CASE: Based on appearance alone, which product seems better suited for:
   a) Professional/office use
   b) Home/casual use

Return your response in this format exactly.
'''

print(product_comparison_prompt)

ビフォー/アフター比較

ビフォー/アフター用プロンプトでは、どの画像がどちらに当たるのか、またどのような変化の背景があるのかを明確に示す必要があります。

before_after_prompt = '''
You are looking at two images: a BEFORE image (Image 1) and an AFTER image (Image 2).

Analyze the transformation:

1. WHAT CHANGED: List all visible changes from Before to After
2. WHAT STAYED THE SAME: List elements that are unchanged
3. QUALITY IMPROVEMENT: Rate the improvement on a scale of 1-10 (1=no improvement, 10=dramatic improvement)
4. REMAINING ISSUES: What could still be improved that the transformation did not address?

Context: This is a [CONTEXT_PLACEHOLDER] before/after comparison.

Return JSON:
{
  "changes": ["string"],
  "unchanged": ["string"],
  "improvement_score": 1-10,
  "remaining_issues": ["string"],
  "summary": "one sentence summary"
}
'''

# Use contexts: room renovation, product refurbishment, skin care treatment, document cleanup
print('Before/after prompt with JSON output defined.')

写真の品質選択

複数の候補から最適な写真を選択します。これは、Eコマース、ソーシャルメディア、出版ワークフローで役立ちます。

import anthropic, base64, json

client = anthropic.Anthropic(api_key='YOUR_API_KEY')

def select_best_photo(image_paths, use_case='e-commerce product listing'):
    def encode(path):
        with open(path, 'rb') as f:
            return base64.standard_b64encode(f.read()).decode('utf-8')

    content = []
    for i, path in enumerate(image_paths):
        content.append({'type': 'text', 'text': f'IMAGE {i+1}:'})
        content.append({'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/jpeg', 'data': encode(path)}})

    prompt = f'''
You have received {len(image_paths)} images. Select the best one for: {use_case}

Evaluate each on: lighting, composition, clarity, and suitability for the use case.
Return JSON: {{"best_image": 1-{len(image_paths)}, "score_breakdown": [{{"image_id": int, "score": 1-10, "reason": str}}]}}
'''
    content.append({'type': 'text', 'text': prompt})

    r = client.messages.create(model='claude-opus-4-5', max_tokens=300, messages=[{'role': 'user', 'content': content}])
    return json.loads(r.content[0].text)

print('Photo selection function defined.')

変化検出プロンプト

同じ画像の2つのバージョン間にある具体的な変化を検出します。これは、ドキュメントのバージョン管理、UIデザインレビュー、モニタリングに役立ちます。

change_detection_prompt = '''
Compare Image 1 (version A) with Image 2 (version B) of the same item.

Identify ALL changes, no matter how small.
For each change:
- Describe what changed
- Where in the image the change occurs (use quadrant: top-left, top-right, bottom-left, bottom-right, center)
- Classify the change: addition, removal, modification, movement

Return JSON:
{
  "total_changes": int,
  "changes": [
    {
      "description": str,
      "location": str,
      "type": "addition|removal|modification|movement"
    }
  ],
  "is_significant_change": true | false
}

If the images appear identical, return: {"total_changes": 0, "changes": [], "is_significant_change": false}
'''

print(change_detection_prompt)

A/Bデザイン比較

2つのデザイン案を客観的に比較します。これは、UI/UXに関する意思決定やクリエイティブディレクションに役立ちます。

design_comparison_prompt = '''
You are an experienced UX designer reviewing two design variants (Image 1 = Design A, Image 2 = Design B).

Evaluate both designs on:

1. VISUAL HIERARCHY: Which design guides the eye more effectively? Why?
2. READABILITY: Which has better text legibility and information density?
3. BRAND CONSISTENCY: Which feels more professional and polished?
4. USABILITY: Which would be easier for a new user to navigate?
5. EMOTIONAL IMPACT: Which creates a stronger positive first impression?

For each dimension, declare a winner (A or B) and explain in one sentence.

Final verdict: Return JSON:
{
  "winner": "A|B|tie",
  "dimension_winners": {"visual_hierarchy": str, "readability": str, "brand": str, "usability": str, "emotional": str},
  "winning_reasons": [str],
  "recommendation": str
}
'''

print('Design comparison prompt defined.')

構造化された類似度スコアリング

自動化されたパイプラインでは、画像間の類似度を数値スコアとして出力します。

similarity_prompt = '''
Compare these two images and provide a structured similarity analysis.

Return JSON:
{
  "overall_similarity": 0.0-1.0,
  "dimensions": {
    "subject_match": 0.0-1.0,
    "color_match": 0.0-1.0,
    "composition_match": 0.0-1.0,
    "style_match": 0.0-1.0
  },
  "key_differences": [str],
  "are_same_item": true | false | "cannot_determine"
}

Scoring: 1.0 = identical, 0.0 = completely different.
'''

import json
def similarity_score(image_path_1, image_path_2):
    result_text = compare_images(image_path_1, image_path_2, similarity_prompt)
    return json.loads(result_text)

print('Similarity scoring function defined.')
print('Use case: duplicate detection, product matching, visual search.')

3枚以上の画像への対応

3枚以上の画像を扱う場合は、増加する複雑さに対応できるようプロンプトを構成します。

def multi_image_prompt(n_images):
    image_labels = ', '.join(f'Image {i+1}' for i in range(n_images))
    return f'''
You have received {n_images} images: {image_labels}.

Rank all {n_images} images from best to worst for use as a product hero image.
For each image, provide:
- Rank (1=best)
- Score 1-10
- Key strengths
- Key weaknesses

Return JSON:
{{
  "ranking": [
    {{"rank": int, "image_id": int, "score": int, "strengths": [str], "weaknesses": [str]}}
  ],
  "recommended_image": int
}}
'''

# Works for 3, 4, or 5 images
print(multi_image_prompt(3)[:300])

複数画像プロンプトでよくある問題

複数の画像を扱う際によくある間違いと、その回避方法を示します。

  • 画像ラベルがない:モデルが各画像を取り違える可能性があります。各画像の前に必ずIMAGE 1:というテキストを付けてラベル付けします
  • 比較の観点がない:比較項目を指定せずに比較を求めると、焦点の定まらない出力になります。比較対象を正確に列挙します
  • コンテキストが不足している:ビフォー/アフター用プロンプトには、単に部屋の写真を2枚示すのではなく、部屋のリフォームなどの変化の背景が必要です
  • 画像が多すぎる:6枚以上では品質が低下します。2~4枚ずつのバッチで処理します
  • JSON出力を忘れている:文章による比較は解析が困難です。パイプラインでは必ず構造化されたJSONを要求します

時系列画像シーケンスの分析

画像が時間の経過を表す場合(毎週のチェックイン、建設の進捗、医療の経過観察など)、比較プロンプトでは時間の経過に伴う進行を明示的に分析する必要があります。

temporal_prompt = '''
You are analyzing a sequence of images taken over time.
Image 1 = earliest, Image 2 = most recent.

Analyze the progression:
1. PROGRESS: What improvements or changes occurred from earliest to most recent?
2. REGRESSION: Any deterioration or negative changes?
3. RATE: Is the rate of change faster, slower, or as expected?
4. TRAJECTORY: Based on the trend, what is the likely state in the next period?

Return JSON:
{
  "progress": [str],
  "regression": [str],
  "change_rate": "faster|on_track|slower|stalled",
  "trajectory": str,
  "next_period_prediction": str
}
'''

print("Temporal sequence analysis prompt defined.")
print("Use cases: fitness progress, construction tracking, medical imaging follow-up.")

確認問題

複数画像比較プロンプトに含めるべき、最も重要な構造要素は何ですか?

複数画像比較 — 要点

複数画像比較プロンプトにより、強力な視覚分析機能を利用できます。

  • コンテンツ配列内の各画像の前にテキストを置き、必ず画像に明確なラベルを付けます
  • 一般的な比較を求めるのではなく、視覚的階層、品質、類似度などの比較項目を指定します
  • ビフォー/アフター用プロンプトには、どのような変化が起きたのかという背景が必要です
  • パイプラインでは、類似度スコア、ランキング、変化検出などに構造化されたJSON出力を使用します
  • 製品比較、写真の品質選択、A/Bデザインレビューは価値の高いユースケースです
  • バッチは最大2~4枚に保ちます。枚数が増えると品質が低下します
  • 変化検出プロンプトでは、各変化を追加、削除、変更、移動の種類に分類します

よくある質問

「複数画像の比較プロンプト」レッスンは無料ですか?

はい。「複数画像の比較プロンプト」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、AI Prompt Engineeringコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 AI Prompt Engineeringコースには全4レッスンが含まれています。

「複数画像の比較プロンプト」で何を学びますか?

2 枚以上の画像について、相違点、類似点、時間経過による変化を比較します。 ブラウザで直接実行するハンズオンコードでAI Prompt Engineeringを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

AI Prompt Engineeringを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのAI Prompt Engineeringは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「複数画像の比較プロンプト」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このAI Prompt Engineeringレッスンでコードを書いて実行できますか?

はい。すべてのAI Prompt Engineeringレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 画像説明とキャプション作成のプロンプト
  2. 画像に関する質問応答
  3. 複数画像の比較プロンプト
  4. OCR とドキュメント分析のプロンプト
← AI Prompt Engineeringに戻る