How can I remove the background from a gif?
-
- Posts: 8
- Joined: 2016-02-23T14:17:23-07:00
- Authentication code: 1151
How can I remove the background from a gif?
Hello,
I have a gif with a stable static background image and movement in the foreground. Is there an easy way to mask out the movement and remove the background? For example, if I wanted to create my own Travolta gif http://imgur.com/j51uHm1 , or BB8 https://media.giphy.com/media/eEbiAqk9YUT5e/giphy.gif
I have a gif with a stable static background image and movement in the foreground. Is there an easy way to mask out the movement and remove the background? For example, if I wanted to create my own Travolta gif http://imgur.com/j51uHm1 , or BB8 https://media.giphy.com/media/eEbiAqk9YUT5e/giphy.gif
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How can I remove the background from a gif?
Are these the images you want to remove the background or the result of removing the background. If the former, namely a reasonably constant color background, then just use
or
for each frame. The result will have a transparent background
Please always provide your IM version and platform when asking questions, since the syntax may differ.
Code: Select all
convert image -fuzz XX% -transparent yourbackgroundcolor result
Code: Select all
convert image -fuzz XX% -fill none -draw "alpha 0,0 floodfill" result
Please always provide your IM version and platform when asking questions, since the syntax may differ.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How can I remove the background from a gif?
If it is an animated gif and you want all the frames with tranparent background, then
Code: Select all
convert -delay Y animation.gif -coalesce -fuzz XX% -transparent yourbackgroundcolor -loop X -layers optimize new_animation.gif
-
- Posts: 8
- Joined: 2016-02-23T14:17:23-07:00
- Authentication code: 1151
Re: How can I remove the background from a gif?
Those are examples of the types of results I would like to achieve by removing the backgrounds from the original videos/gifs.
Version: ImageMagick 6.8.9-9 Q16 i586 2016-02-05
Version: ImageMagick 6.8.9-9 Q16 i586 2016-02-05
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How can I remove the background from a gif?
Background removal of non-constant background is very difficult. There is no good way that I know besides manually tracing the boundary. There are some tools out there that make it easier, but one still has to outline roughly. See for example:
https://clippingmagic.com/
http://research.microsoft.com/pubs/1474 ... rabcut.pdf
https://graphics.ethz.ch/teaching/forme ... apping.pdf
http://docs.opencv.org/3.1.0/d8/d83/tut ... #gsc.tab=0
https://clippingmagic.com/
http://research.microsoft.com/pubs/1474 ... rabcut.pdf
https://graphics.ethz.ch/teaching/forme ... apping.pdf
http://docs.opencv.org/3.1.0/d8/d83/tut ... #gsc.tab=0
-
- Posts: 8
- Joined: 2016-02-23T14:17:23-07:00
- Authentication code: 1151
Re: How can I remove the background from a gif?
I was afraid that might be the case. Thanks for the clippingmagic suggestion.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How can I remove the background from a gif?
I posted a few other links, one is from OpenCV for grabcut.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How can I remove the background from a gif?
If the background doesn't change between frames, you can use that to find it.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How can I remove the background from a gif?
Adding to what snibgo said, I think he is referring to frame-to-frame differences to see what is changing and what is not, if the background does not change between frames.
By tacking on, you run the risk of the IM developers not seeing your specific question. Yes, all questions are about this vulnerability, but each system and IM version may be different, in general, and need different responses. There have been many questions, each asking a different aspect of the vulnerability.That is why I suggested new topics for each.
By tacking on, you run the risk of the IM developers not seeing your specific question. Yes, all questions are about this vulnerability, but each system and IM version may be different, in general, and need different responses. There have been many questions, each asking a different aspect of the vulnerability.That is why I suggested new topics for each.
Re: How can I remove the background from a gif?
This seems to do part of the trick but each previous frame is overlayed:
convert bg-yellowish.gif -fuzz 3% -transparent "#fff5ba" a1.gif
I grabbed the yellowish gif from here:
https://static.ezgif.com/images/bg-yellowish.gif
I am able to do what I need at ezgif.com with the "don't stack frames" option, but I need to do this in code.
convert bg-yellowish.gif -fuzz 3% -transparent "#fff5ba" a1.gif
I grabbed the yellowish gif from here:
https://static.ezgif.com/images/bg-yellowish.gif
I am able to do what I need at ezgif.com with the "don't stack frames" option, but I need to do this in code.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How can I remove the background from a gif?
Try this:
Code: Select all
convert -dispose background bg-yellowish.gif -coalesce -fuzz 3% -transparent "#fff5ba" -layers optimize a1.gif