It is currently Sun Nov 23, 2014 8:08 am


Latest GIMP Scripts & Plug-ins

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How do I remove the background from an image?
PostPosted: Sat Jul 05, 2008 1:54 pm  (#1) 
Offline
Administrator
User avatar

Joined: May 22, 2008
Posts: 6284
Location: Somewhere in GIMP
This is a frequently asked question about gimp. This works if your background is one color; it will not work on multiple-colored backgrounds.

Be sure your image is RGB mode: Image > Mode > RGB.

This is the method I use when the background is all one color and I want semi-transparent pixels (antialiased) around the image. Make sure your background color is white. If the picture background it is a color other than white I use the Color Picker and store the color as the foreground color. Do NOT add an alpha channel to the layer. If the layer name (usually named Background) is not bolded, right-click the layer and choose Remove Alpha Channel - the layer name will be bolded.

This is the original picture.
Image

Use the fuzzy select tool and click the background. If you notice there are small places not selected in the background try raising the Threshold, re-click the background and see if that gets those stray pixels. If not, select Quick Mask, zoom in and find those pixels and paint them with a white brush by clicking the switch tool on the color selector. When you are finished, close Quick Mask, and switch the colors so that the background color is white again.

This is a high zoom picture of the background in the picture. You can see the stray pixels that seem to gather in pictures. You don't want those.
Image

Make sure your background color is white and Delete. Those off-colored pixels are gone. That is because there is no alpha channel and gimp chooses the background color to replace what you delete.

Image

Click Select > Grow and make it 1 pixel. Your selection now has included one pixel of the actual image in the picture. If you have a background other than white that you saved, click the foreground color box and copy the color number.

Colors > Color to Alpha > Click the color bar and delete the color number in there and paste the number you copied from the foreground color. (Don't try to fudge and run the default white color in Color to Alpha first - you'll have a mess.) Click OK. Back to Color to Alpha, click the color bar one more time and change the color to white (ffffff). Run Color to alpha again and your background is now transparent. You can see in the zoomed in picture that the selection is inside the actual image. When you do this, the outer row of pixels becomes semi-transparent.
Image

Here is a screen shot of the apple after running Color to Alpha. You will notice that your layer name is no longer bolded. If you notice that the semitransparent pixels around the image are colored and you want them uncolored (if there is a black stroke around the image especially), while the image is still selected, Colors > Desaturate (I usually use the lightness selection but experiment). You can Undo (Ctrl + Z) and try a different selection in Desaturate. Those colored pixels will be come shades of gray.
Image

Here is a png image of the apple with a transparent background.
Image

Keep in mind, this is not the only method of removing a background. I use this one a lot and it works well for me.

_________________
Image
There are two major products to come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence.

Image


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Profile  
 
 Post subject: Re: How do I remove the background from an image?
PostPosted: Thu Sep 02, 2010 11:22 am  (#2) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 628
In case anyone is interested, I have a script that implements this (more or less).

http://www.silent9.com/incoming/scripts/transbg.scm

It uses the upper left hand corner of the layer as the background colour to remove.

It shows up under Layers->Transparency.

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Last edited by RobA on Mon Apr 22, 2013 8:29 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: How do I remove the background from an image?
PostPosted: Thu Sep 02, 2010 11:49 am  (#3) 
Offline
Administrator
User avatar

Joined: May 22, 2008
Posts: 6284
Location: Somewhere in GIMP
RobA, that is an awesome script.

I love that I can set the threshold, the amount of shrink and can make the holes transparent.

I made this quicky image and flattened it to try it out. I left the threshold 25, shrink = 1, and checked Make the Holes Transparent. All done in the click of the OK button.

Image

I also tried it with the original image posted in this tutorial. Perfect! :clap
Image

_________________
Image
There are two major products to come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence.

Image


Top
 Profile  
 
 Post subject: Re: How do I remove the background from an image?
PostPosted: Thu Sep 02, 2010 5:54 pm  (#4) 
Offline
Administrator
User avatar

Joined: May 22, 2008
Posts: 6284
Location: Somewhere in GIMP
One more. Original image is here

I used shrink 2 in the script. After I ran the script I used the paths tool to select around the shadows and ran the selection through color to alpha with white.

Image

_________________
Image
There are two major products to come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence.

Image


Top
 Profile  
 
 Post subject: Re: How do I remove the background from an image?
PostPosted: Fri Sep 03, 2010 6:14 am  (#5) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 11563
Location: "Looking for my eraser" =P
Very nice!
Thanks for that script Rob.

_________________
Image
____________
OK, . . . . so what's the speed of dark?


Top
 Profile  
 
 Post subject: Re: How do I remove the background from an image?
PostPosted: Sat Oct 01, 2011 3:25 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Sep 12, 2011
Posts: 377
Location: UK
That's a handy script to have. Thanks rob


Top
 Profile  
 
 Post subject: Re: How do I remove the background from an image?
PostPosted: Sat Oct 01, 2011 10:49 am  (#7) 
Offline
GimpChat Member

Joined: Oct 06, 2010
Posts: 2666
Rob: Can I, or Rod host your GIMP script collection on our website as an alternate download location? Or perhaps upload some at the Registry?

_________________
You cannot do a kindness too soon because you never know how soon it will be too late.

~Ralph Waldo Emerson


Top
 Profile  
 
 Post subject: Re: How do I remove the background from an image?
PostPosted: Sat Oct 01, 2011 12:05 pm  (#8) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5877
Well RobA has a impressive collection of good scripts, most were a bit hidden in his side that now seems offline other sparse in replies to questions here on GC, GT on the registry and even at the carthographergilde..

For several if not all would be needed also summarize what request they fulfill and how, if not may be hard too guess
(as may be hard to guess some menu placement as for the gradients scripts...all placed in the most logical and functional but somehow harder to guess menu, the menu that appear only when right clicking on the gradient tool
And are all great scripts may be worth few note and screenshot to explain..)

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Profile  
 
 Post subject: Re: How do I remove the background from an image?
PostPosted: Sat Oct 01, 2011 2:35 pm  (#9) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 628
PhotoComix wrote:
Well RobA has a impressive collection of good scripts, most were a bit hidden in his side that now seems offline other sparse in replies to questions here on GC, GT on the registry and even at the carthographergilde..

For several if not all would be needed also summarize what request they fulfill and how, if not may be hard too guess
(as may be hard to guess some menu placement as for the gradients scripts...all placed in the most logical and functional but somehow harder to guess menu, the menu that appear only when right clicking on the gradient tool
And are all great scripts may be worth few note and screenshot to explain..)


My "big plan" was waiting on 2.8 and start updating them to use new features (particularly layer groups as most of my scripts use layers heavily) and then posting on my site, with example and such, much like:
http://www.silent9.com/blog/archives/14 ... ushes.html
http://www.silent9.com/blog/archives/16 ... Match.html
http://www.silent9.com/blog/archives/15 ... -Path.html
and
http://www.silent9.com/blog/archives/15 ... lugin.html

(The ones I actually have pages for.) Generally, I make them in response to a personal need or based on a specific request. Many are insanely specialized and have limited use, others are quite handy for most folks.

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Last edited by RobA on Mon Apr 22, 2013 8:33 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How do I remove the background from an image?
PostPosted: Sat Oct 01, 2011 3:26 pm  (#10) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5877
maybe i could have phrased better but mine was a positive comment

PS i still use very often Save and Export script, and was so clearly commented i could even add in my copy openraster format to jpg and png without no much trouble .

i would not be able to edit if was not written so clearly

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

* Login  

* Subscribe to Gimp Chat's RSS Feed    * Subscribe to Gimp Chat's Tutorial Feed    * Subscribe to Gimp Chat's G'MIC Feed


Powered by phpBB3 © phpBB Group