Detect surface (wall / floor) & make transparent using GLSL or JavaScript

I’m trying to remove the wall/floor surface from an uploaded image.

I’ve attempted using AI tools, Stack Overflow solutions, and pre-trained Python models, but none have given the expected results.

Can anyone suggest the best approach to achieve this?

current GLSL code : https://codepen.io/Vatsal-Pandya-the-solid/pen/xbxgJjr

glitch code link : Glitch :・゚✧

original image

current output :

expected output or closer to this one :

when we have multiple or complex objects in image scene, not able to identity any of them and make transparent surface.

other sample images


I don’t think this can be done with GLSL. You’ll need an AI-based background remover (and a watermark remover for the last one), combined with a 2D canvas context.

A quick search for “JS AI background remover” gave me these links:



2 Likes

thanks for the quick response, I have just shared a set of images downloaded from freepik, watermark removal is not a part of requirement.

I need to convert many images with a transparent surface, so I am looking for an open-source option. unfortunately imgly third option seems to be a paid one.

could you please share which approach you have used to convert those sample images ?

You can run background removal model (for example this one, but there’s quite a ton of them around) using transformers.js - but effects will vary greatly depending on the users’ device.

And if you have access to a GPU - setting it up is even easier, you just install ComfyUI, add a single node (see example workflow at the bottom), and expose it all as an API endpoint.

3 Likes

I’ve used Imgly :sweat_smile:! But as far as I know, it’s not under a paid license, they use AGPL-3.0, which is open source with a strict copyleft license. That might not align with what you’re looking for.

The first link, cog-RMBG, is the worst option:

  • The model is open-source but only for non-commercial use.
  • Commercial use requires a separate agreement with BRIA. Contact Us for more details.

As for the second link, you can ignore it. Now that I’ve taken a closer look, it’s based on BodyPix, so it only supports body segmentation.

After some digging, I found this blog post on image segmentation. It uses Google’s DeepLab, licensed under Apache-2.0, so it could be a good alternative.

2 Likes

I have tried many of the models, but they fail to identify when we have multiple objects in an image.

I am trying to built an API for this feature, so it would be hard or almost impossible to have GPU access in API server hosting.

thank you for your suggestions.

official sandbox demo link of img.ly.

as far as I understood they provide bg-removal with GUI, I am not sure if they provide a solution which can be used on server side as well ?

Yes, I have tried that in initial phase of finding a solution of this. even it works for only simple images, didn’t worked for complex images.

I have tried this one, not so quite useful in removing bg surfaces.

I found a reference (uses TensorFlow & COCO-SSD), but it detects only some one the pre-defined objects only.

Effective, adequate and universal removal of background in complex images is not trivial. I think it is unsolved problem … there are lot of tools to remove background, but each of them will fail in some cases. Such removal would require either understanding of the objects and their spacial properties, or would require some help (like different colors, depth perception, image recognition, human intervention, etc). That’s why movie productions still use green screens. It just makes things much more manageable.

Here is a sketch that might give you a perspective of potentially fast way to deal with the issue:

And a warning: if you plan to harvest images of furniture or other objects from online images, you should carefully check the license. My suggestion is to contact the other party before initiating mass harvesting even if the images are declared as “free”.

1 Like

@PavelBoytchev thank you for the response.

main usage of approach will be user will upload the actual real time images of their own house / room, from that uploaded images we need to clear the surface backgrounds. Shared images are for the sample usage and testing purpose only.

yes, Agreed.

As I am trying for the dynamically uploaded images, removing bg with manual efforts won’t work. I have already spent a lot of time searching for a suitable library to handle this, but haven’t found one. Writing my own code would take too long, especially since I am still in the learning phase.

Many modern IR phone cameras have depth estimation tools which could sort coplanar surfaces.

M. BIRSAND

2 Likes

and… extending this answer, the Depth-Anything model can be run in the browser…
from depth, you could reconstruct normal, and from normal, extract planes…
from user selected planes, you could extract a mask with the rest of the depth buffer.

using a segmentation model directly is probably easier to implement though.

2 Likes

@kpachinger @manthrax thanks.

I will try this model once : Depth Anything - a Hugging Face Space by LiheYoung