1

I found this guide, but some reason, that only works for some colors, but not for others? What can I do?

Here is a sample image:

enter image description here

And here is what it looks like if I do the inversion:

enter image description here

Note how the red-yellow line doesn't change, but the green-yellow line gets a completely new color profile.

5 Answers 5

1

Here's another method, which involves the use of the Foreground Select tool to make a mask. Also inverting the original image is problematic, so I'm also going to use the Clone Stamp tool to remove the inverted coloured lines. This will change parts of the background, so they won't be exactly the same as the original. Note this method involves quite a bit of manual work (painting), so if you are looking for a fully automatic method, then it's probably not ideal for you.

  1. Duplicate the original so you have two layers, select the top layer

  2. Using the Foreground Select tool, make a rough lasso around the coloured lines.

  3. Hit Enter, then paint with the tool inside the lines. This doesn't have to be exact. My lines are all wobbly in the example below and it doesn't matter.

You want to end up with something like this

enter image description here

  1. Hit Select, and now you will have a selection around the coloured lines

  2. Add a layer mask, choose to initiate the mask from the selection

  3. Temporarily hide the top layer

  4. Select the bottom layer, and invert it.

  5. Use the Clone Stamp tool to clone out the lines using another part of the background as the clone source. Use a soft edged brush with this tool.

  6. Unhide the top layer, and select the layer mask thumbnail in the layers panel

  7. Add a 1px gaussian blur to the mask, and then open the Curves, and make a curve like this. This will help erase some of those outer pixels which are problematic.

enter image description hereClick to see larger

Here's the result at 100%

enter image description here

3
  • That's pretty nice! The only thing that wouldn't really work for me is how you select the lines. In this example it's easy enough, but in my actual images I have many many more lines. Doing this manually wouldn't work. Is there no way to automate this? If I'm not mistaken, in your previous answer, you isolated the lines in the top group. Wouldn't it be possible to use that layer and do something like mask all?
    – mapf
    Apr 6 at 17:30
  • @mapf - Maybe you could try, but I really think you will still end up having to do at least some manual work, such as cleaning up the mask and the background. Part of the real problem here is that you are trying to separate a flat image to different layers so you can invert the background separately from the foreground. This is always going to pose some difficulties, particularly when the background is complex. The ideal way to do this would of course be to use a layered file with everything on separate layers to begin with.
    – Billy Kerr
    Apr 6 at 22:33
  • I see, thank you! That's exactly the problem. I typically only work with svg nowadays, but this is older data that I was trying to adjust a bit.
    – mapf
    Apr 7 at 14:09
1

Try something like this:

  • Put your image in a group (bottom group in screenshot below)
  • Add a white layer below it
  • Set the image layer to LCH Lightness mode
  • The result of the group is a grayscale version of the image
  • Layer > New from visible to "freeze" that result
  • Color > Invert for a negative version
  • Add a second group (top group in screenshot)
  • Add a copy of your initial image in it
  • Add the inverted layer above it in the group
  • Set the inverted layer to LCH Lightness mode

enter image description here

But remember that Lightness isn't color-independent, for our eyes it comes mostly from the green component.

Edit: there is even a way to avoid the "new from visible" (layer modes in parentheses when different from "Normal"):

enter image description here

1
  • Hi, thanks a lot! I tried to follow your steps several times now, but I just don't get the correct result. Now the colors of both lines changed. I'm not sure what I am doing wrong. Did you try my image?
    – mapf
    Apr 5 at 15:48
1

I tried only to write a comment, so do not consider this as an answer. But only those users who have established some reputation can write comments. Moderator's job is to remove non-answers, but hopefully you read this before it happens.

The brightness of the blending result is taken from the bottom layer. The yellow darkened because there's dark blue below it in the bottom layer. Those colors which were about 50% of the max brightness in the original stayed as bright in the inversion, so in the blending they kept their brightness.

Your original image is unsharp. If you look it with high zoom in, you see there's in the edge of the colored area a zone where the colors and the uncolored background have mixed to less colored but not fully to greyshades.

You may have tried to create it as sharp, but your tools have smudged the edges automatically to prevent the common apparent jagginess of non-antialised low resolution images.

No color based selection criteria can fully succeed to separate which pixels should be inverted and which should not. If you bother to experiment a little with on color based selections like already suggested in a given answer, you'll find settings which leaves less dark pixels to the edge. But you can be sure that then there's some inverted colored pixels.

A clever enough program might guess the perfectly sharp gradient fill vector shapes which theoretically were the idealized forms of your colored shapes. That clever software could fix the edge zone exactly. Unfortunately GIMP does not have such functionality. I do not know if such automatic tool is available somewhere.

1
  • Hi, thanks a lot for your explanation! I really appreciate it. I hope it won't get deleted because it's valuable information.
    – mapf
    Apr 6 at 8:20
1

Here's one possible method. It's not perfect since there will still be some black pixels left over around the coloured lines, but it's not bad when viewed at 100%. Unfortunately, there is some anti-aliasing in the original around the coloured lines, so this is kind of unavoidable.

Anyway . . .

  1. Duplicate the image layer twice, so you have three copies of the image

  2. Invert the bottom layer

  3. Desaturate the top layer

  4. Put the desaturated and original layers into a layer group

  5. Select the desaturated layer, and set the layer blending mode to Color Erase

enter image description here

3
  • Thank you! I think this is the best result so far, and if I understand correctly, there is really no way for it to work much better than this.
    – mapf
    Apr 6 at 8:25
  • There may be other ways to do this @mapf - or perhaps ways to improve this result, but it will definitely take more work. Getting perfect extractions from a complex background in a flat image file is not an easy thing to do in any raster image editor, even Adobe Photoshop. Quality-wise, something usually always has to give.
    – Billy Kerr
    Apr 6 at 9:52
  • @mapf - I've also added another answer now, for a completely different method to avoid the black pixels.
    – Billy Kerr
    Apr 6 at 11:16
1

Possibly misunderstood the question in previous answer:

Quick and somewhat dirty method:

Use the Color selector, and set the "Select by" criterion to HSV saturation or LCH chroma. Then click anywhere on the background. This will only select pixels with a very low saturation, ie, the grayscale ones.

Then Color > Invert. However, this leaves a few pixels untouched around the color bars.

enter image description here

PS: The problem with the answer you point to is that the "Color" blend mode (or its equivalents in 2.10, HSL Color and LCH Color) keep the value of the underlying layer, so you start with for instance a light green, the Color > Invert transforms it to a dark purple, and then the Color blend mode transforms the dark purple into... a dark green, because it won't change the value.

To be more specific, use the Pointer dialog to check the "V" Component in the HSV model at the ends of the two lines:

Initial image:

      Red -> yellow:-> 100 -> 100
Turquoise -> yellow:->  50 -> 100

After Color > Invert:

      Red -> yellow:-> 100 -> 100
Turquoise -> yellow:->  97 ->  60

So, no big change of Value in the first bar, but a swap of values in the other one. Applying HSV Color:

      Red -> yellow:-> 100 -> 100
Turquoise -> yellow:->  97 ->  60

HSV Color applied Hue/Saturation, but didn't change the Value, so the luminosity gradient in the turquoise-yellow bar remains inverted. You get similar results if you use LCh instead of HSV.

2
  • Thank you! I didn't expect that this would be such a difficult problem. Why does the approach that I link to work with the yellow-red line though?
    – mapf
    Apr 5 at 18:14
  • See augmented answer. Basically, luck :-)
    – xenoid
    Apr 5 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.