modelslab-image-editing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ModelsLab Image Editing

ModelsLab 图片编辑

Professional image editing tools powered by AI including background removal, upscaling, outpainting, and object manipulation.
由AI驱动的专业图片编辑工具,包括背景移除、图片放大、图像扩展和物体处理。

When to Use This Skill

何时使用该Skill

  • Remove backgrounds from images
  • Upscale images (2x, 4x super resolution)
  • Extend images beyond their borders (outpainting)
  • Remove unwanted objects from images
  • Create professional product photos
  • Enhance image quality
  • Edit images with AI assistance
  • 移除图片背景
  • 图片放大(2倍、4倍超分辨率)
  • 扩展图片边界(图像扩展)
  • 移除图片中不需要的物体
  • 创建专业产品照片
  • 提升图片质量
  • 在AI辅助下编辑图片

Available Endpoints

可用端点

Background Removal

背景移除

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

Super Resolution (Upscaling)

超分辨率(图片放大)

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

Outpainting

图像扩展

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

Object Removal

物体移除

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

Mask Creator

蒙版创建

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

Qwen Image Edit (AI Editing)

Qwen 图片编辑(AI编辑)

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

Background Removal

背景移除

python
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')}")
python
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

Usage

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

Super Resolution (Upscaling)

超分辨率(图片放大)

python
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"))
python
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

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}")
undefined
hd_image = upscale_image( "https://example.com/low-res.jpg", "your_api_key", scale=4 ) print(f"HD image: {hd_image}")
undefined

Outpainting (Extend Images)

图像扩展(扩展图片)

python
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)
python
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

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 )
undefined
extended = extend_image( "https://example.com/landscape.jpg", "Continue the mountain landscape with more peaks and valleys", "your_api_key", width=1024, height=768 )
undefined

Object Removal

物体移除

python
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)
python
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

Remove person from photo

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

AI-Powered Image Editing (Qwen)

AI驱动的图片编辑(Qwen)

python
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)
python
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

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" )
undefined
edited = edit_image_with_ai( "https://example.com/portrait.jpg", "Make the background more blurred and add warm sunset lighting", "your_api_key" )
undefined

Create Mask

创建蒙版

python
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]
python
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

Create mask for person

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

Polling Helper

轮询辅助函数

python
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")
python
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")

Common Workflows

常见工作流

E-commerce Product Photos

电商产品图片

python
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"
)
python
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"
)

Photo Cleanup

图片清理

python
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"
)
python
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"
)

Extend and Enhance

扩展与增强

python
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
python
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

Best Practices

最佳实践

1. Background Removal

1. 背景移除

  • Works best with clear subject separation
  • Good lighting in original image helps
  • High-quality input = better output
  • 在主体与背景分离清晰的图片上效果最佳
  • 原始图片光线良好有助于提升效果
  • 高质量输入=更好的输出

2. Super Resolution

2. 超分辨率

  • Use 2x for moderate upscaling
  • Use 4x for maximum quality boost
  • Don't upscale already high-res images
  • Best results with clear, focused images
  • 2倍放大适用于适度提升分辨率
  • 4倍放大适用于最大化画质提升
  • 不要对已为高分辨率的图片进行放大
  • 在清晰、对焦准确的图片上效果最佳

3. Outpainting

3. 图像扩展

  • Be specific in extension prompts
  • Match style of original image
  • Consider composition when extending
  • Test different sizes
  • 扩展提示语要具体
  • 匹配原始图片的风格
  • 扩展时考虑构图
  • 测试不同尺寸

4. Object Removal

4. 物体移除

  • Be specific about object location
  • Works best with simple backgrounds
  • May need multiple passes for complex scenes
  • 明确说明物体的位置
  • 在简单背景上效果最佳
  • 复杂场景可能需要多次处理

5. Use Webhooks for Batch Operations

5. 批量操作使用Webhooks

python
undefined
python
undefined

Process many images

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}" } )
undefined
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}" } )
undefined

Common Use Cases

常见使用场景

Professional Headshots

专业头像

python
undefined
python
undefined

Remove background and upscale

Remove background and upscale

headshot = remove_background(original, api_key) hd_headshot = upscale_image(headshot, api_key, scale=4)
undefined
headshot = remove_background(original, api_key) hd_headshot = upscale_image(headshot, api_key, scale=4)
undefined

Real Estate Photos

房地产图片

python
undefined
python
undefined

Remove unwanted items

Remove unwanted items

clean_room = remove_object( room_photo, "personal items and clutter", api_key )
clean_room = remove_object( room_photo, "personal items and clutter", api_key )

Extend to show more space

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 )
undefined
wider_view = extend_image( clean_room, "Continue the modern living room with more furniture", api_key, width=1920, height=1080 )
undefined

Social Media Graphics

社交媒体图形

python
undefined
python
undefined

Upscale for quality

Upscale for quality

high_res = upscale_image(graphic, api_key, scale=2)
high_res = upscale_image(graphic, api_key, scale=2)

Extend to different aspect ratios

Extend to different aspect ratios

instagram_square = extend_image( high_res, "Extend background", api_key, width=1080, height=1080 )
undefined
instagram_square = extend_image( high_res, "Extend background", api_key, width=1080, height=1080 )
undefined

Error Handling

错误处理

python
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
python
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

Resources

资源

Related Skills

相关Skill

  • modelslab-image-generation
    - Generate images to edit
  • modelslab-webhooks
    - Handle async operations
  • modelslab-sdk-usage
    - Use official SDKs
  • modelslab-image-generation
    - 生成待编辑的图片
  • modelslab-webhooks
    - 处理异步操作
  • modelslab-sdk-usage
    - 使用官方SDK