RSS/Atom feed Twitter
Site is read-only, email is disabled

Turn black background into white -- with fuzzy edges

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

6 of 6 messages available
Toggle history

Please log in to manage your subscriptions.

Turn black background into white -- with fuzzy edges Lea Wiemann 26 Nov 09:59
  Turn black background into white -- with fuzzy edges Owen 26 Nov 10:57
   Turn black background into white -- with fuzzy edges Dave 77459 26 Nov 15:14
  Turn black background into white -- with fuzzy edges David Gowers 26 Nov 10:58
   Turn black background into white -- with fuzzy edges Lea Wiemann 27 Nov 02:17
  Turn black background into white -- with fuzzy edges Pere Pujal i Carabantes 26 Nov 18:50
Lea Wiemann
2007-11-26 09:59:23 UTC (about 17 years ago)

Turn black background into white -- with fuzzy edges

Hi,

I'd like to turn a black background into white, or transparency (in which case it should look cut if displayed on a white background). My practical use case is photos of objects with black backgrounds that I'd like to improve for Wikipedia. The problem is that the boundary between background and object is usually fuzzy.

I've created a pair of example images (attached): Say I start off with the image fuzzy-circle.png (a gray-patterned circle on a black background); what I would like to get is something like fuzzy-circle-goal.png (the gray-patterned circle on a white background) -- but that seems pretty hard to achieve: If I "select by color: black" and then cut the selection, the corners look either aliased/"too sharp" (for high thresholds in the select-by-color tool), or they have dark pixels in them (for low thresholds). Selecting the black background, growing the selection (2px), feathering it (2px), and then cutting the selection *kinda* works, but it cuts off the blurry part of the object boundary.

Any ideas on this one?

Best wishes,

Lea

Owen
2007-11-26 10:57:07 UTC (about 17 years ago)

Turn black background into white -- with fuzzy edges

On Mon, 26 Nov 2007 03:59:23 -0500 Lea Wiemann wrote:

Hi,

I'd like to turn a black background into white, or transparency (in which case it should look cut if displayed on a white background). My practical use case is photos of objects with black backgrounds that I'd like to improve for Wikipedia. The problem is that the boundary between background and object is usually fuzzy.

I've created a pair of example images (attached): Say I start off with the image fuzzy-circle.png (a gray-patterned circle on a black background); what I would like to get is something like fuzzy-circle-goal.png (the gray-patterned circle on a white background) -- but that seems pretty hard to achieve: If I "select by color: black" and then cut the selection, the corners look either aliased/"too sharp" (for high thresholds in the select-by-color tool), or they have dark pixels in them (for low thresholds). Selecting the black background, growing the selection (2px), feathering it (2px), and then cutting the selection *kinda* works, but it cuts off the blurry part of the object boundary.

Any ideas on this one?

If you are using 2.4, Colours->Colour to alpha or in 2.2 Filters->Colours->Colour to alpha

After that, make a new layer and fill with whatever colour you want

Owen

David Gowers
2007-11-26 10:58:43 UTC (about 17 years ago)

Turn black background into white -- with fuzzy edges

Hi Lea,

On Nov 26, 2007 7:29 PM, Lea Wiemann wrote:

Hi,

I'd like to turn a black background into white, or transparency (in which case it should look cut if displayed on a white background). My practical use case is photos of objects with black backgrounds that I'd like to improve for Wikipedia. The problem is that the boundary between background and object is usually fuzzy.

There is no real good way to do this for arbitrary photos; For this particular photo, the best result I could achieve was by: 1. Use magic wand to select background 2. Convert the selection to a path, and convert the path back into a selection (this has the effect of smoothing the edges of the selection.. PoTrace produces better results than the GIMP sel2path plugin, I assume you have to work with standard GIMP plugins only though.)
3. Fill with white.

The result of applying this is attached.

Notably this shows a smooth black outline around the object. The method I tried to convert white to black without causing an outline effected the overall color of the object too much instead. (this method was: 1. layers->transparency->color to alpha (select black); 2. flatten with bgcolor = white.)

Dave 77459
2007-11-26 15:14:02 UTC (about 17 years ago)

Turn black background into white -- with fuzzy edges

On Nov 26, 2007 3:57 AM, Owen wrote:

On Mon, 26 Nov 2007 03:59:23 -0500 Lea Wiemann wrote:

Any ideas on this one?

If you are using 2.4, Colours->Colour to alpha or in 2.2 Filters->Colours->Colour to alpha

After that, make a new layer and fill with whatever colour you want

Owen

I don't know if that satisfies her need, but it is a useful technique I did not know about but will use extensively. Thank you.

Dave

Pere Pujal i Carabantes
2007-11-26 18:50:32 UTC (about 17 years ago)

Turn black background into white -- with fuzzy edges

El dl 26 de 11 del 2007 a les 03:59 -0500, en/na Lea Wiemann va escriure:

Hi,

I'd like to turn a black background into white, or transparency (in which case it should look cut if displayed on a white background). My practical use case is photos of objects with black backgrounds that I'd like to improve for Wikipedia. The problem is that the boundary between background and object is usually fuzzy.

I've created a pair of example images (attached): Say I start off with the image fuzzy-circle.png (a gray-patterned circle on a black background); what I would like to get is something like fuzzy-circle-goal.png (the gray-patterned circle on a white background) -- but that seems pretty hard to achieve: If I "select by color: black" and then cut the selection, the corners look either aliased/"too sharp" (for high thresholds in the select-by-color tool), or they have dark pixels in them (for low thresholds). Selecting the black background, growing the selection (2px), feathering it (2px), and then cutting the selection *kinda* works, but it cuts off the blurry part of the object boundary.

Any ideas on this one?

I am doing a script that might help you. It is not specyfic to your purpose but hope it helps.

Install mktpstamp.scm from here to your gimp-version/scripts directory http://fornol.no-ip.org/linux/tuxpaint/scripts Then open Gimp

Select by fuzzy select or by color black with threshold 50 Show the layers dialog.
add a layer mask inverted from selection You get something like fuzzy-circle-darks-pixels.png you posted Active the image, not the mask, add an alpha channel to it. Select by fuzzy select or by color black with threshold 50 grow the selection by the number of pixels needed to cover the dark ones.(1 or 2)
CTRL X to delete all the selection.
You get a image that lacks the edge pixels, they will be regenerated from the current edges when running the script.

Run mktpstamp (It appears in filters artistic in gimp 2.4.x or in script-fu alquemy on 2.2.xx)
Uncheck Scale Create .txt file and Create .dat file If you are confident, select a proper filename and keep Save and close. This will make a transparent .png file Else
Change Save and close to Don't save and keep for editing. This will make a new image with 4 layers A backup layer two contrast layers and the working layer. You can then make the contrast layers visible/invisible by turn to check if there is any weird effect.

When happy fill the green contrast layer with wite or any color you want, flat the image and save.

If you want transparency, do a new image from the top layer(just drag the layer to the toolbox) and save it.

More instructions to run it you can find at http://sourceforge.net/mailarchive/forum.php?thread_name=1185622883.26911.151.camel%40hola.fou.net&forum_name=tuxpaint-devel

BTW any comments on how to improve it are welcome.

Best wishes,

Lea

Yours
Pere

Lea Wiemann
2007-11-27 02:17:39 UTC (about 17 years ago)

Turn black background into white -- with fuzzy edges

David Gowers wrote:

On Nov 26, 2007 7:29 PM, Lea Wiemann wrote:

I'd like to turn a black background into white [...] The problem is that the boundary between background and object is usually fuzzy.

1. Use magic wand to select background 2. Convert the selection to a path, and convert the path back into a selection
3. Fill with white.

Notably this shows a smooth black outline around the object.

Cool, thanks a lot! If I grow the resulting selection by 1px before filling with white, I get a very smooth edge without any dark outline (attached). It makes me lose the very outermost pixels of the edge of the object, but I think I can live with that. (In more complex images I found that that the paths needed manual fine-tuning, but it's still fast enough.)

Best wishes,

Lea