Background from a picture

Hello!

Is there a way to remove the background from a picture?

Here's an example.

at this point I think we need a category for truly random questions !

2 Likes

Here is a suggestion... and without background :stuck_out_tongue:

Joking aside... and because, while not retired, I currently DO have more time than energy... I suspect the OP is looking for some JS code, preferably already in a "nicely wrapped node" that will take in an image and spit out same image minus background. Hey, it is only code, should be possible, right?

A little Googling shows that the answer may be *Yes

*lots of background code, perhaps.in form of 3rd party services

For example... I found this service/api (NO affiliation nor intent to advertise... just a result from Googling)...

Or if I’m Linux maybe an imagemagik call from an exec ? How to replace white background color with transparent of an image in ImageMagick? - Stack Overflow

Hello!

Many thanks for the answer.

The side no me but they want enough money for it. 0.20 euros per picture.

Here is a site that is free but doesn't offer an API.

So I'm looking for another solution.

Sorry to interrupt the excellent humour in this thread...

The closest thing to background subtraction in images I found, is the node-red-contrib-camera-motion node. It does not have a readme page (yet), but you can see this in his Github repository:

image

There is also a possiblity to use Tensorflow.js for this purpose (see e.g. here).

Bart

Many thanks for the answer.
I've tried it with imagemagick, but unfortunately that doesn't look so nice.

I had also came across this - Cloudinary - Pricing and Plans

From here - Remove Photo Backgrounds with Cloudinary

With Cloudinary - Pricing and Plans, only 3 images per month are free.

Well, depending on the imagery, you are asking for some relatively serious processing power for hopefully good results... so close to free may be all you get short of coding it yourself.

You can also use opencv.js, which has support background subtraction via the BackgroundSubtractorMOG2 algorithm (see here). And in this link you can find an example of how to run opencv.js (which is a WASM port of OpenCv) in NodeJs.

1 Like

Here is a client side demo...

Hello!

Many thanks for the answer.

But unfortunately it doesn't happen when you click on inject

No. As I said, it is a client side demo. You need to open the endpoint /image_payload (e.g. http://localhost:1880/image_payload or whatever your node-red is)

May or may not be of use - depending on what your goal is

Hello!

Thanks for the answer.

Can this also be built into the flow? Which he converts several images at once.

Probably not. (or not so easily) as I said, it was a client side demo and I had no idea of your usage. It seems you want to automate things at server side.

OpenCV or a command line application is probably the way to go.

OK thanks

As I suggested originally - to do it locally a command line like linux's imagemagik like this may do it on pi etc.

convert input.jpg -fuzz 30 -fill none -draw 'color 1,1 floodfill' output.png`

basically that command take the pixel at 1.1 (top left) and assumes that is the background colour - with a fuzz of 30 so anything close is also background - and make them all transparent.
Note your original image is a jpeg that doesn't support transparency so this converts it to a png.

1 Like

I understood that the OP wanted the backgrounds removed (AKA whitened out as per example) not turn the background into a transparency. Isn't that two different processes, or at least one must come before the other to work effectively.