inpainting
Edit specific areas of an image by applying text prompts to mask and inpaint designated regions, enabling targeted modifications while preserving image integrity.
Instructions
Inpaint a specific part of an image using a text mask prompt.
Args:
image_path: File path of the original image
prompt: Text prompt for the area to be inpainted
mask_prompt: Text prompt for specifying the area to be masked (e.g., "window", "car")
negative_prompt: Text prompt for excluding attributes from generation
height: Output image height (pixels)
width: Output image width (pixels)
cfg_scale: Image matching degree for the prompt (1-20)
open_browser: Whether to open the image in the browser after generation
Returns:
Dict: Dictionary containing the file path of the inpainted image
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cfg_scale | No | ||
| height | No | ||
| image_path | Yes | ||
| mask_prompt | Yes | ||
| negative_prompt | No | ||
| open_browser | No | ||
| prompt | Yes | ||
| width | No |
Implementation Reference
- The main handler function for the 'inpainting' tool. It reads the input image, encodes it to base64, constructs a JSON payload with inpainting parameters for the Bedrock model, generates the image, saves it using image_storage utilities, and returns the saved image path.async def inpainting( image_path: str, prompt: str, mask_prompt: str, negative_prompt: str = "", height: int = 512, width: int = 512, cfg_scale: float = 8.0, open_browser: bool = True, output_path: str = None, ) -> Dict[str, Any]: """ Inpaint a specific part of an image using a text mask prompt. Args: image_path: File path of the original image prompt: Text prompt for the area to be inpainted mask_prompt: Text prompt for specifying the area to be masked (e.g., "window", "car") negative_prompt: Text prompt for excluding attributes from generation height: Output image height (pixels) width: Output image width (pixels) cfg_scale: Image matching degree for the prompt (1-20) open_browser: Whether to open the image in the browser after generation output_path: Absolute path to save the image Returns: Dict: Dictionary containing the file path of the inpainted image """ try: # Read image file and encode to base64 with open(image_path, "rb") as image_file: input_image = base64.b64encode(image_file.read()).decode('utf8') body = json.dumps({ "taskType": "INPAINTING", "inPaintingParams": { "text": prompt, "negativeText": negative_prompt, "image": input_image, "maskPrompt": mask_prompt }, "imageGenerationConfig": { "numberOfImages": 1, "height": height, "width": width, "cfgScale": cfg_scale } }) # Generate image image_bytes = generate_image(body) # Save image image_info = save_image(image_bytes, open_browser=open_browser, output_path=output_path) # Generate result result = { "image_path": image_info["image_path"], "message": f"Inpainting completed successfully. Saved location: {image_info['image_path']}" } return result except Exception as e: raise McpError(f"Error occurred while inpainting: {str(e)}")
- aws_nova_canvas_mcp/server.py:32-32 (registration)Location where the inpainting tool is imported and registered with the MCP server (registration is currently commented out).# mcp.add_tool(inpainting)