0Pricing
AI Prompt Engineering · レッスン

画像説明とキャプション作成のプロンプト

物体、関係、雰囲気、技術的詳細にモデルの注意を向ける方法を学びます。

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

ビジョンモデルとプロンプト設計

GPT-4oやClaudeのような視覚言語モデル(VLM)は、テキストとともに画像を処理できます。画像と一緒に送るプロンプトは、モデルが生成する説明の品質、焦点、形式に大きな影響を与えます。

指示するプロンプトがない場合、何を説明するかはモデルが決めるため、必要な内容と一致しない可能性があります。構造化された説明プロンプトを使うと、どの要素に注目し、出力をどのように整理するかをモデルに正確に指示できます。

プロンプトとともに画像を送信する

Anthropic APIは、base64エンコードされたコンテンツまたはURLとして画像を受け付けます。基本的な構造は次のとおりです。

import anthropic, base64

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

with open('image.jpg', 'rb') as f:
    image_data = base64.standard_b64encode(f.read()).decode('utf-8')

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=500,
    messages=[{
        'role': 'user',
        'content': [
            {
                'type': 'image',
                'source': {
                    'type': 'base64',
                    'media_type': 'image/jpeg',
                    'data': image_data
                }
            },
            {
                'type': 'text',
                'text': 'Describe this image in detail.'
            }
        ]
    }]
)
print(response.content[0].text)

非構造化された説明プロンプト

最も単純なプロンプトであるこの画像を説明してくださいでは、モデルが重視する内容によって出力が完全に左右されます。多くのユースケースでは、これでは不十分です。

  • モデルは、最も関連性の高い要素ではなく、最も目立つ要素に注目することがあります
  • 似た画像でも、説明の長さや構成が大きく異なることがあります
  • 重要な詳細(テキスト、小さな物体、背景の文脈)が省略されることがよくあります

構造化された説明プロンプトを使えば、これらの問題をすべて解決できます。

構造化された説明:注目点を指示する

構造化された説明プロンプトでは、特定の視覚要素にモデルが注目するよう明示的に指示します。

structured_prompt = '''
Describe this image in detail, addressing each of the following aspects:

1. FOREGROUND: Main subjects and objects in the foreground
2. BACKGROUND: Setting, environment, and background elements
3. COLORS: Dominant color palette and notable color contrasts
4. MOOD: Emotional tone, atmosphere, and lighting
5. TEXT: Any visible text, signs, labels, or written content
6. PEOPLE: If people are present — count, approximate age, pose, expression

Organize your response using these exact section headers.
Be specific and descriptive. Avoid vague terms like "some" or "various".
'''

print(structured_prompt)

説明の長さを制御する

同じ画像でも、ユースケースによって必要な説明の長さは異なります。プロンプトで長さを明示的に制御してください。

# For image captions in a product catalog
short_prompt = '''
Write a 1-sentence product image caption (under 15 words).
Focus on the product, its key feature, and setting.
'''

# For accessibility alt-text
alt_text_prompt = '''
Write an image alt-text description for a visually impaired user.
Limit: 125 characters.
Include: what the image shows, any text visible in the image, the most important action or emotion.
'''

# For detailed analysis
detailed_prompt = '''
Write a detailed image analysis of 200-300 words.
Cover: composition, subjects, setting, colors, mood, and any notable technical or artistic elements.
Structure as a single flowing paragraph.
'''

print('Three length-controlled description prompts defined.')

ドメイン固有の説明プロンプト

分野ごとに、必要とされる説明の語彙や注目領域は異なります。

# Medical imaging description
medical_prompt = '''
Describe the key visual findings in this medical image.
Focus on: anatomical structures visible, any abnormalities or anomalies,
location using standard anatomical terms (left/right, superior/inferior, medial/lateral),
and image quality or artifacts.
Note: this description is for informational purposes only, not diagnostic.
'''

# Architecture / real estate
architecture_prompt = '''
Describe this property image for a real estate listing.
Cover: room type, approximate size, key features (flooring, ceiling, natural light),
condition, notable fixtures or finishes, and overall style.
Tone: professional, appealing, factual.
'''

# Security / surveillance
security_prompt = '''
Describe this security camera image.
Note: number of people, approximate location in frame, clothing colors,
any objects being carried, direction of movement, and time of day if discernible.
'''

print('Domain-specific prompts defined.')

画像説明からの構造化出力

自動化されたパイプラインでは、文章ではなく、画像の説明を構造化されたJSONで返すよう求めます。

json_description_prompt = '''
Analyze this product image and return a JSON description:
{
  "product_name": "inferred product name or null",
  "category": "electronics|clothing|furniture|food|other",
  "colors": ["primary color", "secondary color"],
  "condition": "new|used|unclear",
  "background": "white|lifestyle|outdoor|studio|other",
  "people_visible": true | false,
  "text_visible": "extracted text or null",
  "quality_score": 1-10,
  "caption": "one sentence product caption"
}
Return only the JSON object.
'''

print(json_description_prompt)

アクセシビリティを重視した説明

アクセシビリティのために画像を説明する場合は、視覚障害のあるユーザーに必要な情報を優先する、特定のプロンプト形式が必要です。

accessibility_prompt = '''
Write an image description optimized for screen reader accessibility.

Guidelines:
- Start with the most important content (what is this image about?)
- Describe spatial relationships (the man on the left, the building in the background)
- Include all visible text verbatim
- Describe faces and expressions if relevant to the content
- Skip decorative descriptions unless they convey meaning
- End with: if this is a graph or chart, include the key data it shows
- Maximum 250 characters for alt-text. If more is needed, write a 1-sentence alt-text plus a longer caption.
'''

print(accessibility_prompt)

説明プロンプトでよくあるミスを避ける

画像説明プロンプトでよくあるミスと、その修正方法です。

  • 曖昧すぎる:画像を説明してください → 修正:説明する要素を指定します
  • 形式を指定していない:JSONが必要なのにモデルが文章を書く → 修正:出力形式を明示的に指定します
  • 長さの制限がない:モデルが1000語書く → 修正:目標とする長さを指定します
  • 焦点がない:すべての要素を同じように説明する → 修正:どの要素を主とするか指定します
  • ドメインの文脈がない:専門的な画像に対して一般的な説明をする → 修正:分野の語彙と注目基準を含めます

画像説明のバッチ処理パイプライン

自動化されたパイプラインで複数の画像を処理する場合:

import anthropic, base64, json
from pathlib import Path

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

DESCRIPTION_PROMPT = '''
Describe this image for a product catalog.
Return JSON: {"caption": str, "colors": [str], "category": str, "alt_text": str}
'''

def describe_image(image_path):
    with open(image_path, 'rb') as f:
        img_b64 = base64.standard_b64encode(f.read()).decode('utf-8')
    r = client.messages.create(
        model='claude-opus-4-5', max_tokens=200,
        messages=[{'role': 'user', 'content': [
            {'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/jpeg', 'data': img_b64}},
            {'type': 'text', 'text': DESCRIPTION_PROMPT}
        ]}]
    )
    return json.loads(r.content[0].text)

print('Batch image description pipeline defined.')

説明プロンプトの品質をテストする

網羅性と一貫性を確保するため、多様な画像セットで説明プロンプトをテストします。

  • 白い背景に置かれたシンプルな製品
  • 複数の人物が写ったライフスタイル写真
  • 大量のテキストを含む文書や看板
  • 暗い画像や低品質の画像
  • 抽象的または曖昧な内容

各テスト画像について、出力が必要な要素をすべて含み、長さの制約を守り、必要な形式を使用していることを確認します。いずれかのカテゴリで体系的な失敗が見られたら、プロンプトを調整してください。

クイックチェック

単純な「この画像を説明してください」というプロンプトと比べて、構造化された画像説明プロンプトを使う主な利点は何ですか?

画像説明プロンプト — 重要ポイント

構造化された画像説明プロンプトは、一貫性があり役立つビジュアルAIの出力に不可欠です。

  • 説明する視覚要素(前景、背景、色、雰囲気、テキスト、人物)を明示的に列挙します
  • 出力形式(文章、JSON、特定のセクション見出し)を指定します
  • 長さを明示的に制御し、ユースケースに合わせます(15語のキャプションと250語の分析など)
  • ドメイン固有のプロンプト(医療、不動産、セキュリティ)には、分野の語彙と注目基準が必要です
  • アクセシビリティのためには、美的要素より情報を優先し、見えているすべてのテキストをそのまま含めます
  • 製品、ライフスタイル、テキストの多い画像、低品質の画像、抽象的な画像など、多様な画像タイプでテストします

よくある質問

「画像説明とキャプション作成のプロンプト」レッスンは無料ですか?

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

「画像説明とキャプション作成のプロンプト」で何を学びますか?

物体、関係、雰囲気、技術的詳細にモデルの注意を向ける方法を学びます。 ブラウザで直接実行するハンズオンコードでAI Prompt Engineeringを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「画像説明とキャプション作成のプロンプト」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

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