Pixel-precise area selection and AI-powered inpainting — replace specific zones in interior images with generated content or real product photos.
Two-stage pipeline:
Python API: /api/segment/* (sam_routes.py)
Frontend: RegionEditCanvas.tsx for user mask painting
Model: meta/sam-2
Takes an image and zone hints (bounding boxes or click points) and returns a binary PNG mask where:
When SAM 2 is unavailable or for speed-critical paths, a Pillow-based fallback generates approximate rectangular or elliptical masks. Instant, zero cost.
Model: ali-vilab/anydoor via Replicate
When reference_image_url is provided, AnyDoor places the real product photo into the masked zone, adapting lighting and perspective. Use this to visualize how a specific tile, fabric, or material looks in the room.
When no reference image is provided, FLUX Fill Pro generates content based on the text prompt. Use this to replace a floor with "herringbone oak parquet" or a wall with "rough concrete texture".
The generate-region-edit edge function provides the end-to-end masked inpainting experience:
POST /functions/v1/generate-region-edit
Authorization: Bearer <jwt>
Content-Type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
image_url |
string | Yes | Public URL of the room image to edit |
mask_data_url |
string | Yes | PNG data URL of the binary mask (white = regenerate) |
prompt |
string | Yes | Text description of what to place in the masked area |
workspace_id |
string | No | Workspace ID for credit deduction |
user_id |
string | No | Required for server-to-server calls |
Credits: 20 per call (Grok Aurora inpainting)
Model: Grok Aurora (/v1/images/edits endpoint) for mask-guided inpainting.
{
"success": true,
"image_url": "https://bgbavxtjlbvgplozizxu.supabase.co/storage/v1/object/public/generation-images/region-edit/job-uuid.jpg",
"credits_used": 20
}
POST /api/segment/mask
{
"image_url": "https://...",
"zone_hints": [
{ "type": "bbox", "x": 100, "y": 200, "width": 300, "height": 150 }
],
"fallback": false
}
{
"mask_data_url": "data:image/png;base64,...",
"method": "sam2",
"processing_ms": 2400
}
POST /api/segment/inpaint
{
"image_url": "https://...",
"mask_data_url": "data:image/png;base64,...",
"prompt": "Herringbone oak parquet flooring",
"reference_image_url": "https://..." // optional — triggers AnyDoor
}
RegionEditCanvas.tsx provides:
image_url + mask_data_url + prompt to generate-region-editAccessed via GeminiEditModal.tsx in the Designer.
Inpainting results are stored at:
generation-images/region-edit/{job-uuid}.{jpg|png}
Last Updated: March 2026