Posts: 6,366
Threads: 276
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 3.00RC1
10-30-2016, 02:19 PM
(This post was last modified: 10-30-2016, 02:20 PM by Ofnuts.)
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
Posts: 939
Threads: 93
Joined: Oct 2016
Reputation:
36
Operating system(s):
- Windows (Vista and later)
Gimp version: 2.10
10-30-2016, 03:53 PM
(This post was last modified: 10-30-2016, 03:59 PM by Espermaschine.)
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.
Posts: 6,366
Threads: 276
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 3.00RC1
(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?
Posts: 939
Threads: 93
Joined: Oct 2016
Reputation:
36
Operating system(s):
- Windows (Vista and later)
Gimp version: 2.10
(10-30-2016, 07:25 PM)Ofnuts Wrote: Can you post the original image?
Whats wrong with the one i posted ?
Posts: 6,366
Threads: 276
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 3.00RC1
10-30-2016, 09:23 PM
(This post was last modified: 10-30-2016, 09:26 PM by Ofnuts.)
(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:
Posts: 939
Threads: 93
Joined: Oct 2016
Reputation:
36
Operating system(s):
- Windows (Vista and later)
Gimp version: 2.10
10-30-2016, 09:54 PM
(This post was last modified: 10-30-2016, 10:01 PM by Espermaschine.)
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.
Posts: 6,366
Threads: 276
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 3.00RC1
10-30-2016, 11:04 PM
(This post was last modified: 10-30-2016, 11:21 PM by Ofnuts.)
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?
Posts: 6,366
Threads: 276
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 3.00RC1
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?
Posts: 939
Threads: 93
Joined: Oct 2016
Reputation:
36
Operating system(s):
- Windows (Vista and later)
Gimp version: 2.10
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.
Posts: 6,366
Threads: 276
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 3.00RC1
Still can't tell what is wrong on your system and not on mine
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?
|