Skip to content

Instantly share code, notes, and snippets.

@cristianmenghi
Created October 13, 2023 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristianmenghi/393f170ae9e9baad7005318898fc5273 to your computer and use it in GitHub Desktop.
Save cristianmenghi/393f170ae9e9baad7005318898fc5273 to your computer and use it in GitHub Desktop.
Remove background
import argparse
from rembg import remove # pip install rembg
from PIL import Image
def main():
parser = argparse.ArgumentParser(description="Remove background from an image using rembg")
parser.add_argument("input_path", help="Input image file path")
parser.add_argument("output_path", help="Output image file path")
args = parser.parse_args()
input_path = args.input_path
output_path = args.output_path
inp = Image.open(input_path)
output = remove(inp)
output.save(output_path)
print(f"Background removed and saved to {output_path}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment