Gimp-Forum.net
ofn-erase-background - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: ofn-erase-background (/Thread-ofn-erase-background)

Pages: 1 2 3 4


ofn-erase-background - Ofnuts - 10-30-2016

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


RE: ofn-erase-background - Espermaschine - 10-30-2016

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.

[attachment=71]


RE: ofn-erase-background - Ofnuts - 10-30-2016

(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?


RE: ofn-erase-background - Espermaschine - 10-30-2016

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

Whats wrong with the one i posted ?


RE: ofn-erase-background - Ofnuts - 10-30-2016

(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:

[attachment=72]


RE: ofn-erase-background - Espermaschine - 10-30-2016

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.

[attachment=73]


RE: ofn-erase-background - Ofnuts - 10-30-2016

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?


RE: ofn-erase-background - Ofnuts - 10-30-2016

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?


RE: ofn-erase-background - Espermaschine - 10-30-2016

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.


RE: ofn-erase-background - Ofnuts - 10-31-2016

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?