10

I know how to Invert Colors but is it possible to swap Colors? For example from this one:

enter image description here

To this one:

enter image description here

So that I select one Area and then swap Colors (or even the full Layer/Picture)? By the way I am using Gimp 2.8.10

-Edit: I found this https://superuser.com/questions/155143/how-can-i-swap-colors-with-gimp but this is just for one Color and didnt work for me with the different color tones of transparency and it just works with one color at a time, where I need both colors swapped.

7
  • Could you please explain the downvote?
    – user29421
    Sep 18, 2014 at 8:05
  • 1
    Question shows no effort. If you hover your mouse over the down arrow, you can see why down votes happen.
    – Scott
    Sep 18, 2014 at 8:18
  • @Scott, I didn't know that.
    – Rosenthal
    Sep 18, 2014 at 21:13
  • 1
    Your goal is a bit unclear. Do you want to swap the colors on a true color image or on a paletted one? In this case you can simply edit the palette, it's a very quick operation. Sep 19, 2014 at 21:31
  • I need to swap the two colors in a selected area
    – user29421
    Sep 19, 2014 at 21:33

5 Answers 5

8

In such a simple image, not very difficult. The basic principle is that the text is made of pixels of varying opacity (fully opaque for most, but partially opaque on the edges) overlaying a background. So what we need to do is to recover that opacity, and use it when repainting with new colors. Note that this technique works to change foreground/background to any color, not just to exchange them.

So, starting with:

Initial

We use Colors>Color to alpha to remove the background color. The remaining pixels have exactly the opacity necessary to recreate the text:

after color-to-alpha

We can then paint with the same opacity by setting the alpha-lock on the layer. The alpha-lock is the checkerboard icon in the "lock" line at the top of the Layers list. When it is set, the opacity of the pixels cannot change. So we can bucket fill the whole layer with the new color, the color will only "stick" on the opaque pixels (and stick partially on the partially opaque pixels):

after bucket fill with alpha-lock

To fill the background, we could just add a layer filled with the new background color, move it to the bottom of the stack and merge everything, but there is a faster method: use the Behind mode of the bucket-fill tool (the "mode" is the selector at the top of the Tool options). In that mode, paint tools only fill transparent pixels, partially fill partially opaque pixels to "complement to opacity" with the new color, and leave alone the opaque pixels. As the name implies, it is equivalent to painting on a layer behind the selected layer, so after resetting the alpha-lock (because this time we change the opacity of pixels), just bucket-fill the whole layer with the new background color:

enter image description here

The images at their actual size:

enter image description here

7

If you have more than a few, but less than 256 colors, you can work in indexed mode and reverse the ordering of the colors.

This can be done in 3 steps:

  1. duplicate and store palette
  2. reverse ordering of colormap
  3. apply the stored palette

Here a detailed explanation of these 3 steps:

  1. Palettes dialog (Windows -> Dockable dialogs -> Palettes): right click on the current colormap, select "Duplicate Palette", choose a new name (e.g. original palette), and save it.
  2. Rearrange Colormap (Colors -> Map -> Rearrange Colormap): right click, then click on "Reverse order", click ok.
  3. Set Colormap (Colors -> Map -> Set Colormap): click on the Palette and select the palette saved in step 1, click ok.
3
  • For anyone who runs into the same problem as I did: GIMP opened the palette chooser in the background (in step 3). That's why I got stuck at first, but in the end it worked out fine.
    – twigmac
    Feb 9, 2018 at 9:57
  • Make sure the image mode is "indexed", or the Rearrange Colormap option will be disabled. You can change image mode from: Image > Mode. Sep 2, 2019 at 14:48
  • I don't see "current colormap". Jul 26, 2020 at 19:52
2

There is a filter in Photoshop called Selective Color that allows the user to modify multiple colors at the same time, but until 9/18/2014 nothing similar has been implemented in Gimp. The closest tool in Gimp to deal with what you are looking for is the Channel Mixer.

0

If the image has few pixels as this one, and would not suffer loss on being changed to indexed (max. 256 colors), you can edit an image color map directly. That way you could just select the pixels in the color you want to replace, and type a new value for them.

Change the image to indexed in image->mode->indexed, and them open the colormap dialog in windows->dockable dialogs->colormap. Double click on an indexed color to change it.

0

This is an elaboration that I've found to be useful for swapping nuances in some cases, complex or simple. Copy original image to layer. From menu: Color - Invert (or Linear Invert) The colors will be totally wrong but don't worry... Next, go to Color Map Sample Colorize and sample from the Image with the original colors. (You pick that one to the right next to Sample. Click Get Sample Colors. Uncheck Smooth samples, and probably uncheck Original Intensity but keep Hold intensity. Tweak the Input levels. With some tweaking it is also possible to change green G on white background to white G on green background as in the example above.

1
  • Welcome to GDSE! That sounds like a great solution, could you edit to add screenshots and examples?
    – Alith7
    Nov 3, 2020 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy