danielgatis / rembg

Rembg is a tool to remove images background
MIT License
16.48k stars 1.84k forks source link

Add cloth category selection feature to u2net_cloth_seg #485

Closed szriru closed 1 year ago

szriru commented 1 year ago

Overview

This Pull Request adds cloth category selection feature when using u2net_cloth_seg

Changes Made

Users now can select which cloth category to "rembg" with a command -cc or --cloth-category. The values are "upper" or "lower" or "full", so it can be used like: rembg i input.png out.png --model u2net_cloth_seg --cloth-category lower

Mensioned Issue

484

Testing

Tried "i" and "p" command with the new option "-cc" and "--cloth-category", and it worked fine.

Result example

python ./rembg.py i ./cc-example.jpg ./cc-example-out.jpg -om --model u2net_cloth_seg --cloth-category upper

Input

cc-example

Output

cc-example-out

Reviewer Notes

I would appreciate your review of this Pull Request.

Thank you.

danielgatis commented 1 year ago

Wow! Thank you so much. It would be nice to use the existing extra option instead of creating another option.

for example:

rembg i input.png out.png -m u2net_cloth_seg -x '{ "cloth-category": "lower" }'
szriru commented 1 year ago

@danielgatis Thank you for reviewing. I commited the fixed code. It can be used with args like you provided: -x '{ "cloth-category": "lower" } or --extras '{ "cc": "upper" } I would appreciate if you can review again.

I tested with these commands, and it worked fine.

python rembg.py i input.jpg output.jpg -m u2net_cloth_seg -om python rembg.py i input.jpg output.jpg -m u2net_cloth_seg -om -x '{"cc": "lower"}' python rembg.py i input.jpg output.jpg -m u2net_cloth_seg -om --extras '{"cloth_category": "upper"}'

((We have to be careful because it will not work correctly if we swap single and double quotes due to a problem in cmd or shell or in the argment parser we use. We should put like '{"cc": "lower"}' not "{'cc': 'lower'}"))