Skip to main content

Masking

Generates images with masked inpainting - selectively regenerates specific areas of an image while preserving the rest.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Connection Id - The connection ID from the Connect node (optional if API Key is provided directly).
  • Image Save Path - Directory path where generated images will be saved. Images are automatically named as img2img_masking_0.png, img2img_masking_1.png, etc.
  • Init Image Path - Path to the source image for inpainting. This is the base image that will be partially regenerated.
  • Engine Id - Stability AI engine ID for inpainting (e.g., stable-inpainting-512-v2-0). Must be an inpainting-capable engine.
  • Prompt - Text description of what to generate in the masked area. Describes the content that should replace the masked region.

Options

Authentication

  • API Key - Stability AI API key (optional if using Connection ID). You can provide the API key directly instead of using a Connect node.

Generation Settings

  • Cfg Scale - How strictly the diffusion process adheres to the prompt (default: 7). Range: 1-35. Higher values follow the prompt more closely.
  • Samples - Number of images to generate (1-10, default: 1). Generates multiple inpainting variations.
  • Seed - Random noise seed (default: 0 for random). Use specific values for reproducible results.
  • Steps - Number of diffusion steps to run (10-150, default: 50). More steps = better quality but slower generation.

Mask Settings

  • Mask Source - Source for the mask defining areas to inpaint:

    • MASK_IMAGE_WHITE - Separate mask image where white areas are inpainted (default)
    • MASK_IMAGE_BLACK - Separate mask image where black areas are inpainted
    • INIT_IMAGE_ALPHA - Use alpha channel of init image (transparent areas are inpainted)
  • Mask Image Path - Path to mask image file (required for MASK_IMAGE_WHITE and MASK_IMAGE_BLACK modes). Must have same dimensions as init image.

Advanced Settings

  • Clip Guidance Preset - CLIP guidance preset for image generation quality:

    • NONE - No CLIP guidance (default)
    • FAST_BLUE, FAST_GREEN, SIMPLE, SLOW, SLOWER, SLOWEST
  • Sampler - Sampling algorithm used for diffusion process:

    • NONE - Use engine default (recommended)
    • DDIM, DDPM, K_DPMPP_2M, K_DPMPP_2S_ANCESTRAL, K_DPM_2, K_DPM_2_ANCESTRAL, K_EULER, K_EULER_ANCESTRAL, K_HEUN, K_LMS
  • Style Preset - Style preset to guide the image generation:

    • NONE - No style preset (default)
    • 3d-model, analog-film, anime, cinematic, comic-book, digital-art, enhance, fantasy-art, isometric, line-art, low-poly, modeling-compound, neon-punk, origami, photographic, pixel-art, tile-texture

How It Works

The Masking node performs selective image regeneration (inpainting) on specific areas. When executed, the node:

  1. Validates the connection or creates a temporary client using provided credentials
  2. Validates the prompt, engine ID, init image path, and save path
  3. Determines the mask source and reads required files:
    • For MASK_IMAGE_WHITE/BLACK: Reads both init image and mask image
    • For INIT_IMAGE_ALPHA: Reads init image with alpha channel
  4. Constructs the multipart request with:
    • Init image data
    • Mask image data (if applicable)
    • Mask source mode
    • Prompt for masked area
    • Generation parameters
  5. Sends the request to Stability AI inpainting endpoint
  6. Receives base64-encoded images with inpainted regions
  7. Saves images to the specified directory
  8. Images are named sequentially: img2img_masking_0.png, img2img_masking_1.png, etc.

Requirements

  • Either a valid Connection Id from Connect node OR direct API Key credentials
  • Non-empty Prompt
  • Valid Init Image Path (file must exist)
  • Valid Engine Id (must be an inpainting-capable engine like stable-inpainting-512-v2-0)
  • Valid Image Save Path (directory must exist)
  • For MASK_IMAGE_WHITE/BLACK modes: Valid Mask Image Path
  • Mask image must have same dimensions as init image
  • Sufficient Stability AI credits for inpainting

Error Handling

The node will return specific errors in the following cases:

  • Empty or missing Prompt
  • Empty or missing Engine Id
  • Empty or missing Init Image Path
  • Empty or missing Image Save Path
  • Empty or missing Mask Image Path (when using MASK_IMAGE_WHITE/BLACK)
  • Invalid Connection Id (when not using direct credentials)
  • Init image file not found
  • Mask image file not found
  • Dimension mismatch between init and mask images
  • Cfg Scale, Samples, Seed, or Steps not valid integers
  • Samples outside range of 1-10
  • Steps outside range of 10-150
  • API authentication errors (401)
  • Insufficient credits (402)
  • API rate limit errors (429)
  • API service errors (500, 503)

Usage Notes

Understanding Inpainting

  • Inpainting fills in or replaces specific areas of an image
  • Masked areas are regenerated based on the prompt
  • Unmasked areas remain unchanged
  • The AI considers surrounding context for seamless blending

Mask Modes Explained

  • MASK_IMAGE_WHITE: Create a separate mask image where white = inpaint this area
  • MASK_IMAGE_BLACK: Create a separate mask image where black = inpaint this area
  • INIT_IMAGE_ALPHA: Use PNG with transparency, transparent = inpaint this area

Creating Mask Images

  • Mask image must be same size as init image
  • Use image editing software (Photoshop, GIMP, Paint.NET)
  • For MASK_IMAGE_WHITE: Paint white on black background for areas to inpaint
  • For MASK_IMAGE_BLACK: Paint black on white background for areas to inpaint
  • Soft edges in mask create smoother blending
  • Sharp edges in mask create crisp boundaries

Inpainting Engines

  • Common inpainting engine: stable-inpainting-512-v2-0
  • Specialized for 512x512 images
  • Check available engines with GetEnginesList node
  • Not all engines support inpainting

Examples

Example 1: Remove Object from Photo

Inputs:

  • Connection Id: (from Connect node)
  • Image Save Path: "/path/to/output"
  • Init Image Path: "/path/to/photo_with_object.jpg"
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "Empty space, natural background, seamless continuation"

Options:

  • Mask Source: MASK_IMAGE_WHITE
  • Mask Image Path: "/path/to/mask_white.png" (white over object to remove)
  • Steps: 50
  • Cfg Scale: 7

Use Case: Remove unwanted objects from photos (people, signs, clutter)


Example 2: Add Object to Scene

Inputs:

  • Connection Id: (from Connect node)
  • Image Save Path: "/path/to/output"
  • Init Image Path: "/path/to/room.jpg"
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "Modern red sofa, comfortable furniture, contemporary design"

Options:

  • Mask Source: MASK_IMAGE_WHITE
  • Mask Image Path: "/path/to/mask_sofa_area.png"
  • Steps: 50
  • Style Preset: photographic

Use Case: Add furniture or objects to empty spaces


Example 3: Face Replacement/Editing

Inputs:

  • Connection Id: (from Connect node)
  • Image Save Path: "/path/to/output"
  • Init Image Path: "/path/to/portrait.jpg"
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "Smiling face, happy expression, natural lighting"

Options:

  • Mask Source: MASK_IMAGE_WHITE
  • Mask Image Path: "/path/to/face_mask.png" (white over face area)
  • Steps: 50
  • Samples: 3

Use Case: Modify facial expressions or features


Example 4: Using Alpha Channel

Inputs:

  • Connection Id: (from Connect node)
  • Image Save Path: "/path/to/output"
  • Init Image Path: "/path/to/image_with_transparency.png"
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "Detailed texture, high quality fill"

Options:

  • Mask Source: INIT_IMAGE_ALPHA
  • Steps: 40

Use Case: Fill transparent areas in PNG images


Example 5: RPA Use Case - Product Photo Cleanup

Flow:

Read product photos with defects
→ Create mask programmatically (detect defects)
→ Masking (remove defects)
→ Quality check
→ Upload cleaned photos

Inputs:

  • Init Image Path: msg.productPhoto
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "Clean product surface, flawless appearance, professional photography"
  • Mask Image Path: msg.defectMask

Options:

  • Mask Source: MASK_IMAGE_WHITE
  • Steps: 50
  • Style Preset: photographic

Use Case: Automatically clean up product photography defects, scratches, or blemishes


Example 6: RPA Use Case - Background Replacement

Flow:

Extract products with background removal tool
→ Create mask for background area
→ Masking (generate new background)
→ Save with multiple background variants

Inputs:

  • Init Image Path: "/temp/product_foreground.png"
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "White studio background, professional product photography background"
  • Mask Image Path: "/temp/background_mask.png"

Options:

  • Mask Source: MASK_IMAGE_WHITE
  • Steps: 40
  • Samples: 3
  • Style Preset: photographic

Use Case: Generate multiple background variants for product photos


Example 7: RPA Use Case - Real Estate Photo Enhancement

Flow:

Read property photos
→ Detect problematic areas (old fixtures, damage)
→ Generate masks for problem areas
→ Masking (replace with modern/clean elements)
→ Save enhanced photos

Inputs:

  • Init Image Path: msg.propertyPhoto
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "Modern updated fixture, clean new appearance, professional real estate photography"
  • Mask Image Path: msg.fixtureMask

Options:

  • Mask Source: MASK_IMAGE_WHITE
  • Steps: 50

Use Case: Enhance real estate photos by updating dated fixtures or repairing damage


Example 8: RPA Use Case - Batch Watermark Removal

Flow:

Read images with watermarks
→ Detect watermark positions
→ Create masks programmatically
→ Masking (remove watermarks)
→ Save cleaned images

Inputs:

  • Init Image Path: msg.imagePath
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "Natural background continuation, seamless image area"
  • Mask Image Path: msg.watermarkMask

Options:

  • Mask Source: MASK_IMAGE_WHITE
  • Steps: 50
  • Samples: 2

Use Case: Remove watermarks from batch of images (ensure you have legal rights to do so)


Example 9: Artistic Editing

Inputs:

  • Connection Id: (from Connect node)
  • Image Save Path: "/path/to/output"
  • Init Image Path: "/path/to/landscape.jpg"
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "Dramatic sunset sky, vibrant orange and pink colors, beautiful clouds"

Options:

  • Mask Source: MASK_IMAGE_WHITE
  • Mask Image Path: "/path/to/sky_mask.png" (white over sky area)
  • Steps: 50
  • Style Preset: cinematic

Use Case: Replace sky in landscape photos with more dramatic version


Example 10: Multiple Area Inpainting

Inputs:

  • Connection Id: (from Connect node)
  • Image Save Path: "/path/to/output"
  • Init Image Path: "/path/to/scene.jpg"
  • Engine Id: "stable-inpainting-512-v2-0"
  • Prompt: "Lush green grass, healthy lawn, well-maintained garden"

Options:

  • Mask Source: MASK_IMAGE_WHITE
  • Mask Image Path: "/path/to/multiple_areas_mask.png" (white over multiple lawn sections)
  • Steps: 50
  • Samples: 3

Use Case: Inpaint multiple disconnected areas with single prompt

Best Practices

  1. Mask Creation:

    • Make masks slightly larger than target area for better blending
    • Use soft/feathered edges for natural transitions
    • Use hard edges when you want crisp boundaries
    • Ensure mask is exactly same dimensions as init image
  2. Prompt Writing:

    • Describe what should be in masked area, not what to remove
    • Include context from surrounding image
    • Be specific about style and lighting to match original
    • Consider surrounding elements for seamless integration
  3. Engine Selection:

    • Use specialized inpainting engines (e.g., stable-inpainting-512-v2-0)
    • Check engine compatibility with GetEnginesList
    • Match image size to engine capabilities (512x512 for most inpainting engines)
  4. Quality Optimization:

    • Use 40-50 steps for good quality
    • Generate multiple samples to choose best result
    • Higher Cfg Scale (10-15) for more accurate prompt following
    • Lower Cfg Scale (5-7) for more natural blending
  5. Mask Mode Selection:

    • MASK_IMAGE_WHITE: Most common, intuitive (white = paint here)
    • MASK_IMAGE_BLACK: Use when working with inverted masks
    • INIT_IMAGE_ALPHA: Convenient when you already have transparency
  6. Error Prevention:

    • Validate image dimensions match before processing
    • Test mask on single image before batch processing
    • Ensure mask file paths are correct
    • Check engine ID is valid inpainting engine
  7. Batch Processing:

    • Standardize image and mask dimensions
    • Use consistent naming conventions
    • Implement quality checks after inpainting
    • Log successful and failed operations

Tips for RPA Developers

  • Programmatic Mask Generation: Use image processing libraries to create masks automatically
  • Defect Detection: Combine with image analysis to detect areas needing inpainting
  • Quality Assurance: Implement automated checks to verify inpainting quality
  • Fallback Strategy: Have backup masks or prompts for common scenarios
  • Mask Library: Build reusable mask templates for common use cases
  • A/B Testing: Generate multiple samples and select best automatically or manually
  • Dimension Validation: Always check image dimensions before processing
  • File Management: Organize masks and init images with clear naming conventions

Common Errors and Solutions

Error: "Mask Image Path cannot be empty"

  • Solution: Provide mask image path when using MASK_IMAGE_WHITE or MASK_IMAGE_BLACK mode

Error: "Init image file not found"

  • Solution: Verify init image path is correct and file exists

Error: Dimension mismatch

  • Solution: Ensure mask image has exact same dimensions as init image

Error: "Engine ID cannot be empty"

  • Solution: Provide valid inpainting engine ID (e.g., stable-inpainting-512-v2-0)

Poor inpainting results:

  • Solution: Refine prompt to better describe desired content
  • Solution: Adjust Cfg Scale (try 10-15)
  • Solution: Increase steps to 50-75
  • Solution: Generate multiple samples and select best