16.5 u2net cutout


20211015 Remove the background from an image to produce a cutout version of the photo.

ml cutout u2net [options] [imagefile]
     -o <file.png> --output=<file.png>  Output image.
     -m <model>    --model=<model>      Which model to use.
                   --view               View a comparison in addition to generating the cutout.
                   --jpeg               Result is JPEG, no transparency.
     -a            --alpha-matting      Alpha matting.

     -f            --alpha-matting-foreground-threshold=240
     -b            --alpha-matting-background-threshold=10
     -e            --alpha-matting-erode-size=10
     -z            --alpha-matting-base-size=1000

By default the generated cutout is saved to the same input file with _cutout appended, but saved to the current working directory. To save the result elsewhere use -o|--output.

The package includes some sample images. Here we generate animal-1_cutout.png in the current working directory from a sample image:

ml cutout u2net ~/.mlhub/rembg/examples/animal-1.jpg

To view a popup that compares the cutout to the original, as well as saving the cutout to the local file, add the `–view`` option.

ml cutout u2net ~/.mlhub/rembg/examples/animal-1.jpg --view

TODO: Explain the models.

Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0