Clearing background from an image using Machine Learning

Updated 14 December 2023


There are many use cases of AI and Machine Learning in mobile apps these days, one of the most usable use cases of machine learning is removing background from an Image.

Let’s imagine there is a person who is running his online eCommerce website, and everybody knows that product images play an important role in attracting customers.

But Clicking a high-quality image background less image requires a studio. And the Studio costs way too much.

How about an AI-based solution that converts your ordinary, “with-background” image to “background-less image”.

Yes, you heard it right for this TensorFlow provided a browser-based technique using which you can remove your image background just like that.

So let’s go and check how this can be done programmatically.

Firstly you need to have a well-trained model, there are two ways to do this.

a) Go for a pre-trained model, there are plenty out there

b) Train model yourself.

Both of the above-mentioned ways have their own pros and cons. This topic itself is very vast, we will discuss it in another blog.

Then you need to take a camera stream pic a frame from it and use the TensorFlow js API method  “model.execute()” to predict the desired object in that frame and delete or replace other pixels with some color or create a new picture from it and save it.

In the same way, you can use the HTML input type file as an input to the execute method

After that, if you want you can display the same with help of drawImage() on HTML 5 component canvas.

show me code

OK OK Let’s talk something about CODE

First, you need to load the model

Then, execute the model of the source input

Finally, Utilise this result data and draw on the canvas.

I followed this but can also follow, but this is limited to video-only.

For any query mail us t [email protected]

We would love to hear from you.

Thanks and stay tuned for other ML and AI-based articles.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home