U2Net Segmentation
This function block performs salient object detection and background removal. Use it to extract a clear foreground mask and to produce a segmented image where the background is removed.
π₯ Inputs
Image Any The input image to analyze (color or grayscale). Connect the image source you want to segment.
π€ Outputs
Image Gray Grayscale probability map / mask showing object likelihood.
Image Any Segmented image where background is removed using the mask.
πΉοΈ Controls
Model Select between available U2Net variants (for example "U2Net (High Quality)" or "U2NetP (Fast)"). Choose higher quality for better masks or the fast model for speed.
Input Size Resize the model input. Smaller values increase speed; larger values improve detail at the cost of performance.
Threshold Controls binarization of the probability map to create the final mask. Increasing the threshold makes the mask stricter (fewer foreground pixels).
π¨ Features
Foreground extraction to produce a soft probability map and a binary mask.
Segmented color image output that keeps only the detected foreground.
Two model choices to trade off accuracy vs speed.
Adjustable preprocessing size and threshold for fine control.
π Usage Instructions
Connect an image source to the
Image Anyinput.Choose a
Modeldepending on whether you prefer quality or speed.Adjust
Input Sizeto balance detail and processing time.Tune
Thresholdto get the desired binary mask (preview using aShow Imageblock).Use the
Image Grayoutput when you need the mask for further processing, and theImage Anyoutput for visualization or saving.
π Evaluation
When run, this block produces a probability mask and a segmented image based on the currently selected model and slider settings. Use the mask output to feed subsequent processing blocks (e.g., filtering, contour detection, ROI operations).
π‘ Tips and Tricks
To speed up processing while keeping acceptable quality, reduce
Input Sizeand use theU2NetP (Fast)model.For better-looking masks on noisy images, pass the source through
DenoisingorBlurbefore this block.If the subject is small relative to the image, use
Image Resizeto upsample the region of interest before segmentation.Preview results interactively by connecting the segmented output to
Show Image.Save results automatically by linking the segmented image to
Image LoggerorImage Write.If you need alternative background removal approaches, compare results with
Background Removal (RMBG-1.4)orBackground Removal (BiRefNet)to see which fits your scene best.Use the binary mask output as input to ROI or shape-analysis blocks (for example, contour finders or measurement blocks) to extract object geometry.
(hint: useful companion blocks β Show Image, Image Resize, Denoising, Image Logger, Image Write, Background Removal (RMBG-1.4), Background Removal (BiRefNet))
π οΈ Troubleshooting
If masks look incomplete or too noisy: increase
Input Sizeor applyDenoising/Blurto the input image.If the mask is too permissive (background included): raise
Thresholdto make the mask stricter.If processing is too slow: switch to the faster model option and/or lower the
Input Size.If no output appears: confirm a valid image is connected to the
Image Anyinput and preview usingShow Image.
Last updated