It is currently Mon Apr 15, 2024 8:14 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Remove BG BY Color to Alpha script
PostPosted: Sat Oct 29, 2016 11:56 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Cutting out the same bg color per layer can be tedious so i remembered Ofnuts small tutorial on removing SOLID bg colors by
1) Add alpha channel
2) Select by color
3) grow by pixels needed to remove all color
4) utilize Color To Alpha to make selected color TRANSPARENT within ONLY the selected area.
5) Remove selection
SEE POST #4 for new added feathering update to script.
This works excellent so i scripted it for quicker use.
SCM is attached -
Attachment:
Removes-bg-color-from-Hemera-Photo-Objects_RD.scm [2.19 KiB]
Downloaded 363 times

Menu location is Rod>Remove Photo Object BG Color

Dialog has 2 values for input
1) Color to choose to make transparent
2) Grow Selection by how many pixels

Example image
Image

After running filter with these settings
Image

Image

If i would have used a larger pixel growth on the selection all the blue color would have been removed. So i hope this helps someone out there.

Thank you Ofnuts for the idea. :) :bigthup

Let me know if you have any bugs or issues with it.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Last edited by Rod on Sat Jul 15, 2017 5:21 pm, edited 2 times in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 1:52 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Mar 01, 2014
Posts: 12636
Location: Spain, Aragón
Rod, your script is so useful. It was a dream I had if it was possible to do and you did it! :tyspin :bump
Thank you so much :)

_________________
Image

Gimp 2.10.30(samj) portable _ OS Windows 10 Home_ 64bits
Don’t be afraid to start over. It’s a new chance to rebuild what you want.


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 2:16 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Issabella wrote:
Rod, your script is so useful. It was a dream I had if it was possible to do and you did it! :tyspin :bump
Thank you so much :)

You are very welcome. I hope it helps you in the future. I will probably add feather selection to it as Ofnuts did mention feathering the selection also. I will keep you updated on that.

Thanks Issabella.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 2:29 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Actually it was pretty easy to just add it now. The filter is updated to 1.1.
Added "Feather Selection"

Image

Attachment:
File comment: Added Feather Selection v-1.1
Removes-bg-color-from-Hemera-Photo-Objects_RD.scm [2.33 KiB]
Downloaded 299 times

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 2:37 am  (#5) 
Offline
GimpChat Member

Joined: Sep 23, 2016
Posts: 316
Rod wrote:
1) Add alpha channel
2) Select by color
3) grow by pixels needed to remove all color
4) utilize Color To Alpha to make selected color TRANSPARENT within ONLY the selected area.
5) Remove selection


The above works well if the background is a solid colour eg if created by vector graphics. Take for example an item photographed against a background colour and saved as a jpg. There will be significant variations in the background colour.

A more useful workflow is:
1) Add alpha channel
2) Select by color
3) Delete background
4) grow by pixels needed to remove all color
5) utilize Color To Alpha to make selected color TRANSPARENT within ONLY the selected area.
6) Remove selection
Deleting the background takes care of the variations in background colour.


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 5:13 am  (#6) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
Blighty II wrote:
Rod wrote:
1) Add alpha channel
2) Select by color
3) grow by pixels needed to remove all color
4) utilize Color To Alpha to make selected color TRANSPARENT within ONLY the selected area.
5) Remove selection


The above works well if the background is a solid colour eg if created by vector graphics. Take for example an item photographed against a background colour and saved as a jpg. There will be significant variations in the background colour.

A more useful workflow is:
1) Add alpha channel
2) Select by color
3) Delete background
4) grow by pixels needed to remove all color
5) utilize Color To Alpha to make selected color TRANSPARENT within ONLY the selected area.
6) Remove selection
Deleting the background takes care of the variations in background colour.


There is a problem with this method... when you delete you also include some pixels that should have been processed by Color-to-Alpha, so a more proper technique would be:

  1. Select background, and save to channel
  2. Select>Shrink by 2px and delete
  3. Restore saved selection
  4. Select>Grow by 2px and use Color-to-Alpha
This uses a saved selection because growing by 4 pixels something you shrunk by 2 can be different from growing the original by 2.
A script could also evaluate the average color of the background and use that in Color-to-alpha, instead of requesting it from the user, so once you have a selection no parameters are needed and the script becomes significantly faster that the manual method.

_________________
Image


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 5:16 am  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
Rod wrote:
I will probably add feather selection to it as Ofnuts did mention feathering the selection also.

No, nay , never(*)... Of give me a link, I must have been drunk.

(*) it is completely against the principles of that technique.

_________________
Image


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 9:12 am  (#8) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Blighty II wrote:
Rod wrote:
1) Add alpha channel
2) Select by color
3) grow by pixels needed to remove all color
4) utilize Color To Alpha to make selected color TRANSPARENT within ONLY the selected area.
5) Remove selection


The above works well if the background is a solid colour eg if created by vector graphics. Take for example an item photographed against a background colour and saved as a jpg. There will be significant variations in the background colour.

A more useful workflow is:
1) Add alpha channel
2) Select by color
3) Delete background
4) grow by pixels needed to remove all color
5) utilize Color To Alpha to make selected color TRANSPARENT within ONLY the selected area.
6) Remove selection
Deleting the background takes care of the variations in background colour.

I created this script to do just that. Remove a single solid color. If you want to add features like remove different colors from bg be my guest. :)
You can however keep re running the filter (SHIFT + CTRL + F) selecting bg colors for multi color backgrounds.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 9:13 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
ofnuts wrote:
Rod wrote:
I will probably add feather selection to it as Ofnuts did mention feathering the selection also.

No, nay , never(*)... Of give me a link, I must have been drunk.

(*) it is completely against the principles of that technique.


I am getting old and forgetful Ofnuts so perhaps i am wrong about your mention. It does however seem to work a little better with Feather so i will leave it in.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 9:15 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Quote:
A script could also evaluate the average color of the background and use that in Color-to-alpha


How would i do that?
Would "blur>pixelize" the entire image work?

Nope tried it.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 9:24 am  (#11) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
Rod wrote:
Quote:
A script could also evaluate the average color of the background and use that in Color-to-alpha


How would i do that?
Would "blur>pixelize" the entire image work?

Nope tried it.

Thought about this over breakfast, and implented it together will Blighty's suggestion. See here

_________________
Image


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 9:33 am  (#12) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
ofnuts wrote:
Rod wrote:
Quote:
A script could also evaluate the average color of the background and use that in Color-to-alpha


How would i do that?
Would "blur>pixelize" the entire image work?

Nope tried it.

Thought about this over breakfast, and implented it together will Blighty's suggestion. See here

Thank you sir. :)

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 11:11 am  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Rod wrote:
Actually it was pretty easy to just add it now. The filter is updated to 1.1.
Added "Feather Selection"

[ Image ]

Attachment:
The attachment Removes-bg-color-from-Hemera-Photo-Objects_RD.scm is no longer available


installed and used to create from these
Attachment:
flowers_photography_by_almaskary-d54f9on-crop.jpg
flowers_photography_by_almaskary-d54f9on-crop.jpg [ 193.85 KiB | Viewed 2330 times ]

Attachment:
Ice-Mountains-Landscapes-Snow-Night-Fire-Deviantart-High-Definition-Hdr-Photography-Skyscapes-Evrengunturkun-1280x720.jpg
Ice-Mountains-Landscapes-Snow-Night-Fire-Deviantart-High-Definition-Hdr-Photography-Skyscapes-Evrengunturkun-1280x720.jpg [ 661.18 KiB | Viewed 2330 times ]


this one
Attachment:
Ice-Mountains-Landscapes-with-flower-FG.jpg
Ice-Mountains-Landscapes-with-flower-FG.jpg [ 809.96 KiB | Viewed 2330 times ]


nice, Rod!

_________________
"Where am I ?"


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 11:25 am  (#14) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
dinasset wrote:
Rod wrote:
Actually it was pretty easy to just add it now. The filter is updated to 1.1.
Added "Feather Selection"

[ Image ]

Attachment:
Removes-bg-color-from-Hemera-Photo-Objects_RD.scm


installed and used to create from these
Attachment:
flowers_photography_by_almaskary-d54f9on-crop.jpg

Attachment:
Ice-Mountains-Landscapes-Snow-Night-Fire-Deviantart-High-Definition-Hdr-Photography-Skyscapes-Evrengunturkun-1280x720.jpg


this one
Attachment:
Ice-Mountains-Landscapes-with-flower-FG.jpg


nice, Rod!

Those came out beautiful. :)
Glad it was helpful.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 11:33 am  (#15) 
Offline
GimpChat Member
User avatar

Joined: Dec 10, 2013
Posts: 1004
Image


Thank you Rod!

_________________
Image
Macbook Air - MacOS Sierra 10.12
McGimp 2.8.14
G'mic 1.6.5


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Oct 30, 2016 11:45 am  (#16) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Dalia wrote:
[ Image ]


Thank you Rod!

You are welcome Dalia. :)

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Mon Oct 31, 2016 8:56 am  (#17) 
Offline
GimpChat Member
User avatar

Joined: Mar 01, 2014
Posts: 12636
Location: Spain, Aragón
Rod, your filter works wonderful! Thanks with flowers :tyspin

The result is in transparency. PNG :)


Attachments:
decoracion3.jpg
decoracion3.jpg [ 332.05 KiB | Viewed 2301 times ]
decoracion3.PNG
decoracion3.PNG [ 1.87 MiB | Viewed 2301 times ]

_________________
Image

Gimp 2.10.30(samj) portable _ OS Windows 10 Home_ 64bits
Don’t be afraid to start over. It’s a new chance to rebuild what you want.
Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Mon Oct 31, 2016 8:58 am  (#18) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Issabella wrote:
Rod, your filter works wonderful! Thanks with flowers :tyspin

The result is in transparency. PNG :)


Thank you Issabella. That looks really nice. :)

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Aug 23, 2020 12:01 am  (#19) 
Offline
GimpChat Member
User avatar

Joined: Jul 06, 2013
Posts: 2605
Location: California
Does this script work in 2.10.20 in Windows 10?


Top
 Post subject: Re: Remove BG BY Color to Alpha script
PostPosted: Sun Aug 23, 2020 12:34 am  (#20) 
Offline
GimpChat Member
User avatar

Joined: Nov 04, 2015
Posts: 1331
Works OK in 2.10.19 Ubuntu appimage. Best to use it on logos but results will vary on other images.


Top
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Layer masks darkening color channels (forced premultiplied alpha?)

2

No new posts Attachment(s) GEGL Color Light Fusion (12 blend modes for color overlay)

9

No new posts Attachment(s) Background color chanage and typed text color change

8

No new posts Attachment(s) Color does not exactly match color in GIMP 2.10 (SOLVED)

9

No new posts Attachment(s) Remove Stain from Image

5



* Login  



Powered by phpBB3 © phpBB Group