每日备份 2026-03-27
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
---
|
||||
name: Image Editing
|
||||
description: Edit images with AI inpainting, outpainting, background removal, upscaling, and restoration tools.
|
||||
metadata: {"clawdbot":{"emoji":"✂️","os":["linux","darwin","win32"]}}
|
||||
---
|
||||
|
||||
# AI Image Editing
|
||||
|
||||
Help users edit and enhance images with AI tools.
|
||||
|
||||
**Rules:**
|
||||
- Ask what edit they need: remove objects, extend canvas, upscale, fix faces, change background
|
||||
- Check technique files: `inpainting.md`, `outpainting.md`, `background-removal.md`, `upscaling.md`, `restoration.md`, `style-transfer.md`
|
||||
- Check `tools.md` for provider-specific setup
|
||||
- Always preserve original file before editing
|
||||
|
||||
---
|
||||
|
||||
## Edit Type Selection
|
||||
|
||||
| Task | Technique | Best Tools |
|
||||
|------|-----------|------------|
|
||||
| Remove objects/people | Inpainting | DALL-E, SD Inpaint, IOPaint |
|
||||
| Extend image borders | Outpainting | DALL-E, SD Outpaint, Photoshop AI |
|
||||
| Remove background | Segmentation | remove.bg, ClipDrop, Photoroom |
|
||||
| Increase resolution | Upscaling | Real-ESRGAN, Topaz, Magnific |
|
||||
| Fix blurry faces | Restoration | GFPGAN, CodeFormer |
|
||||
| Change style | Style Transfer | SD img2img, ControlNet |
|
||||
| Relight scene | Relighting | ClipDrop, IC-Light |
|
||||
|
||||
---
|
||||
|
||||
## Workflow Principles
|
||||
|
||||
- **Non-destructive editing** — keep originals, save edits as new files
|
||||
- **Work in layers** — combine multiple edits sequentially
|
||||
- **Match resolution** — edit at original resolution, upscale last
|
||||
- **Mask precision matters** — better masks = better results
|
||||
- **Iterate on masks** — refine edges for seamless blends
|
||||
|
||||
---
|
||||
|
||||
## Masking Basics
|
||||
|
||||
Masks define edit regions:
|
||||
- **White** = edit this area
|
||||
- **Black** = preserve this area
|
||||
- **Gray** = partial blend (feathering)
|
||||
|
||||
**Mask creation methods:**
|
||||
- Manual brush in editor
|
||||
- SAM (Segment Anything) for auto-selection
|
||||
- Color/luminance keying
|
||||
- Edge detection
|
||||
|
||||
---
|
||||
|
||||
## Common Workflows
|
||||
|
||||
### Object Removal
|
||||
1. Create mask over unwanted object
|
||||
2. Run inpainting with context prompt (optional)
|
||||
3. Blend edges if needed
|
||||
4. Touch up artifacts
|
||||
|
||||
### Background Replacement
|
||||
1. Remove background (get transparent PNG)
|
||||
2. Place on new background
|
||||
3. Match lighting/color
|
||||
4. Add shadows for realism
|
||||
|
||||
### Enhancement Pipeline
|
||||
1. Restore faces (if present)
|
||||
2. Remove artifacts/noise
|
||||
3. Color correct
|
||||
4. Upscale to final resolution
|
||||
|
||||
---
|
||||
|
||||
## Quality Tips
|
||||
|
||||
- **Feather masks** — hard edges look artificial
|
||||
- **Context prompts help** — describe what should fill the area
|
||||
- **Multiple passes** — large edits may need iterative refinement
|
||||
- **Check edges** — zoom in to verify blend quality
|
||||
- **Match grain/noise** — add film grain to match original
|
||||
|
||||
---
|
||||
|
||||
### Current Setup
|
||||
<!-- Tool: status -->
|
||||
|
||||
### Projects
|
||||
<!-- What they're editing -->
|
||||
|
||||
### Preferences
|
||||
<!-- Preferred tools, quality settings -->
|
||||
|
||||
---
|
||||
*Check technique files for detailed workflows.*
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ownerId": "kn73vp5rarc3b14rc7wjcw8f8580t5d1",
|
||||
"slug": "image-edit",
|
||||
"version": "1.0.0",
|
||||
"publishedAt": 1770861845569
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
# Background Removal
|
||||
|
||||
Extract subjects from images with transparent backgrounds.
|
||||
|
||||
## Tools
|
||||
|
||||
### remove.bg (API)
|
||||
|
||||
```bash
|
||||
curl -X POST "https://api.remove.bg/v1.0/removebg" \
|
||||
-H "X-Api-Key: YOUR_API_KEY" \
|
||||
-F "image_file=@photo.jpg" \
|
||||
-F "size=auto" \
|
||||
-o "result.png"
|
||||
```
|
||||
|
||||
```python
|
||||
import requests
|
||||
|
||||
response = requests.post(
|
||||
"https://api.remove.bg/v1.0/removebg",
|
||||
files={"image_file": open("photo.jpg", "rb")},
|
||||
data={"size": "auto"},
|
||||
headers={"X-Api-Key": "YOUR_API_KEY"}
|
||||
)
|
||||
with open("result.png", "wb") as f:
|
||||
f.write(response.content)
|
||||
```
|
||||
|
||||
**Pricing:** ~$0.20/image (50 free/month)
|
||||
|
||||
### ClipDrop (Stability AI)
|
||||
|
||||
```python
|
||||
import requests
|
||||
|
||||
response = requests.post(
|
||||
"https://clipdrop-api.co/remove-background/v1",
|
||||
files={"image_file": open("photo.jpg", "rb")},
|
||||
headers={"x-api-key": "YOUR_API_KEY"}
|
||||
)
|
||||
```
|
||||
|
||||
**Features:** Background removal, cleanup, relighting
|
||||
|
||||
### Photoroom API
|
||||
|
||||
```python
|
||||
response = requests.post(
|
||||
"https://sdk.photoroom.com/v1/segment",
|
||||
files={"image_file": open("photo.jpg", "rb")},
|
||||
headers={"x-api-key": "YOUR_API_KEY"}
|
||||
)
|
||||
```
|
||||
|
||||
### Local (rembg)
|
||||
|
||||
```bash
|
||||
pip install rembg
|
||||
|
||||
# CLI
|
||||
rembg i input.jpg output.png
|
||||
|
||||
# Python
|
||||
from rembg import remove
|
||||
from PIL import Image
|
||||
|
||||
output = remove(Image.open("input.jpg"))
|
||||
output.save("output.png")
|
||||
```
|
||||
|
||||
**Models:**
|
||||
- `u2net` — General purpose (default)
|
||||
- `u2net_human_seg` — Optimized for people
|
||||
- `silueta` — Faster, smaller
|
||||
|
||||
## Batch Processing
|
||||
|
||||
```python
|
||||
from rembg import remove
|
||||
from pathlib import Path
|
||||
|
||||
for img_path in Path("input/").glob("*.jpg"):
|
||||
result = remove(Image.open(img_path))
|
||||
result.save(f"output/{img_path.stem}.png")
|
||||
```
|
||||
|
||||
## Edge Refinement
|
||||
|
||||
Raw removal often has rough edges:
|
||||
|
||||
1. **Feather edges** — Gaussian blur on alpha channel
|
||||
2. **Matting models** — Use dedicated matting for hair/fur
|
||||
3. **Manual cleanup** — Touch up in photo editor
|
||||
|
||||
## Use Cases
|
||||
|
||||
- Product photography
|
||||
- Profile pictures
|
||||
- Compositing
|
||||
- E-commerce listings
|
||||
- Marketing materials
|
||||
|
||||
## Quality Tips
|
||||
|
||||
- **Good lighting** — clear subject separation helps
|
||||
- **High contrast** — distinct foreground/background
|
||||
- **Clean backgrounds** — simpler = better results
|
||||
- **Check hair/fur** — often needs manual refinement
|
||||
@@ -0,0 +1,93 @@
|
||||
# Inpainting
|
||||
|
||||
Replace or remove parts of an image using AI.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. Provide source image
|
||||
2. Create mask (white = area to change)
|
||||
3. Optionally describe replacement content
|
||||
4. AI fills masked area matching surrounding context
|
||||
|
||||
## Tools
|
||||
|
||||
### DALL-E 2 (OpenAI)
|
||||
|
||||
```python
|
||||
from openai import OpenAI
|
||||
client = OpenAI()
|
||||
|
||||
response = client.images.edit(
|
||||
model="dall-e-2",
|
||||
image=open("image.png", "rb"),
|
||||
mask=open("mask.png", "rb"),
|
||||
prompt="A sunny beach with palm trees",
|
||||
size="1024x1024"
|
||||
)
|
||||
```
|
||||
|
||||
**Requirements:**
|
||||
- Image must be square PNG
|
||||
- Mask: transparent areas = edit zone
|
||||
- Max 4MB per file
|
||||
|
||||
### Stable Diffusion Inpaint
|
||||
|
||||
```python
|
||||
from diffusers import StableDiffusionInpaintPipeline
|
||||
import torch
|
||||
|
||||
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
||||
"runwayml/stable-diffusion-inpainting",
|
||||
torch_dtype=torch.float16
|
||||
)
|
||||
pipe.to("cuda")
|
||||
|
||||
result = pipe(
|
||||
prompt="A fluffy cat",
|
||||
image=init_image,
|
||||
mask_image=mask,
|
||||
num_inference_steps=30,
|
||||
guidance_scale=7.5
|
||||
).images[0]
|
||||
```
|
||||
|
||||
**Key parameters:**
|
||||
- `strength` — How much to change (0.5-1.0)
|
||||
- `guidance_scale` — Prompt adherence (5-15)
|
||||
|
||||
### IOPaint (Local, Free)
|
||||
|
||||
```bash
|
||||
# Install
|
||||
pip install iopaint
|
||||
|
||||
# Run web UI
|
||||
iopaint start --model lama --port 8080
|
||||
```
|
||||
|
||||
**Models:**
|
||||
- `lama` — Fast, good for object removal
|
||||
- `ldm` — Better quality, slower
|
||||
- `sd` — Stable Diffusion backend
|
||||
|
||||
## Best Practices
|
||||
|
||||
- **Extend mask slightly** — cover edges of object to remove
|
||||
- **Describe surroundings** — "grassy field" helps context
|
||||
- **Multiple passes** — for large areas, edit in chunks
|
||||
- **Clean up edges** — blend modes in photo editor
|
||||
|
||||
## Object Removal (No Prompt)
|
||||
|
||||
For pure removal without replacement:
|
||||
- Use LaMa model (designed for removal)
|
||||
- Leave prompt empty or minimal
|
||||
- AI infers from surrounding context
|
||||
|
||||
## Common Issues
|
||||
|
||||
- **Visible seams** — feather mask edges
|
||||
- **Wrong content** — be more specific in prompt
|
||||
- **Repeating patterns** — edit in smaller sections
|
||||
- **Color mismatch** — adjust levels after inpainting
|
||||
@@ -0,0 +1,95 @@
|
||||
# Outpainting
|
||||
|
||||
Extend an image beyond its original borders.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. Place original image on larger canvas
|
||||
2. Mask the empty areas (white = generate here)
|
||||
3. Describe what should appear in extended areas
|
||||
4. AI generates content matching style and context
|
||||
|
||||
## Tools
|
||||
|
||||
### DALL-E 2 (OpenAI)
|
||||
|
||||
```python
|
||||
from openai import OpenAI
|
||||
from PIL import Image
|
||||
import io
|
||||
|
||||
client = OpenAI()
|
||||
|
||||
# Create extended canvas
|
||||
original = Image.open("photo.png")
|
||||
extended = Image.new("RGBA", (1024, 1024), (0, 0, 0, 0))
|
||||
extended.paste(original, (256, 256)) # Center original
|
||||
|
||||
# Create mask (transparent = edit)
|
||||
mask = Image.new("RGBA", (1024, 1024), (255, 255, 255, 255))
|
||||
mask.paste(Image.new("RGBA", original.size, (0, 0, 0, 0)), (256, 256))
|
||||
|
||||
response = client.images.edit(
|
||||
model="dall-e-2",
|
||||
image=to_bytes(extended),
|
||||
mask=to_bytes(mask),
|
||||
prompt="Continue the landscape with mountains in the distance"
|
||||
)
|
||||
```
|
||||
|
||||
### Stable Diffusion Outpaint
|
||||
|
||||
```python
|
||||
from diffusers import StableDiffusionInpaintPipeline
|
||||
|
||||
# Same as inpainting, but with extended canvas
|
||||
# Original image centered, mask covers new areas
|
||||
|
||||
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
||||
"runwayml/stable-diffusion-inpainting",
|
||||
torch_dtype=torch.float16
|
||||
)
|
||||
|
||||
result = pipe(
|
||||
prompt="expansive landscape, same style",
|
||||
image=extended_image,
|
||||
mask_image=outpaint_mask,
|
||||
num_inference_steps=50
|
||||
).images[0]
|
||||
```
|
||||
|
||||
### Photoshop Generative Fill
|
||||
|
||||
1. Select > All
|
||||
2. Image > Canvas Size (increase dimensions)
|
||||
3. Select empty areas with Magic Wand
|
||||
4. Edit > Generative Fill
|
||||
5. Enter prompt or leave blank
|
||||
|
||||
## Aspect Ratio Expansion
|
||||
|
||||
**Portrait to Landscape:**
|
||||
- Extend left and right
|
||||
- Prompt for environmental context
|
||||
|
||||
**Landscape to Portrait:**
|
||||
- Extend top and bottom
|
||||
- Consider sky above, ground below
|
||||
|
||||
**Square to Cinematic (16:9):**
|
||||
- Add 280px each side for 1080p
|
||||
- Describe scene continuation
|
||||
|
||||
## Best Practices
|
||||
|
||||
- **Overlap slightly** — let AI see edge context
|
||||
- **Match lighting direction** — describe consistent light
|
||||
- **Extend in steps** — don't 4x the canvas at once
|
||||
- **Describe style** — "same artistic style", "photorealistic"
|
||||
|
||||
## Common Issues
|
||||
|
||||
- **Style mismatch** — add style keywords to prompt
|
||||
- **Repeated elements** — AI may duplicate objects
|
||||
- **Perspective errors** — complex scenes may warp
|
||||
- **Seam lines** — blend with photo editor after
|
||||
@@ -0,0 +1,148 @@
|
||||
# Image Restoration
|
||||
|
||||
Fix damaged, blurry, or degraded images with AI.
|
||||
|
||||
## Face Restoration
|
||||
|
||||
### GFPGAN
|
||||
|
||||
```bash
|
||||
pip install gfpgan
|
||||
|
||||
# CLI
|
||||
python inference_gfpgan.py -i inputs/ -o results/ -v 1.4 -s 2
|
||||
```
|
||||
|
||||
```python
|
||||
from gfpgan import GFPGANer
|
||||
|
||||
restorer = GFPGANer(
|
||||
model_path="GFPGANv1.4.pth",
|
||||
upscale=2,
|
||||
arch="clean",
|
||||
channel_multiplier=2
|
||||
)
|
||||
|
||||
_, _, output = restorer.enhance(
|
||||
input_img,
|
||||
has_aligned=False,
|
||||
only_center_face=False,
|
||||
paste_back=True
|
||||
)
|
||||
```
|
||||
|
||||
### CodeFormer
|
||||
|
||||
```python
|
||||
from codeformer import CodeFormer
|
||||
|
||||
model = CodeFormer()
|
||||
result = model.restore(
|
||||
image,
|
||||
fidelity=0.5 # 0=quality, 1=fidelity to original
|
||||
)
|
||||
```
|
||||
|
||||
**Fidelity slider:**
|
||||
- Low (0.1-0.3) — more enhancement, may change face
|
||||
- High (0.7-0.9) — preserves original, less enhancement
|
||||
|
||||
### Replicate
|
||||
|
||||
```python
|
||||
import replicate
|
||||
|
||||
output = replicate.run(
|
||||
"tencentarc/gfpgan:9283608cc6b7be6b65a8e44983db012355fde4132009bf99d976b2f0896856a3",
|
||||
input={"img": open("face.jpg", "rb"), "scale": 2}
|
||||
)
|
||||
```
|
||||
|
||||
## Old Photo Restoration
|
||||
|
||||
### Bringing Old Photos Back to Life
|
||||
|
||||
```python
|
||||
import replicate
|
||||
|
||||
output = replicate.run(
|
||||
"microsoft/bringing-old-photos-back-to-life:c75db81db6cbd809d93b27b0f3e88a4c88aec3ed9be33b8c0f7f0c98d14f1d34",
|
||||
input={
|
||||
"image": open("old_photo.jpg", "rb"),
|
||||
"with_scratch": True
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
**Features:**
|
||||
- Scratch removal
|
||||
- Face restoration
|
||||
- Color enhancement
|
||||
|
||||
## Denoising
|
||||
|
||||
### Real-ESRGAN Denoise
|
||||
|
||||
```python
|
||||
from realesrgan import RealESRGAN
|
||||
|
||||
model = RealESRGAN(device, scale=1) # scale=1 for denoise only
|
||||
model.load_weights("realesr-general-x4v3.pth")
|
||||
```
|
||||
|
||||
### OpenCV Denoising
|
||||
|
||||
```python
|
||||
import cv2
|
||||
|
||||
# For color images
|
||||
denoised = cv2.fastNlMeansDenoisingColored(
|
||||
image,
|
||||
None,
|
||||
h=10, # Filter strength
|
||||
hForColorComponents=10,
|
||||
templateWindowSize=7,
|
||||
searchWindowSize=21
|
||||
)
|
||||
```
|
||||
|
||||
## Colorization
|
||||
|
||||
### DeOldify
|
||||
|
||||
```python
|
||||
from deoldify import device
|
||||
from deoldify.visualize import get_image_colorizer
|
||||
|
||||
colorizer = get_image_colorizer(artistic=True)
|
||||
result = colorizer.get_transformed_image(
|
||||
"bw_photo.jpg",
|
||||
render_factor=35
|
||||
)
|
||||
```
|
||||
|
||||
### Replicate
|
||||
|
||||
```python
|
||||
output = replicate.run(
|
||||
"arielreplicate/deoldify_image:0da600fab0c45a66211339f1c16b71345d22f26ef5fea3dca1bb90bb5711e950",
|
||||
input={"input_image": open("bw.jpg", "rb")}
|
||||
)
|
||||
```
|
||||
|
||||
## Restoration Pipeline
|
||||
|
||||
1. **Remove scratches/damage** — Old Photos model
|
||||
2. **Denoise** — if grainy
|
||||
3. **Restore faces** — GFPGAN/CodeFormer
|
||||
4. **Colorize** — if B&W
|
||||
5. **Upscale** — to final resolution
|
||||
6. **Sharpen** — light enhancement
|
||||
|
||||
## Quality Tips
|
||||
|
||||
- **Preserve original** — always keep unedited copy
|
||||
- **Gradual enhancement** — don't over-process
|
||||
- **Check faces** — restoration can change features
|
||||
- **Manual touchup** — AI may miss spots
|
||||
- **Add grain** — restored images can look too clean
|
||||
@@ -0,0 +1,114 @@
|
||||
# Style Transfer
|
||||
|
||||
Transform image style while preserving content.
|
||||
|
||||
## Techniques
|
||||
|
||||
### img2img (Stable Diffusion)
|
||||
|
||||
```python
|
||||
from diffusers import StableDiffusionImg2ImgPipeline
|
||||
import torch
|
||||
|
||||
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
||||
"runwayml/stable-diffusion-v1-5",
|
||||
torch_dtype=torch.float16
|
||||
)
|
||||
pipe.to("cuda")
|
||||
|
||||
result = pipe(
|
||||
prompt="oil painting style, impressionist",
|
||||
image=init_image,
|
||||
strength=0.6, # 0=no change, 1=full generation
|
||||
guidance_scale=7.5
|
||||
).images[0]
|
||||
```
|
||||
|
||||
**Strength parameter:**
|
||||
- 0.3-0.4 — Light style, preserves most detail
|
||||
- 0.5-0.6 — Balanced transformation
|
||||
- 0.7-0.8 — Heavy restyle, may lose detail
|
||||
|
||||
### ControlNet
|
||||
|
||||
```python
|
||||
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
|
||||
|
||||
controlnet = ControlNetModel.from_pretrained(
|
||||
"lllyasviel/sd-controlnet-canny",
|
||||
torch_dtype=torch.float16
|
||||
)
|
||||
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
||||
"runwayml/stable-diffusion-v1-5",
|
||||
controlnet=controlnet,
|
||||
torch_dtype=torch.float16
|
||||
)
|
||||
|
||||
# Extract edges for structure guidance
|
||||
import cv2
|
||||
canny = cv2.Canny(image, 100, 200)
|
||||
|
||||
result = pipe(
|
||||
prompt="anime style illustration",
|
||||
image=canny,
|
||||
num_inference_steps=30
|
||||
).images[0]
|
||||
```
|
||||
|
||||
**ControlNet modes:**
|
||||
- `canny` — Edge detection
|
||||
- `depth` — Depth map
|
||||
- `pose` — Human pose
|
||||
- `lineart` — Line drawing
|
||||
|
||||
### IP-Adapter (Style Reference)
|
||||
|
||||
```python
|
||||
from diffusers import StableDiffusionPipeline
|
||||
from transformers import CLIPVisionModelWithProjection
|
||||
|
||||
# Use reference image as style guide
|
||||
pipe.load_ip_adapter("h94/IP-Adapter", subfolder="models")
|
||||
pipe.set_ip_adapter_scale(0.6)
|
||||
|
||||
result = pipe(
|
||||
prompt="a portrait",
|
||||
ip_adapter_image=style_reference, # Your style image
|
||||
image=content_image
|
||||
).images[0]
|
||||
```
|
||||
|
||||
## Style Types
|
||||
|
||||
| Style | Prompt Keywords |
|
||||
|-------|-----------------|
|
||||
| Oil painting | oil painting, brushstrokes, impasto |
|
||||
| Watercolor | watercolor, soft edges, wet medium |
|
||||
| Anime | anime style, cel shaded, studio ghibli |
|
||||
| Pencil sketch | pencil drawing, graphite, sketch |
|
||||
| 3D render | 3D render, octane, blender |
|
||||
| Pixel art | pixel art, 8-bit, retro |
|
||||
| Photorealistic | hyperrealistic, photography, DSLR |
|
||||
|
||||
## Workflow
|
||||
|
||||
1. **Choose technique** based on control needed
|
||||
2. **Start with low strength** (0.3-0.4)
|
||||
3. **Iterate** — adjust strength and prompt
|
||||
4. **ControlNet** for precise structure preservation
|
||||
5. **Post-process** — color match to original if needed
|
||||
|
||||
## Best Practices
|
||||
|
||||
- **Lower strength = more original** — start low
|
||||
- **ControlNet for precision** — when structure matters
|
||||
- **Style reference images** — IP-Adapter for specific styles
|
||||
- **Consistent results** — lock seed, batch variations
|
||||
- **Resolution** — match input resolution
|
||||
|
||||
## Common Issues
|
||||
|
||||
- **Lost detail** — reduce strength
|
||||
- **Wrong style** — add more specific keywords
|
||||
- **Artifacts** — increase steps, reduce guidance
|
||||
- **Color shift** — color correct after
|
||||
@@ -0,0 +1,133 @@
|
||||
# Image Editing Tools
|
||||
|
||||
Provider setup and API reference.
|
||||
|
||||
## Cloud APIs
|
||||
|
||||
### OpenAI (DALL-E 2)
|
||||
|
||||
```python
|
||||
from openai import OpenAI
|
||||
client = OpenAI() # OPENAI_API_KEY env var
|
||||
|
||||
# Edit/Inpaint
|
||||
response = client.images.edit(
|
||||
model="dall-e-2",
|
||||
image=open("image.png", "rb"),
|
||||
mask=open("mask.png", "rb"),
|
||||
prompt="description",
|
||||
size="1024x1024"
|
||||
)
|
||||
```
|
||||
|
||||
**Pricing:** $0.020/image (1024x1024)
|
||||
|
||||
### Stability AI
|
||||
|
||||
```python
|
||||
import requests
|
||||
|
||||
response = requests.post(
|
||||
"https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image",
|
||||
headers={"Authorization": f"Bearer {API_KEY}"},
|
||||
files={"init_image": open("image.png", "rb")},
|
||||
data={
|
||||
"text_prompts[0][text]": "description",
|
||||
"init_image_mode": "IMAGE_STRENGTH",
|
||||
"image_strength": 0.35
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
### ClipDrop
|
||||
|
||||
```python
|
||||
import requests
|
||||
|
||||
# Background removal
|
||||
response = requests.post(
|
||||
"https://clipdrop-api.co/remove-background/v1",
|
||||
headers={"x-api-key": API_KEY},
|
||||
files={"image_file": open("photo.jpg", "rb")}
|
||||
)
|
||||
|
||||
# Cleanup (remove objects)
|
||||
response = requests.post(
|
||||
"https://clipdrop-api.co/cleanup/v1",
|
||||
headers={"x-api-key": API_KEY},
|
||||
files={
|
||||
"image_file": open("photo.jpg", "rb"),
|
||||
"mask_file": open("mask.png", "rb")
|
||||
}
|
||||
)
|
||||
|
||||
# Relight
|
||||
response = requests.post(
|
||||
"https://clipdrop-api.co/relight/v1",
|
||||
headers={"x-api-key": API_KEY},
|
||||
files={"image_file": open("photo.jpg", "rb")},
|
||||
data={"mode": "sunrise"}
|
||||
)
|
||||
```
|
||||
|
||||
### remove.bg
|
||||
|
||||
```python
|
||||
response = requests.post(
|
||||
"https://api.remove.bg/v1.0/removebg",
|
||||
headers={"X-Api-Key": API_KEY},
|
||||
files={"image_file": open("photo.jpg", "rb")},
|
||||
data={"size": "auto"}
|
||||
)
|
||||
```
|
||||
|
||||
## Local Tools
|
||||
|
||||
### IOPaint
|
||||
|
||||
```bash
|
||||
pip install iopaint
|
||||
iopaint start --model lama --port 8080
|
||||
```
|
||||
|
||||
Access web UI at http://localhost:8080
|
||||
|
||||
### rembg
|
||||
|
||||
```bash
|
||||
pip install rembg[gpu] # or rembg for CPU
|
||||
rembg i input.jpg output.png
|
||||
```
|
||||
|
||||
### Real-ESRGAN
|
||||
|
||||
```bash
|
||||
pip install realesrgan
|
||||
realesrgan-ncnn-vulkan -i input.jpg -o output.png
|
||||
```
|
||||
|
||||
### GFPGAN
|
||||
|
||||
```bash
|
||||
pip install gfpgan
|
||||
python inference_gfpgan.py -i inputs/ -o results/
|
||||
```
|
||||
|
||||
## Desktop Apps
|
||||
|
||||
| App | Features | Price |
|
||||
|-----|----------|-------|
|
||||
| Photoshop | Generative Fill, everything | $23/mo |
|
||||
| Topaz Photo AI | Upscale, denoise, sharpen | $199 |
|
||||
| Affinity Photo | Manual editing, AI plugins | $70 |
|
||||
| GIMP + plugins | Free, extensible | Free |
|
||||
|
||||
## Comparison
|
||||
|
||||
| Task | Best Free | Best Paid |
|
||||
|------|-----------|-----------|
|
||||
| Inpainting | IOPaint | Photoshop |
|
||||
| Background removal | rembg | remove.bg |
|
||||
| Upscaling | Real-ESRGAN | Topaz |
|
||||
| Face restoration | GFPGAN | — |
|
||||
| All-in-one | ComfyUI | Photoshop |
|
||||
@@ -0,0 +1,108 @@
|
||||
# Upscaling
|
||||
|
||||
Increase image resolution with AI enhancement.
|
||||
|
||||
## Tools
|
||||
|
||||
### Real-ESRGAN (Local, Free)
|
||||
|
||||
```bash
|
||||
# Install
|
||||
pip install realesrgan
|
||||
|
||||
# CLI
|
||||
realesrgan-ncnn-vulkan -i input.jpg -o output.png -n realesrgan-x4plus
|
||||
```
|
||||
|
||||
```python
|
||||
from realesrgan import RealESRGAN
|
||||
import torch
|
||||
|
||||
model = RealESRGAN(torch.device("cuda"), scale=4)
|
||||
model.load_weights("weights/RealESRGAN_x4plus.pth")
|
||||
|
||||
result = model.predict(input_image)
|
||||
```
|
||||
|
||||
**Models:**
|
||||
- `realesrgan-x4plus` — General images (4x)
|
||||
- `realesrgan-x4plus-anime` — Anime/illustrations
|
||||
- `realesr-general-x4v3` — Latest general model
|
||||
|
||||
### Topaz Gigapixel AI
|
||||
|
||||
Commercial desktop app:
|
||||
- Up to 6x upscale
|
||||
- Face recovery built-in
|
||||
- Batch processing
|
||||
- ~$99 one-time
|
||||
|
||||
### Magnific AI
|
||||
|
||||
```bash
|
||||
curl -X POST "https://api.magnific.ai/v1/upscale" \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-F "image=@photo.jpg" \
|
||||
-F "scale=2"
|
||||
```
|
||||
|
||||
**Features:**
|
||||
- "Creativity" slider adds AI detail
|
||||
- Best for artistic enhancement
|
||||
- ~$0.50/image
|
||||
|
||||
### Replicate (Various Models)
|
||||
|
||||
```python
|
||||
import replicate
|
||||
|
||||
output = replicate.run(
|
||||
"nightmareai/real-esrgan:42fed1c4974146d4d2414e2be2c5277c7fcf05fcc3a73abf41610695738c1d7b",
|
||||
input={
|
||||
"image": open("photo.jpg", "rb"),
|
||||
"scale": 4,
|
||||
"face_enhance": True
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
## Scale Factors
|
||||
|
||||
| Original | 2x | 4x | 8x |
|
||||
|----------|-----|-----|-----|
|
||||
| 512x512 | 1024 | 2048 | 4096 |
|
||||
| 1080p | 4K | 8K | — |
|
||||
| 720p | 1440p | 4K | 8K |
|
||||
|
||||
**Rule:** Don't upscale beyond 4x in one pass for best quality.
|
||||
|
||||
## When to Upscale
|
||||
|
||||
- **Print production** — need 300 DPI
|
||||
- **Large displays** — billboards, banners
|
||||
- **Old photos** — restore low-res originals
|
||||
- **AI-generated images** — increase from 1024px
|
||||
|
||||
## Pipeline Order
|
||||
|
||||
1. **Restore faces first** — GFPGAN/CodeFormer
|
||||
2. **Remove artifacts** — denoise if needed
|
||||
3. **Upscale** — Real-ESRGAN or similar
|
||||
4. **Sharpen** — light unsharp mask if soft
|
||||
|
||||
## Quality Tips
|
||||
|
||||
- **Don't over-upscale** — 4x max in one pass
|
||||
- **Match model to content** — anime model for anime
|
||||
- **Face enhance** — enable for portraits
|
||||
- **Check artifacts** — AI can add weird textures
|
||||
- **Preserve grain** — add back film grain if needed
|
||||
|
||||
## Comparison
|
||||
|
||||
| Tool | Scale | Speed | Quality | Cost |
|
||||
|------|-------|-------|---------|------|
|
||||
| Real-ESRGAN | 4x | Fast | Good | Free |
|
||||
| Topaz | 6x | Medium | Excellent | $99 |
|
||||
| Magnific | 2-4x | Medium | Best (creative) | $$$ |
|
||||
| Replicate | Varies | Fast | Good | Per-use |
|
||||
Reference in New Issue
Block a user