mcpField
M
modelslab-image-editing

modelslab-image-editing

github.com/modelslabクリエイティブ・メディア1391 回インストール36 週間前に更新
リポジトリ

modelslab-image-editing について

modelslab-image-editing は、APIリクエストでModelsLabの画像編集エンドポイントを利用するスキルです。背景・物体の除去、拡大、アウトペインティング、マスク作成、指示による編集に対応します。

主な機能

  1. 01画像の背景除去
  2. 02画像を2倍または4倍に拡大
  3. 03アウトペインティングで画像の端を拡張
  4. 04指定した物体の除去
  5. 05物体マスクの作成
  6. 06Qwenへの指示による画像編集

活用シーン

  1. 01商品写真の背景を除去して拡大
  2. 02不動産写真から不要な物体を除去
  3. 03グラフィックを異なるアスペクト比に拡張
  4. 04プロフィール写真の解像度を向上

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/modelslab/skills --skill modelslab-image-editing

インストール後、Claude Code で/modelslab-image-editingを入力して読み込まれたか確認します。

詳細

ModelsLab 画像編集

背景の削除、アップスケーリング、アウトペインティング、オブジェクト操作など、AI を活用したプロ向けの画像編集ツールです。

このスキルを使用する場面

  • 画像の背景を削除する
  • 画像をアップスケールする(2x、4x の超解像)
  • 画像の境界を超えて拡張する(アウトペインティング)
  • 画像から不要なオブジェクトを削除する
  • プロ品質の商品写真を作成する
  • 画質を向上させる
  • AI の支援を受けて画像を編集する

利用可能なエンドポイント

背景の削除

POST https://modelslab.com/api/v6/image_editing/removebg

超解像(アップスケーリング)

POST https://modelslab.com/api/v6/image_editing/super_resolution

アウトペインティング

POST https://modelslab.com/api/v6/image_editing/outpainting

オブジェクトの削除

POST https://modelslab.com/api/v6/image_editing/object_removal

マスクの作成

POST https://modelslab.com/api/v6/image_editing/create_mask

Qwen Image Edit(AI 編集)

POST https://modelslab.com/api/v6/image_editing/qwen_edit

背景の削除

import requests

def remove_background(image_url, api_key):
    """Remove background from an image.

    Args:
        image_url: URL of the image
        api_key: Your ModelsLab API key

    Returns:
        URL of image with transparent background
    """
    response = requests.post(
        "https://modelslab.com/api/v6/image_editing/removebg",
        json={
            "key": api_key,
            "image": image_url
        }
    )

    data = response.json()

    if data["status"] == "success":
        return data["output"][0]
    else:
        raise Exception(f"Error: {data.get('message', 'Unknown error')}")

# Usage
result = remove_background(
    "https://example.com/product-photo.jpg",
    "your_api_key"
)
print(f"Image without background: {result}")

超解像(アップスケーリング)

def upscale_image(image_url, api_key, scale=4):
    """Upscale an image to higher resolution.

    Args:
        image_url: URL of the image to upscale
        scale: Upscale factor (2 or 4)

    Returns:
        URL of upscaled high-resolution image
    """
    response = requests.post(
        "https://modelslab.com/api/v6/image_editing/super_resolution",
        json={
            "key": api_key,
            "image": image_url,
            "scale": scale  # 2x or 4x
        }
    )

    data = response.json()

    if data["status"] == "success":
        return data["output"][0]
    else:
        raise Exception(data.get("message"))

# Upscale to 4x resolution
hd_image = upscale_image(
    "https://example.com/low-res.jpg",
    "your_api_key",
    scale=4
)
print(f"HD image: {hd_image}")

アウトペインティング(画像の拡張)

def extend_image(image_url, prompt, api_key, width=1024, height=768):
    """Extend an image beyond its original boundaries.

    Args:
        image_url: Original image URL
        prompt: Description of how to extend the image
        width: New width (larger than original)
        height: New height (larger than original)
    """
    response = requests.post(
        "https://modelslab.com/api/v6/image_editing/outpainting",
        json={
            "key": api_key,
            "image": image_url,
            "prompt": prompt,
            "width": width,
            "height": height,
            "num_inference_steps": 30,
            "guidance_scale": 7.5
        }
    )

    data = response.json()

    if data["status"] == "success":
        return data["output"][0]
    elif data["status"] == "processing":
        return poll_result(data["id"], api_key)

# Extend a landscape image
extended = extend_image(
    "https://example.com/landscape.jpg",
    "Continue the mountain landscape with more peaks and valleys",
    "your_api_key",
    width=1024,
    height=768
)

オブジェクトの削除

def remove_object(image_url, object_name, api_key):
    """Remove a specific object from an image.

    Args:
        image_url: URL of the image
        object_name: Name of object to remove (e.g., "person", "car", "sign")
    """
    response = requests.post(
        "https://modelslab.com/api/v6/image_editing/object_removal",
        json={
            "key": api_key,
            "image": image_url,
            "object_name": object_name
        }
    )

    data = response.json()

    if data["status"] == "success":
        return data["output"][0]
    elif data["status"] == "processing":
        return poll_result(data["id"], api_key)

# Remove person from photo
cleaned = remove_object(
    "https://example.com/photo.jpg",
    "person in background",
    "your_api_key"
)

AI を活用した画像編集(Qwen)

def edit_image_with_ai(image_url, edit_instruction, api_key):
    """Edit image using AI instructions.

    Args:
        image_url: URL of the image to edit
        edit_instruction: Natural language editing instruction
    """
    response = requests.post(
        "https://modelslab.com/api/v6/image_editing/qwen_edit",
        json={
            "key": api_key,
            "image": image_url,
            "prompt": edit_instruction,
            "negative_prompt": "low quality, distorted",
            "num_inference_steps": 30,
            "guidance_scale": 7.5
        }
    )

    data = response.json()

    if data["status"] == "success":
        return data["output"][0]
    elif data["status"] == "processing":
        return poll_result(data["id"], api_key)

# AI-powered editing
edited = edit_image_with_ai(
    "https://example.com/portrait.jpg",
    "Make the background more blurred and add warm sunset lighting",
    "your_api_key"
)

マスクの作成

def create_object_mask(image_url, object_description, api_key):
    """Create a mask for a specific object in an image.

    Args:
        image_url: URL of the image
        object_description: What to mask (e.g., "person", "car", "background")

    Returns:
        URL of mask image (white = selected, black = not selected)
    """
    response = requests.post(
        "https://modelslab.com/api/v6/image_editing/create_mask",
        json={
            "key": api_key,
            "image": image_url,
            "object": object_description
        }
    )

    data = response.json()

    if data["status"] == "success":
        return data["output"][0]

# Create mask for person
mask_url = create_object_mask(
    "https://example.com/group-photo.jpg",
    "person in red shirt",
    "your_api_key"
)

ポーリング用ヘルパー

import time

def poll_result(request_id, api_key, timeout=300):
    """Poll for async editing results."""
    start_time = time.time()

    while time.time() - start_time < timeout:
        fetch = requests.post(
            f"https://modelslab.com/api/v6/image_editing/fetch/{request_id}",
            json={"key": api_key}
        )
        result = fetch.json()

        if result["status"] == "success":
            return result["output"][0]
        elif result["status"] == "failed":
            raise Exception(result.get("message", "Failed"))

        time.sleep(5)

    raise Exception("Timeout")

よくあるワークフロー

EC サイトの商品写真
def prepare_product_image(image_url, api_key):
    """Complete product photo workflow."""

    # Step 1: Remove background
    no_bg = remove_background(image_url, api_key)
    print(f"Background removed: {no_bg}")

    # Step 2: Upscale to high resolution
    hd_image = upscale_image(no_bg, api_key, scale=4)
    print(f"Upscaled: {hd_image}")

    return hd_image

product_image = prepare_product_image(
    "https://example.com/product.jpg",
    "your_api_key"
)
写真の修整
def cleanup_photo(image_url, unwanted_objects, api_key):
    """Remove multiple unwanted objects from photo."""

    cleaned_image = image_url

    for obj in unwanted_objects:
        cleaned_image = remove_object(cleaned_image, obj, api_key)
        print(f"Removed: {obj}")

    # Upscale final result
    final = upscale_image(cleaned_image, api_key, scale=2)

    return final

result = cleanup_photo(
    "https://example.com/vacation.jpg",
    ["power lines", "trash can", "stranger in background"],
    "your_api_key"
)
拡張と高画質化
def extend_and_enhance(image_url, extension_prompt, api_key):
    """Extend image and upscale result."""

    # Extend the image
    extended = extend_image(
        image_url,
        extension_prompt,
        api_key,
        width=1920,
        height=1080
    )

    # Upscale for maximum quality
    final = upscale_image(extended, api_key, scale=2)

    return final

ベストプラクティス

1. 背景の削除
  • 被写体が背景からはっきり分離されている画像で最も効果を発揮します
  • 元の画像の照明が適切だと、より良い結果が得られます
  • 入力画像の品質が高いほど、出力品質も向上します
2. 超解像
  • 適度にアップスケールする場合は 2x を使用します
  • 最大限に画質を向上させる場合は 4x を使用します
  • すでに高解像度の画像はアップスケールしないでください
  • 明瞭でピントの合った画像で最良の結果が得られます
3. アウトペインティング
  • 拡張用のプロンプトは具体的に指定してください
  • 元の画像のスタイルに合わせてください
  • 拡張時は構図を考慮してください
  • サイズを変えて試してください
4. オブジェクトの削除
  • オブジェクトの位置を具体的に指定してください
  • 背景がシンプルな画像で最も効果を発揮します
  • 複雑なシーンでは、複数回の処理が必要になる場合があります
5. バッチ処理には Webhook を使用する
# Process many images
for image in image_list:
    response = requests.post(
        endpoint,
        json={
            "key": api_key,
            "image": image,
            "webhook": "https://yourserver.com/callback",
            "track_id": f"img_{image_id}"
        }
    )

よくあるユースケース

プロ向けの顔写真
# Remove background and upscale
headshot = remove_background(original, api_key)
hd_headshot = upscale_image(headshot, api_key, scale=4)
不動産写真
# Remove unwanted items
clean_room = remove_object(
    room_photo,
    "personal items and clutter",
    api_key
)

# Extend to show more space
wider_view = extend_image(
    clean_room,
    "Continue the modern living room with more furniture",
    api_key,
    width=1920,
    height=1080
)
ソーシャルメディア用のグラフィック
# Upscale for quality
high_res = upscale_image(graphic, api_key, scale=2)

# Extend to different aspect ratios
instagram_square = extend_image(
    high_res,
    "Extend background",
    api_key,
    width=1080,
    height=1080
)

エラー処理

try:
    result = remove_background(image_url, api_key)
    print(f"Success: {result}")
except Exception as e:
    print(f"Editing failed: {e}")
    # Log error, retry, or notify user

リソース

関連スキル

  • modelslab-image-generation - 編集する画像を生成する
  • modelslab-webhooks - 非同期処理を扱う
  • modelslab-sdk-usage - 公式 SDK を使用する

コメント