{"id":26104670,"url":"https://github.com/vaxdata22/image-background-remover-demo-with-python","last_synced_at":"2026-05-18T06:11:44.965Z","repository":{"id":280850222,"uuid":"943384922","full_name":"vaxdata22/Image-Background-Remover-demo-with-Python","owner":"vaxdata22","description":"This is a simple but fun exercise that was done to demonstrate the power of Python in image manipulation using libraries like Pillow (PIL) and Rembg as well as leveraging ONNX Runtime for faster processing on GPU. ","archived":false,"fork":false,"pushed_at":"2025-03-05T18:35:55.000Z","size":16453,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T21:11:48.068Z","etag":null,"topics":["jupyter-notebook","pillow","python","rembg"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vaxdata22.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-05T16:12:35.000Z","updated_at":"2025-03-05T18:35:58.000Z","dependencies_parsed_at":"2025-03-05T17:38:38.157Z","dependency_job_id":null,"html_url":"https://github.com/vaxdata22/Image-Background-Remover-demo-with-Python","commit_stats":null,"previous_names":["vaxdata22/image-background-remover-with-python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vaxdata22/Image-Background-Remover-demo-with-Python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaxdata22%2FImage-Background-Remover-demo-with-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaxdata22%2FImage-Background-Remover-demo-with-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaxdata22%2FImage-Background-Remover-demo-with-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaxdata22%2FImage-Background-Remover-demo-with-Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaxdata22","download_url":"https://codeload.github.com/vaxdata22/Image-Background-Remover-demo-with-Python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaxdata22%2FImage-Background-Remover-demo-with-Python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278543736,"owners_count":26004200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jupyter-notebook","pillow","python","rembg"],"created_at":"2025-03-09T21:01:54.405Z","updated_at":"2025-10-06T01:09:50.582Z","avatar_url":"https://github.com/vaxdata22.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Image Background Remover demonstration with Python\nThis is a simple but fun exercise that was done to demonstrate the power of Python in image manipulation using libraries like Pillow (PIL) and Rembg as well as leveraging ONNX Runtime for faster processing on GPU. \n\nIn this simple but exciting demo, we would see how to leverage the power of Python to remove background from an image file. \nThere are two methods that would be explained here.\n\u003cbr\u003e\u003c/br\u003e\n\n## METHOD 1: Interactive Python Notebook\nYou can do this using Jupyter notebook environment. \n\nThis guide uses Google Colab.\n\nGo to [colab.google.com](https://colab.google.com/) \n\n![img1](screenshots/img1.png)\n\u003cbr\u003e\n\nClick on New Notebook.\n\n![img2](screenshots/img2.png)\n\u003cbr\u003e\n\nOn the left pane, click on the folder icon to see the Files browser\n\n![img3](screenshots/img3.png)\n\u003cbr\u003e\n\nClick on the file upload icon to upload JPEG photo file(s). \nBrowse your local storage to select the file(s) you wish to work on, then click Open and OK.\n\n![img4](screenshots/img4.png)\n\u003cbr\u003e\n\nDouble-click on the uploaded image file on the left pane to preview it. \nIt displays on the right pane.\n\n![img5](screenshots/img5.png)\n\u003cbr\u003e\n\nNow you can just upload the [image_background_remover.ipynb](codes/image_background_remover.ipynb) file provided via File \u003e Upload notebook  \u003e Upload \u003e Browse. This would have all the code ready for you. \n\nHowever let’s fill in the code by hand. \nFill in the code below into three cells, and run each cell one-by-one:\n```\npip install pillow rembg onnxruntime\n\nfrom rembg import remove\nfrom PIL import Image\n\nimg = Image.open(\"photo.jpg\")\noutput = remove(img)\noutput.save(\"photo.png\")\n```\n\nEnsure that a cell has finished running before you run the next one. \nTo begin, click on Code just above the middle section. \nAfter filling in that cell, move your mouse pointer to the middle of the cell and click on the Code icon that appears.\n\nNote that you would have to replace “photo” in the code with the name of the JPEG file you uploaded. \nThe output can be of any filename anyway but this file must be a PNG file, while the input should be a JPG file. \n\n![img6](screenshots/img6.png)\n\u003cbr\u003e\n\nBe patient for a while so that the third cell would finish running. \nYou’ll see that it has finished running when it creates the output image file on the left pane.\n\n![img7](screenshots/img7.png)\n\u003cbr\u003e\n\nNow double-click on the output file on the left pane to preview it.\n\n![img8](screenshots/img8.png)\n\u003cbr\u003e\n\nThe background has been removed nicely. \nTo download it to your local storage, you can simply right-click on it then click “Save Image As”. \nAlternatively, you can click on the three dots that appear when you point to the output file on the left pane, and then click on “Download”.\n\nTo work on another JPEG file, simply upload the file.\n\n![img9](screenshots/img9.png)\n\u003cbr\u003e\n\nThen go to the third cell to edit the input and output filenames accordingly, and then re-run only that cell.\n\n![img10](screenshots/img10.png)\n\u003cbr\u003e\n\nThe background is again, removed!\n\u003cbr\u003e\u003c/br\u003e\n\n## METHOD 2: Command-Line Interface (CLI)\nThis can be done from your command prompt (Windows) or Terminal (Unix/Linux).\nRemember to change directory (cd) into the directory that contains the JPEG image file(s) that you want to work on, or you can simply place those files in your current working directory.\nThen run this command to install the RemBG CLI package into your environment:\n```\npip install rembg[cli] onnxruntime\n```\n\nThe next command would be used to remove background from a specified JPEG file. \nReplace “photo” with the name of your chosen file. \nThe “i” flag is used to pass the file. Again the output file can be of any filename:\n```\nrembg i photo.jpg photo.png\n```\n\nIf you want to process multiple JPEG files, pass the directory that contains the files as input using the “p” flag, and specify a directory (the same or another) where the output files would be dumped. \nThe code below would be used if the input files are located in your current working and you still want to dump the output files there:\n```\nrembg p ./ ./\n```\n\nIn the following examples, the commands would be run on an interactive Python notebook by preceding each command with an exclamation sign “!”:\n\n![img11](screenshots/img11.png)\n\n![img12](screenshots/img12.png)\n\n![img13](screenshots/img13.png)\n\n![img14](screenshots/img14.png)\n\u003cbr\u003e\n\nThe following last screenshots show how to handle several files:\n\n![img15](screenshots/img15.png)\n\n![img16](screenshots/img16.png)\n\n![img17](screenshots/img17.png)\n\u003cbr\u003e\n\nThe outputs:\n\n![img18](screenshots/img18.png)\n\n![img19](screenshots/img19.png)\n\n![img20](screenshots/img20.png)\n\u003cbr\u003e\n\nOn a final note, to get faster results you can switch from CPU processing to GPU. Go to the top and click on the Runtime menu, then click Change Runtime Type. Under Hardware Accelerator, click T4 GPU.\n\nNB: The CLI commands are [here.](codes/background_remover_CLI.txt)\n\nYou can use the following [photos](photos) to practice (remember to give proper credits if you would share your work online or offline).\n\nIMAGE CREDITS (Pexels.com):\nDog: Matheus Bertelli\nHen: Frank Grün\nCat: Bruno Scramgnon\n\nThank you for going through this demo with me!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaxdata22%2Fimage-background-remover-demo-with-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaxdata22%2Fimage-background-remover-demo-with-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaxdata22%2Fimage-background-remover-demo-with-python/lists"}