vision-multimodal について
Vision & Multimodal Skillは、Claudeで画像や文書を分析するための手法をまとめたスキルです。画像の確認、テキスト抽出、チャートや図の解釈などに利用できます。
主な機能
- 01画像とスクリーンショットの分析
- 02PDFと文書の処理
- 03OCR形式のテキスト抽出
- 04画像の比較
- 05チャートと図の解釈
- 06画像の最適化ガイド
活用シーン
- 01画像からテキストや表を抽出
- 02複数の画像を比較
- 03チャートや技術図を分析
- 04PDF文書を処理
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ thelobbi/ claude --skill vision-multimodalインストール後、Claude Code で/vision-multimodalを入力して読み込まれたか確認します。
詳細
ビジョン&マルチモーダルスキル
Claude のビジョン機能を活用して、画像分析、ドキュメント処理、マルチモーダル理解を行います。
このスキルを使用する場面
- 画像の分析と説明
- ドキュメント/PDF の処理
- スクリーンショットの分析
- OCR のようなテキスト抽出
- 視覚的な比較
- グラフや図の解釈
対応フォーマット
| フォーマット | 状態 | 最適な用途 |
|---|---|---|
| JPEG | ✓ | 写真、自然の風景 |
| PNG | ✓ | スクリーンショット、UI、テキスト |
| GIF | ✓ | アニメーション(最初のフレーム) |
| WebP | ✓ | モダンな圧縮形式 |
| ✓ | ドキュメント(Files API 経由) |
画像サイズのガイドライン
- 最小: 200 ピクセル(これより小さいと精度が低下します)
- 最適: 1000x1000 ピクセル
- 最大: 8000x8000 ピクセル
- トークンコスト: 約(幅 × 高さ)/ 1000
- ヒント: 最大辺を 1568px にリサイズすると、トークンを 30~50% 節約できます
基本パターン
パターン 1:単一画像の分析
import anthropic
import base64
client = anthropic.Anthropic()
# Load and encode image
with open("image.jpg", "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode("utf-8")
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": image_data
}
},
{
"type": "text",
"text": "Describe this image in detail."
}
]
}]
)
パターン 2:URL からの画像
import httpx
# Fetch and encode from URL
image_url = "https://example.com/image.jpg"
response = httpx.get(image_url)
image_data = base64.standard_b64encode(response.content).decode("utf-8")
# Then use same pattern as above
パターン 3:複数の画像
# Compare multiple images (up to 100 per request)
messages = [{
"role": "user",
"content": [
{"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": image1}},
{"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": image2}},
{"type": "text", "text": "Compare these two images and list the differences."}
]
}]
パターン 4:画像を使った少数ショット例
# Teach by example
messages = [
# Example 1
{"role": "user", "content": [
{"type": "image", "source": {...}},
{"type": "text", "text": "Classify this image."}
]},
{"role": "assistant", "content": "Category: Landscape\nElements: Mountains, lake, trees"},
# Example 2
{"role": "user", "content": [
{"type": "image", "source": {...}},
{"type": "text", "text": "Classify this image."}
]},
{"role": "assistant", "content": "Category: Portrait\nElements: Person, indoor, professional"},
# Target image
{"role": "user", "content": [
{"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": target_image}},
{"type": "text", "text": "Classify this image."}
]}
]
パターン 5:PDF の処理
# Using Files API (beta)
with open("document.pdf", "rb") as f:
pdf_data = base64.standard_b64encode(f.read()).decode("utf-8")
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=4096,
messages=[{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": pdf_data
}
},
{"type": "text", "text": "Summarize this document."}
]
}]
)
ビジョン向けプロンプトエンジニアリング
戦略 1:役割の割り当て
prompt = """You have perfect vision and exceptional attention to detail,
making you an expert at analyzing technical diagrams.
Analyze this architecture diagram and identify:
1. All components
2. Data flow between components
3. Potential bottlenecks"""
戦略 2:段階的な思考
prompt = """Before answering, analyze the image systematically:
<thinking>
1. What is the overall subject?
2. What are the key elements?
3. How do elements relate to each other?
4. What details stand out?
</thinking>
Then provide your answer based on this analysis."""
戦略 3:構造化出力
prompt = """Extract information from this receipt and return as JSON:
{
"vendor": "",
"date": "",
"items": [{"name": "", "price": 0}],
"total": 0
}"""
画像の最適化
from PIL import Image
import io
def optimize_for_claude(image_path, max_dimension=1568):
"""Resize image to reduce token usage by 30-50%"""
with Image.open(image_path) as img:
# Calculate new dimensions
ratio = min(max_dimension / img.width, max_dimension / img.height)
if ratio < 1:
new_size = (int(img.width * ratio), int(img.height * ratio))
img = img.resize(new_size, Image.LANCZOS)
# Convert to bytes
buffer = io.BytesIO()
img.save(buffer, format="JPEG", quality=85)
return base64.standard_b64encode(buffer.getvalue()).decode("utf-8")
一般的な使用例
テキスト抽出(OCR のような処理)
prompt = """Extract all text from this image.
Preserve the original formatting and structure as much as possible.
If text is unclear, indicate with [unclear]."""
表の抽出
prompt = """Extract the table data from this image.
Return as a markdown table with proper headers and alignment."""
グラフの分析
prompt = """Analyze this chart:
1. What type of chart is this?
2. What are the axes/labels?
3. What are the key data points?
4. What trends or patterns are visible?"""
ベストプラクティス
推奨事項:
- 高品質な画像(≥1000px)を使用します
- トークンを節約するため、大きな画像をリサイズします
- 何を確認すべきかのコンテキストを提供します
- 一貫した出力を得るため、少数ショットの例を使用します
非推奨事項:
- 200px 未満の画像を送信しないでください
- 手書き文字の OCR が完璧であると期待しないでください
- 非常に大きな画像(>8000px)を送信しないでください
- 複数の画像を扱う際にトークンコストを無視しないでください
制限事項
- 特定の個人を識別できません
- 非常に小さなテキストの読み取りが難しい場合があります
- アニメーション GIF:最初のフレームのみ分析されます
- 一部の専門的な記号を誤読する場合があります
関連項目
- [[llm-integration]] - API の基本
- [[extended-thinking]] - 複雑な推論
- [[citations-retrieval]] - ドキュメントの引用
コメント
Markdown 対応