{"id":22883033,"url":"https://github.com/ezaldeen99/backgroundremoval","last_synced_at":"2025-04-09T11:12:54.010Z","repository":{"id":38320226,"uuid":"470960450","full_name":"Ezaldeen99/BackgroundRemoval","owner":"Ezaldeen99","description":"Background Removal written with swift using u2net model ","archived":false,"fork":false,"pushed_at":"2023-12-21T10:00:22.000Z","size":6435,"stargazers_count":252,"open_issues_count":2,"forks_count":41,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-02T09:07:07.922Z","etag":null,"topics":["background-subtraction","backgroundremover","coreml","image-processing","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ezaldeen99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-03-17T11:12:18.000Z","updated_at":"2025-04-01T07:51:41.000Z","dependencies_parsed_at":"2024-12-13T18:42:34.436Z","dependency_job_id":null,"html_url":"https://github.com/Ezaldeen99/BackgroundRemoval","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ezaldeen99%2FBackgroundRemoval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ezaldeen99%2FBackgroundRemoval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ezaldeen99%2FBackgroundRemoval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ezaldeen99%2FBackgroundRemoval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ezaldeen99","download_url":"https://codeload.github.com/Ezaldeen99/BackgroundRemoval/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248027411,"owners_count":21035594,"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","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":["background-subtraction","backgroundremover","coreml","image-processing","swift"],"created_at":"2024-12-13T18:31:52.620Z","updated_at":"2025-04-09T11:12:53.982Z","avatar_url":"https://github.com/Ezaldeen99.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BackgroundRemoval\n\n\u003cimg src=\"https://github.com/Ezaldeen99/BackgroundRemoval/blob/main/ScreenShots/results.jpg\" alt=\"Removal results\" align=\"center\" /\u003e\n\n![License](https://img.shields.io/static/v1?style=for-the-badge\u0026message=Apache\u0026color=D22128\u0026logo=Apache\u0026logoColor=FFFFFF\u0026label=)\n![Platform](https://img.shields.io/static/v1?style=for-the-badge\u0026message=iOS\u0026color=000000\u0026logo=iOS\u0026logoColor=FFFFFF\u0026label=)\n![Swift](https://img.shields.io/static/v1?style=for-the-badge\u0026message=Swift\u0026color=F05138\u0026logo=Swift\u0026logoColor=FFFFFF\u0026label=)\n\n## Description\n\n\u003cimg src=\"https://github.com/Ezaldeen99/BackgroundRemoval/blob/main/ScreenShots/logo.jpg\" alt=\"Removal Icon\" align=\"right\" width=\"250\" height=\"250\" /\u003e\n\nWe depends heavily on Images these days, and sometimes developers need to make processing on these files and one of these things that give us headache is backgorund removal, I really hate that there are so few open source background removal models and libraries so I decided to make this library open source so people can use it, If this suits your need, give it a try 😉\n\n`Background removal` can give you two different outouts\n\n- Mask Image: The mask for your input image (black \u0026 white) so you can do any processing that you needs\n- Output image: ( default case) your output image without its background \n\nAnd, it has zero dependencies 😎\n\n## Usage\n\n### Output image\n\nTo start the background removal on your image you just need to pass a `UIImage` component to the library and get your output image, only that \n\n```swift\nlet image = UIImage(named: \"child\")\nlet backgroundRemoval = BackgroundRemoval()\ndo {\n    outputImage.image = try backgroundRemoval.removeBackground(image: image!)\n} catch {\n    print(error)\n}\n```\n\nThe output will always be a `UIImage` in all cases.\n\n### Mask Image\n\nIn case you wanted only The mask for your input image (black \u0026 white), then you case pass `maskOnly` arg to the library\n\n```swift\nlet image = UIImage(named: \"child\")\nlet backgroundRemoval = BackgroundRemoval()\ndo {\n    segmentedImage.image = try backgroundRemoval.removeBackground(image: image!, maskOnly: true)\n} catch {\n    print(error)\n}\n```\n\n## Save the Image \n\nMany users have already reported issues while saving the image without background to the device, \n\nthe solution below should work.\n\n```swift\nlet resultImage = BackgroundRemoval().removeBackground(image: image!)\n\nlet newImage2 = drawImage(resultImage)\nlet newImage = UIImage(data: newImage2!.pngData()!)\n\noutputImage.image = newImage\n```\n    \n  \nwhere the draw function is\n```swift\nfunc drawImage(_ image: UIImage) -\u003e UIImage?\n    {\n        guard let coreImage = image.cgImage else {\n            return nil;\n        }\n        UIGraphicsBeginImageContext(CGSize(width: coreImage.width, height: coreImage.height))\n        image.draw(in: CGRect(x: Int(0.0), y: Int(0.0), width: coreImage.width, height: coreImage.height))\n        let resultImage = UIGraphicsGetImageFromCurrentImageContext()\n        UIGraphicsEndImageContext()\n    \n        return resultImage;\n    }\n```\n\n### Improve results\n\nyou may see some shadows on the edges after you remove the background, you can add some filters on your mask before you mask the input image to get the output result, here is an example of a good tested workaround that gave me a better resutls\n\n```swift\nlet image = UIImage(named: \"child\")\nlet scaledOut = BackgroundRemoval.init().removeBackground(image: image!, maskOnly: true)\n\n\n/// post processing to get rid of image blur\nlet imageSource = BBMetalStaticImageSource(image: scaledOut)\n\n// Set up some filters for mask post processing\nlet contrastFilter = BBMetalContrastFilter(contrast: 3)\nlet sharpenFilter = BBMetalSharpenFilter(sharpeness: 1)\n\n// Set up filter chain\n// Make last filter run synchronously\nimageSource.add(consumer: contrastFilter)\n //   .add(consumer: lookupFilter)\n    .add(consumer: sharpenFilter)\n    .runSynchronously = true\n\n// Start processing\nimageSource.transmitTexture()\n\n// Get filtered mask\nlet filteredImage = sharpenFilter.outputTexture?.bb_image\n\n```\n\n\n### iOS version\n\nThe model supports macOS = 11, iOS = 14. however the library currently supports only iOS systems.\n\n\n\n## Installation\n\n**Background Removal** is available through [Package Manager](https://www.swift.org/package-manager/). To install\nit, simply copy the url file and click add package in your xcode and paste it:\n\n```\nhttps://github.com/Ezaldeen99/BackgroundRemoval.git\n```\n\n## Author\n\nEzaldeen sahb, let us connect https://www.linkedin.com/in/ezzulddin-abdulzahra-17918b137\n\n\n## Contributing\n\nWe would love you to contribute to **Background Removal**, there is still a huge room for improvment.\n\n\n## Credits\nThe library wouldn't be done without the effort of open source community specially.\n- [U-2-Net](https://github.com/xuebinqin/U-2-Net)\n- [SmartyToe](https://github.com/SmartyToe/Image-segmentation)\n\n\n\n## License\nProject is published under the Apache 2.0 license. Feel free to clone and modify repo as you want, but don't forget to add reference to authors :)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezaldeen99%2Fbackgroundremoval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezaldeen99%2Fbackgroundremoval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezaldeen99%2Fbackgroundremoval/lists"}