Before you start
- Source image: The image whose foreground should be segmented. Keep this same original available if a later composite must retain its pixels.
Start with the image you want to protect
Start in Generate a background-removal mask, version 0.1.2, with your source image. Its useful result is a separate mask exposed as output:20, with the role MaskPreview. It is not an edited image or a transparent cutout.
Keep the original image alongside the mask. An existing downstream flow may use the mask to choose an edit region or combine image layers, but the selected recipe stops at mask extraction and preview. No downstream connection is established by this guide.
Extract and inspect the foreground mask
The graph sends image output slot 0 from 17 / LoadImage to the image input of 24 / RemoveBackground. 25 / LoadBackgroundRemovalModel supplies its model output to bg_removal_model. RemoveBackground calls the model's encode_image(image) and returns the named mask output; slot 0 feeds 20 / MaskPreview through its mask input.
The model selects foreground coverage rather than returning original RGB pixels. The retained source describes a foreground mask but does not establish its numerical polarity, edge accuracy or dimensions for every input. Inspect these before handing the mask to another flow. The required model component is unresolved in the preparation record, so the default filename is not evidence that the model is installed.
- Choose your source image in node 17 / LoadImage, replacing the saved example the_lily_veil.png. Keep the same original image for any later preservation composite.
Look for: Node 24 receives the chosen image through its existing image connection. The retained graph stores the image selector as a widget, without an exposed input name.
- Set bg_removal_name on node 25 / LoadBackgroundRemovalModel to birefnet.safetensors. Confirm that this file is available in the background_removal model category before running the recipe.
Look for: The loader supplies bg_model to node 24's bg_removal_model input if the selected file is present and valid.
- Run the recipe and inspect node 20 / MaskPreview and output:20 against the source image. Check subject coverage, background leakage and boundary alignment; determine which mask values cover foreground before downstream use.
Look for: A separate mask is available through the declared mask output. Inspection establishes whether it is suitable for the intended region; foreground polarity is not numerically specified by the retained extraction source.
Outputs: output:20
- Background-removal model: birefnet.safetensors
- Selects the model used to generate the foreground mask. The loader resolves the file from background_removal; an invalid model raises an error. The selected graph exposes no threshold, feathering or inversion control.
Match polarity to the downstream operation
Use output:20 only through a mask input and connection method supported by your existing flow. This recipe declares an output port but no downstream input port, adaptation or supported binding action, so there is no executable handoff to specify here.
For an image edit, first determine whether the receiving mask marks pixels to change or pixels to protect. To replace a background while keeping the subject, those conventions require opposite polarity. The retained pack contains no implementation of an edit-mask consumer, so its behavior must be established in that flow.
For the pinned ImageCompositeMasked implementation, mask value 0 selects destination pixels and 1 selects source pixels; intermediate values blend them. With the original image as destination and an edited image as source, protecting the subject requires zero over the subject. If your extracted foreground has high values over the subject, it needs inversion for that arrangement. Inversion is not a control in this recipe.
For a transparent cutout in an existing JoinImageWithAlpha flow, the pinned implementation uses opacity 1 - resized alpha and concatenates it with the input image's first three channels. Its alpha input therefore uses zero for opaque regions and one for transparent regions. A high-valued foreground mask needs inversion to keep the foreground opaque. This node retains input RGB at that stage, but it is absent from the selected recipe.
What should the existing downstream flow produce?
- An edited region: Establish the receiving edit mask's change-versus-protect convention. Supplying segmentation alone does not establish pixel preservation.Continue
- A composite retaining the original subject: For the pinned masked composite, use original destination pixels where the aligned mask is zero.Continue
- A transparent cutout: For the pinned alpha join, provide zero over opaque subject regions. It appends opacity to input RGB; the selected recipe does not perform this operation.
Pixel preservation depends on the composite
Segmentation answers where the foreground is. Pixel preservation depends on which image contributes pixels. The pinned masked composite combines destination × (1 - mask) with source × mask. A zero mask retains destination pixel values at that stage; a nonzero mask admits source values. A soft edge is a blend, so it does not provide the same preservation as a fully zero protected region.
In an existing flow using that implementation, retain the original as destination and use the edited image as source. The supplied preservation rule requires x = 0, y = 0, resize_source = false, an aligned mask that is zero throughout the protected region, and matching image representations. These are downstream conditions, not controls available in this mask recipe.
Check alignment against the exact images being composited. Matching width and height alone does not establish matching coordinates after a crop or repositioning. The implementation resizes the mask to source dimensions, applies placement and can resize the source; automatic resizing does not prove that a subject boundary still lines up. It also normalizes alpha representations, so representation conversion must be accounted for before claiming equality with the original.
Any preservation claim applies to that composite stage. Later resizing, color changes, encoding or other transformations need separate consideration. No composite node or preservation binding exists in the selected recipe, so extracting output:20 cannot guarantee unchanged pixels in a final image.
Resolve common mask handoff problems
Separate extraction problems from downstream interpretation problems. A mask can correctly identify the foreground and still select the wrong pixels when a consumer expects the opposite polarity. Likewise, a good segmentation boundary can become displaced if the mask and images no longer share coordinates. The selected recipe supplies neither an inversion control nor a boundary-refinement control; those remedies require capabilities already supported by your downstream flow.
The subject changes, or becomes transparent, while the background remains.
The receiving operation may interpret high mask values as source contribution or transparency rather than protection.
Check: The extracted boundary covers the intended subject, but the downstream operation acts on the opposite region.
Inspect foreground values and the receiving operation's polarity. If needed, invert using a supported downstream operation; this recipe has no inversion control.
The replacement boundary is shifted or scaled away from the subject.
Mask coordinates no longer match the source and destination; placement or resizing can change the correspondence.
Check: The mask fits the extraction image but does not fit one of the images entering the composite.
Restore matching coordinates or regenerate the mask from the image in the coordinate system used by the existing flow. For the supplied preservation rule, establish alignment with x and y at zero and resize_source false.
A protected edge still contains edited pixels.
Intermediate mask values blend source and destination; a nonzero protected region admits edited source values.
Check: The affected pixels lie where the composite mask is greater than zero, even if the preview looks nearly black.
Use supported downstream mask refinement if exact protection is needed, and inspect the coverage tradeoff. Keep protected pixels at zero for the original-destination arrangement; feathering blends the boundary.
Foreground details are missing from the extracted mask.
The model-generated foreground coverage does not necessarily include every detail needed for the intended edit.
Check: The omission is already visible in output:20 before downstream placement or blending.
Recipes and setup
What you need
- Model files
- 0.4 GiB
Remaining hardware or download-size estimates are not available yet.
Where this approach stops
- This recipe contains no image-edit, masked-composite, alpha-join or mask-inversion node.
- The retained operation declares no supported binding action or downstream input port.
- The recipe does not guarantee preservation of pixels in a final edited image.
