

Let's build a workflow that removes the foreground object from an image. The pipeline:
- Generates an image using
GenerateImage
Generate an image.
ExampleAPI ReferenceGenerateImage( prompt="hokusai futuristic supercell spiral cloud with glowing core over turbulent ocean", store="hosted", )Output{ "image_uri": "https://assets.substrate.run/84848484.jpg" } - Removes the background of the image using , creating a foreground mask
RemoveBackground
Remove the background from an image and return the foreground segment as a cut-out or a mask.
ExampleAPI ReferenceRemoveBackground( image_uri="https://media.substrate.run/apple-forest.jpeg", store="hosted", )Output{ "image_uri": "https://assets.substrate.run/84848484.jpg" } - Erase content inside the mask using
EraseImage
Erase the masked part of an image, e.g. to remove an object by inpainting.
ExampleAPI ReferenceEraseImage( image_uri="https://media.substrate.run/apple-forest.jpeg", mask_image_uri="https://media.substrate.run/apple-forest-mask.jpeg", store="hosted", )Output{ "image_uri": "https://assets.substrate.run/84848484.jpg" } - Fill in details using
InpaintImage
Edit an image using image generation inside part of the image or the full image.
ExampleAPI ReferenceInpaintImage( image_uri="https://media.substrate.run/docs-klimt-park.jpg", mask_image_uri="https://media.substrate.run/spiral-logo.jpeg", prompt="large tropical colorful bright anime birds in a dark jungle full of vines, high resolution", store="hosted", )Output{ "image_uri": "https://assets.substrate.run/84848484.jpg" }
First, initialize Substrate:
Generate an image using Generate an image.GenerateImage
Advanced image generation
- For more control over Stable Diffusion XL, use StableDiffusionXLLightning (opens in a new tab).
- Provide a seed to "pin" the initial noise in the image generation process – this can be a good way to experiment with subtle changes in your prompt.
Remove the background from the image, and turn the result into a "mask" (a black and white image). Without Remove the background from an image and return the foreground segment as a cut-out or a mask.return_mask=True
, RemoveBackground
Erase the content inside the mask using Erase the masked part of an image, e.g. to remove an object by inpainting. Edit an image using image generation inside part of the image or the full image. Edit an image using Stable Diffusion XL. Supports inpainting (edit part of the image with a mask) and image-to-image (edit the full image).EraseImage
InpaintImage
StableDiffusionXLInpaint
substrate.run
with the terminal node of the pipeline, inpaint
.
Here's a sample result from this pipeline:

res.get(image)

res.get(mask)

res.get(erase)

res.get(inpaint)