Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ofn-erase-background
#1
A quick script to automate the background erasure when the background is uniform.

To use:
  • Make a selection on the background using the fuzzy selector with a threshold big enough to include small irregularities
  • Use Layer>Erase background
The script uses the now-classic color-to-alpha-on-grown-selection with a couple of enhancements:
  • Most of the background is completely deleted and is guaranteed to be totally transparent (thanks Blighty)
  • The color used for color-to-alpha is deduced from the erase background color, and so doesn't ned to be specified.
Script is at the usual place: Ofnuts' Gimp Tools downloads
Reply
#2
I tried it and got a border. Used the Fuzzy Select set at Red 33,2.
What did i do wrong ?

EDIT: also why is the image displayed in an upscaled way ? Its 640x400px.

   
Reply
#3
(10-30-2016, 03:53 PM)Espermaschine Wrote: I tried it and got a border. Used the Fuzzy Select set at Red 33,2.
What did i do wrong ?

EDIT: also why is the image displayed in an upscaled way ? Its 640x400px.

Can you post the original image?
Reply
#4
(10-30-2016, 07:25 PM)Ofnuts Wrote: Can you post the original image?

Whats wrong with the one i posted ?
Reply
#5
(10-30-2016, 07:39 PM)Espermaschine Wrote:
(10-30-2016, 07:25 PM)Ofnuts Wrote: Can you post the original image?

Whats wrong with the one i posted ?

Looking closer at you submission. Since the top image is transparent, I assume this is the result, and the bottom one was the source. The opening post says "script to automate the background erasure when the background is uniform. Which it obviously is not... so the color-to-alpha bit is going to use the "average red" in your image so some bit are not going to be transparent. However your result seems to indicate the script didn't terminate properly, but you should have error messages (dialogs or error console).

Anyway while trying to figure out your problem I found another one and fixed it so please re-download the latest (zip file should be 2623 bytes).

What I get with your image is:

   
Reply
#6
I wanted to simulate "artifacts" you mention in the documentary, so i added a bit of a slightly different red, as a lot of images you get, have a slight variation of color in their backgrounds.

There were no error messages or anything like that.

It appears to me, the red border at the edges of the image and around the circle, is where the selection was expanded but the wrong way around.#

EDIT: tried the new plug-in, i still get the same borders around the circle and on the edges. Even when executing the script on an image with pure red...

Im attaching the base-image.

   
Reply
#7
Your final image is normal as an intermediate step... but it is what I get when removing the color-to-alpha step from the script. There are only three lines of code at play there:

Code:
pdb.gimp_image_select_item(image, CHANNEL_OP_REPLACE, savedSelection)
pdb.gimp_selection_grow(image,2)
pdb.plug_in_colortoalpha(image,layer,(r,g,b))
The first one is the verbatim repeat of another operation, so I don't see it failing the 2nd time around, the second is too trivial to be a suspect, which leaves us with the third one. Have you got a functional Color-to-alpha plugin?
 
Also AFAIK if the code crashes you'll get a message. If you have the error console the messages are quietly logged there and easily overlooked.

Have you got a saved selection channel?
Reply
#8
Try this
  • Start Gimp, or close all images (we need to have one single image in Gimp).
  • Make/load an image with one single layer with something dark over a white background
  • make sure the layer has an alpha-channel
  • start the Python console (Filters>Python-fu>Console) and copy these two lines one by one followed by [enter]:
Code:
image=gimp.image_list()[0]
pdb.plug_in_colortoalpha(image,image.active_layer,(255,255,255))

Is the white background removed?

PS: when the script ends, have you got a selection? Is it the original one, or has it been shrunk or grown?
Reply
#9
Ok, so i made a black circle on a white background.
Did as you told me.

The white gets removed, but the progression bar, saying 'color gets removed' is somewhat stuck at approx. 90%
The progression bar disappears as soon as i close the console.

There is no selection, just a black circle on a transparent BG.
Reply
#10
Still can't tell what is wrong on your system and not on mine Smile

Just in case this is the C2A plugin, I changed the code to use the bucket-fill in color-erase mode, which is strictly equivalent. Can you donwload latest (zip is 2723 bytes) and give it a shot?

@everyone else: anyone else tried the script? Same problem, or OK for you?
Reply


Forum Jump: