Show HN: Open-source background removal in the browser

395 points by buss_jan 2 years ago | 38 comments
@imgly/background-removal is a powerful javascript library that allows seamlessly background removal of images directly in the browser. With its unique features and capabilities, this package offers an innovative and cost-effective solution for background removal tasks without compromising data privacy.
  • culi 2 years ago
    Seems to be on par with the other best background remover I've tried.[0] The first one I've come across that's open source and this good. And it works in the browser! This is great, thanks

    [0] https://www.remove.bg/

  • iamflimflam1 2 years ago
    I didn’t realise that the preview app on Mac’s now has background removal built in. But I’ll also be bookmarking this site!
    • stephenr 2 years ago
      You can also just right click a file and choose "Remove background" from the Actions menu - on iOS this same behaviour is available just by long-press on a photo almost anywhere and drag the resulting foreground-only image, or alternatively hold and then choose "Copy Subject".

      Quite different (arguably better but I guess your use case will determine if it's better or worse) results for some images too, e.g. this image (https://www.southwiltonvet.com/files/HedgehogSouthWiltonVet....). The linked demo removes the hands/arms, macOS retains the hands/arms.

      On this image (https://media-cldnry.s-nbcnews.com/image/upload/streams/2014...) the linked demo makes the hands fade away like Greg Kinnear

      • elishah 2 years ago
        Yeah, and as is usually the case, it's not Preview in particular doing it. Preview itself does almost nothing, it's just a wrapper around the standard file handling libraries that everything on the platform uses.

        So this is just a normal thing you can do in nearly any context that any image is displayed anywhere on macos/ios. Not only no external site required, but not even any particular application required.

      • ianbicking 2 years ago
        This was the first time I heard of img.ly and had a little hobby project I was considering where the tools might be a nice fit... but the terms and cost is extremely opaque. Feels a little surprising given how pleasingly usable and straight-forward this open source software is.

        (I _think_ as long as I'm doing a hobby project I could use the img.ly CE.SDK for free indefinitely...? The only restriction is on "production" but what does that mean?)

        Probably these products don't match what I'm looking for, but it was all a little hard to ingest. That said, background-removal looks very easy to use and probably does fit my needs, so kudos for that. As someone who loves the ease of prototyping 100% in the browser this is also great!

        • nimrody 2 years ago
          Unrelated: anything similar for increasing photo resolution? I frequently encounter cases where users upload low resolution images (transferred using Whatsapp or similar) and need to increase the resolution to get something suitable for printing.
        • moffkalast 2 years ago
          Hmm it works surprisingly well, but it would be practical to have some kind of background area selector to help guide it and a threshold to adjust the removal, since the default setup sometimes messes up ever so slightly in some areas.
          • jtriangle 2 years ago
            The only software I've seen do that is Topazlab's product, which works based on trimapping with some AI edge detection/cleaning thrown in on top of it. Takes some fiddling to get good results, but, easily print quality.
          • hackernewds 2 years ago
            amazing library! I've been using pixian.ai but this is a game changer
            • culi 2 years ago
              Now if someone can just do this for a WASM AI-powered bitmap to vector conversion library, I'll be set
            • mydriasis 2 years ago
              That's awesome! I'm bookmarking this for later. This is something I always find myself wanting.
              • ibrarmalik 2 years ago
                Where does the model come from? Hard to trust the license when we have no idea with what data it has been trained.
                • mbappe123 2 years ago
                  Nice one, Remove.bg does the job little better over hairs.
                  • iamflimflam1 2 years ago
                    What are the licensing options? Can I use the npm package in a commercial project?
                    • dec0dedab0de 2 years ago
                      It says it's GPL. So yes you can use it in a commercial project as long as it is also GPL. Also, any license that restricts commercial use is neither Open Source as defined by the OSI, nor is it Free Software as defined by the FSF.
                      • pcthrowaway 2 years ago
                        IANAL, but I think it'd be OK to use it as long as you're not transpiling/minifying/bundling it in with your code[1].

                        Since it's Typescript, you obviously need to transpile to Javascript and host it somewhere you control for security (your own server is fine, just make sure the GPL license text is embedded). This is your GPL-respecting distribution of the software

                        Then in your webpage's index.html or other markup, include a `<script>` tag that links to it.

                        I believe this is all you need to be compliant with GPL.

                        [1]: https://unbiased-coder.com/can-you-use-gpl-in-closed-source/...

                        edit: much more detail in this answer: https://opensource.stackexchange.com/a/4385/10533

                        If there's any doubt, it seems like you'd be safe releasing a GPL-ed service worker which your website calls, as the boundary when calling a service worker is definitely enough for it to be deemed communication between two distinct pieces of software. This might be a bit difficult with a library that removes the background from your webcam though

                        • dec0dedab0de 2 years ago
                          I believe those links are talking about exceptions, and the LGPL.

                          Any exception would have to be granted by the copyright holder, and the LGPL is a different license which is designed for allowing libraries to be linked into non GPL code.

                      • buss_jan 2 years ago
                        The project is GPL licensed, if, however, you cannot use GPL licensed software do get in touch with support@img.ly and we'll make the package available to you under a different license.
                      • jjohansson 2 years ago
                        Amazing tech, congratulations!
                        • Gelob 2 years ago
                          how can i modify this if i have product images that have white in them but it keeps getting removed as this think its blended in the background?
                          • lionkor 2 years ago
                            Is there a similar tool as an android app?
                            • syuzannah 2 years ago
                              Great addition!
                              • revskill 2 years ago
                                I need watermark removal version.
                                • dathos 2 years ago
                                  You need to pay for art