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

how to invert greyscale values only...

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.

10 of 10 messages available
Toggle history

Please log in to manage your subscriptions.

how to invert greyscale values only... Cédric Gémy 02 Feb 23:58
  how to invert greyscale values only... Rich Evans 03 Feb 01:54
   how to invert greyscale values only... Ken Warner 03 Feb 02:12
    how to invert greyscale values only... Rich Evans 03 Feb 15:55
     how to invert greyscale values only... Andrew 03 Feb 16:08
     how to invert greyscale values only... yahvuu 04 Feb 10:31
      how to invert greyscale values only... Rich Evans 04 Feb 13:39
       how to invert greyscale values only... yahvuu 05 Feb 15:05
   how to invert greyscale values only... Owen 03 Feb 04:45
how to invert greyscale values only... Cédric Gémy 04 Feb 09:41
Cédric Gémy
2010-02-02 23:58:51 UTC (almost 15 years ago)

how to invert greyscale values only...

not completely satisfied with sven's method, working on some pictures but not any, depending on the shades. I used to do it in CMYK a long time ago with photoshop by just pushing the image to CMYK and inverting the K curve. I guess something might be done with decompose color filter or so. But the quicker/best average i've found is just adding a mask based on the layer (L from Lab or N form CMYK could be used too), and play with the curve to adapt to the shades+refine with brush on mask. It takes few seconds if the picture is not too complex. Then put a white layer below and it's quite done.
But i'm not completely satisfied with it.

Rich Evans
2010-02-03 01:54:09 UTC (almost 15 years ago)

how to invert greyscale values only...

I'm grateful for the replies I have received, but I was thinking that if there isn't a well-known tool or method already, that maybe someone could point me to a site that describes how custom filters can be made from scratch. I'm not afraid to learn what I need to to make the filter, ...I've just never done it before. *grin* I just need someone to point me to a decent tutorial (I can do c programming if that's what it is, but my working assumption is that, all things being equal, it should be easier to make a filter for GIMP than it would be to write a c program from scratch).Would anyone consider this... easy?

continue thanks, -Rich

----- Original Message ---- From: Cédric Gémy
To: Gimp-user@lists.XCF.Berkeley.EDU Sent: Tue, February 2, 2010 5:58:51 PM Subject: Re: [Gimp-user] how to invert greyscale values only...

not completely satisfied with sven's method, working on some pictures but not any, depending on the shades. I used to do it in CMYK a long time ago with photoshop by just pushing the image to CMYK and inverting the K curve. I guess something might be done with decompose color filter or so. But the quicker/best average i've found is just adding a mask based on the layer (L from Lab or N form CMYK could be used too), and play with the curve to adapt to the shades+refine with brush on mask. It takes few seconds if the picture is not too complex. Then put a white layer below and it's quite done.
But i'm not completely satisfied with it.

Ken Warner
2010-02-03 02:12:09 UTC (almost 15 years ago)

how to invert greyscale values only...

Colors -> Desaturate; Colors -> Invert

No?

Rich Evans wrote:

I'm grateful for the replies I have received, but I was thinking that if there isn't a well-known tool or method already, that maybe someone could point me to a site that describes how custom filters can be made from scratch. I'm not afraid to learn what I need to to make the filter, ...I've just never done it before. *grin* I just need someone to point me to a decent tutorial (I can do c programming if that's what it is, but my working assumption is that, all things being equal, it should be easier to make a filter for GIMP than it would be to write a c program from scratch).Would anyone consider this... easy?

continue thanks, -Rich

----- Original Message ---- From: Cédric Gémy
To: Gimp-user@lists.XCF.Berkeley.EDU Sent: Tue, February 2, 2010 5:58:51 PM Subject: Re: [Gimp-user] how to invert greyscale values only...

not completely satisfied with sven's method, working on some pictures but not any, depending on the shades. I used to do it in CMYK a long time ago with photoshop by just pushing the image to CMYK and inverting the K curve. I guess something might be done with decompose color filter or so. But the quicker/best average i've found is just adding a mask based on the layer (L from Lab or N form CMYK could be used too), and play with the curve to adapt to the shades+refine with brush on mask. It takes few seconds if the picture is not too complex. Then put a white layer below and it's quite done.
But i'm not completely satisfied with it.

Owen
2010-02-03 04:45:45 UTC (almost 15 years ago)

how to invert greyscale values only...

On Tue, 2 Feb 2010 16:54:09 -0800 (PST) Rich Evans wrote:

I'm grateful for the replies I have received, but I was thinking that if there isn't a well-known tool or method already, that maybe someone could point me to a site that describes how custom filters can be made from scratch. I'm not afraid to learn what I need to to make the filter, ...I've just never done it before. *grin* I just need someone to point me to a decent tutorial (I can do c programming if that's what it is, but my working assumption is that, all things being equal, it should be easier to make a filter for GIMP than it would be to write a c program from scratch).Would anyone consider this... easy?

continue thanks, -Rich

----- Original Message ---- From: Cédric Gémy
To: Gimp-user@lists.XCF.Berkeley.EDU Sent: Tue, February 2, 2010 5:58:51 PM Subject: Re: [Gimp-user] how to invert greyscale values only...

not completely satisfied with sven's method, working on some pictures but not any, depending on the shades. I used to do it in CMYK a long time ago with photoshop by just pushing the image to CMYK and inverting the K curve. I guess something might be done with decompose color filter or so. But the quicker/best average i've found is just adding a mask based on the layer (L from Lab or N form CMYK could be used too), and play with the curve to adapt to the shades+refine with brush on mask. It takes few seconds if the picture is not too complex. Then put a white layer below and it's quite done.
But i'm not completely satisfied with it.

If you look at http://www.gimp.org/tutorials/Color2BW/ I am pretty sure all those techniques can be scripted with with either scheme or python.

Owen

Rich Evans
2010-02-03 15:55:45 UTC (almost 15 years ago)

how to invert greyscale values only...

Ken --- close. but no cigar...
the steps: 1) Colors -> Desaturate; 2) Colors -> Invert leaves me with a greyscale image... all color is gone :-( I'm looking for a filter that will invert only black, white and grey pixels... leaving color saturated pixels alone.

Owen --- I will investigate the python solution. thanks for the advice.

All --- Maybe the best question to ask is this... where online should I go to learn about how GIMP filters are developed? I suppose once I learn how to make on filter.. I suspect I will quickly conjure up other filter ideas as well...

For completeness, my original question is this: I have an RGB image that is basically a black background with many colorful objects and white text. --- I'd like to invert the image so that it is a white background with black text but a simple invert inverts the colors in all the colored objects as well. Is there a technique or tool to invert any part of the image that is only a shade of grey? i.e. invert pixeils with a saturation of ~0 (if that is how you say it). I could imagine a filter that does a simple RGB invert for any pixel whose calculated RGB saturation value is below a set threshold. Does this type of tool/script exist?

continued thanks, -rich

----- Original Message ---- From: Ken Warner
To: Rich Evans
Cc: Gimp-user@lists.XCF.Berkeley.EDU Sent: Tue, February 2, 2010 8:12:09 PM Subject: Re: [Gimp-user] how to invert greyscale values only...

Colors -> Desaturate; Colors -> Invert

No?

Rich Evans wrote:

I'm grateful for the replies I have received, but I was thinking that if there isn't a well-known tool or method already, that maybe someone could point me to a site that describes how custom filters can be made from scratch. I'm not afraid to learn what I need to to make the filter, ...I've just never done it before. *grin* I just need someone to point me to a decent tutorial (I can do c programming if that's what it is, but my working assumption is that, all things being equal, it should be easier to make a filter for GIMP than it would be to write a c program from scratch).Would anyone consider this... easy?

continue thanks, -Rich

----- Original Message ---- From: Cédric Gémy
To: Gimp-user@lists.XCF.Berkeley.EDU Sent: Tue, February 2, 2010 5:58:51 PM Subject: Re: [Gimp-user] how to invert greyscale values only...

not completely satisfied with sven's method, working on some pictures but not any, depending on the shades. I used to do it in CMYK a long time ago with photoshop by just pushing the image to CMYK and inverting the K curve. I guess something might be done with decompose color filter or so. But the quicker/best average i've found is just adding a mask based on the layer (L from Lab or N form CMYK could be used too), and play with the curve to adapt to the shades+refine with brush on mask. It takes few seconds if the picture is not too complex. Then put a white layer below and it's quite done. But i'm not completely satisfied with it.

Andrew
2010-02-03 16:08:32 UTC (almost 15 years ago)

how to invert greyscale values only...

Rich Evans wrote:

Ken --- close. but no cigar...
the steps: 1) Colors -> Desaturate; 2) Colors -> Invert leaves me with a greyscale image... all color is gone :-( I'm looking for a filter that will invert only black, white and grey pixels... leaving color saturated pixels alone.

Owen --- I will investigate the python solution. thanks for the advice.

All --- Maybe the best question to ask is this... where online should I go to learn about how GIMP filters are developed? I suppose once I learn how to make on filter.. I suspect I will quickly conjure up other filter ideas as well...

Meanwhile (and bearing in mind you haven't let us see the image in question), would this work?:
Duplicate layer, invert bottom layer and cut all blacks and whites out of (transparent) top layer (of course, if there's a range of greys it gets more complicated).
Andrew

For completeness, my original question is this: I have an RGB image that is basically a black background with many colorful objects and white text. --- I'd like to invert the image so that it is a white background with black text but a simple invert inverts the colors in all the colored objects as well. Is there a technique or tool to invert any part of the image that is only a shade of grey? i.e. invert pixeils with a saturation of ~0 (if that is how you say it). I could imagine a filter that does a simple RGB invert for any pixel whose calculated RGB saturation value is below a set threshold. Does this type of tool/script exist?

continued thanks, -rich

----- Original Message ---- From: Ken Warner
To: Rich Evans
Cc: Gimp-user@lists.XCF.Berkeley.EDU Sent: Tue, February 2, 2010 8:12:09 PM Subject: Re: [Gimp-user] how to invert greyscale values only...

Colors -> Desaturate; Colors -> Invert

No?

Rich Evans wrote:

I'm grateful for the replies I have received, but I was thinking that if there isn't a well-known tool or method already, that maybe someone could point me to a site that describes how custom filters can be made from scratch. I'm not afraid to learn what I need to to make the filter, ...I've just never done it before. *grin* I just need someone to point me to a decent tutorial (I can do c programming if that's what it is, but my working assumption is that, all things being equal, it should be easier to make a filter for GIMP than it would be to write a c program from scratch).Would anyone consider this... easy?

continue thanks, -Rich

----- Original Message ---- From: Cédric Gémy
To: Gimp-user@lists.XCF.Berkeley.EDU Sent: Tue, February 2, 2010 5:58:51 PM Subject: Re: [Gimp-user] how to invert greyscale values only...

not completely satisfied with sven's method, working on some pictures but not any, depending on the shades. I used to do it in CMYK a long time ago with photoshop by just pushing the image to CMYK and inverting the K curve. I guess something might be done with decompose color filter or so. But the quicker/best average i've found is just adding a mask based on the layer (L from Lab or N form CMYK could be used too), and play with the curve to adapt to the shades+refine with brush on mask. It takes few seconds if the picture is not too complex. Then put a white layer below and it's quite done. But i'm not completely satisfied with it.

Cédric Gémy
2010-02-04 09:41:45 UTC (almost 15 years ago)

how to invert greyscale values only...

"Duplicate layer, invert bottom layer and cut all blacks and whites out of (transparent) top layer (of course, if there's a range of greys it gets more complicated)."

it's evident that this is the problem : i don't know about Rich's photo but the sample i use here have various flavors of blacks'. If it is not a simple Color2alpha should work to delete blacks and just add a white layer below :)

i guess this is not the case :)

Rich : Try Gmic Toolbox>Colors>Replace color select black as original and white as dest and play with smoothness. Is that good ?

!! It's not working exactly the same as Gimp's replace color!!

find gmic here : http://gmic.sourceforge.net/ this is a external filter addons with so many possibilities :)

pygmee

yahvuu
2010-02-04 10:31:19 UTC (almost 15 years ago)

how to invert greyscale values only...

hi,

Rich Evans wrote:

[..] Is there a
technique or tool to invert any part of the image that is only a shade of grey? i.e. invert pixeils with a saturation of ~0 (if that is how you say it).

The on-board tools are just fine for this.

"Do something to some pixels (here: invert) and leave the rest unchanged" translates to: duplicate the layer, do that something and apply a suitable layer mask.

Where the layer mask is white, the modified pixels from the top layer are visible, otherwise the unchanged pixels from the bottom layer show through.

So a layer mask is needed which equates the image's saturation, such that it is white (= show inverted pixels) where the saturation is zero (or close to zero).

The saturation gets calculated during conversion to the HSV color model: Color->Components->Decompose delivers a "saturation" layer. The lighter this layers is, the more saturation the corresponding image pixel has.

In consequence, it must be inverted. To further mask out image pixels, which are not close to a saturation of 0, a threshold of 254 can be applied. (More on that later).

Using this layer as a layer mask for the "inverted" layer will reveal wether this train of thought is correct...

The steps:

1. Create inverse copy of picture

Duplicate the picture layer

Invert that new layer

2. Create HSV color separation

Select picture layer and do Colors->Components->Decompose ("color model HSV"), which creates a new image.

Copy the "saturation" layer to your original image. (simply drag the layer from the layers dialog to the image window.)

Invert that new layer

(for better finetuning, we'll do the thresholding later)

3. Turn saturation layer into a layer mask for the inverted picture

somebody please help out and insert a sane way to copy a layer to another layer's mask

With saturation layer: Add Layer Mask ("Grayscale copy of layer")

Mask to Selection

Delete the saturation layer (all required information is in the selection mask)

With the "inverted picture" layer:

Add Layer Mask ("Selection")

Select->None

now we're basicly done

4. Fine-tuning of layer mask

Select newly created layer mask

According to the question, now a Colors->Threshold of 254 should be applied, but
Color->Levels and dragging the middle slider to the right gives better control.

Don't expect the saturation mask to be perfect, some rounding errors due to 8bit resolution might show up.

have fun, peter

Rich Evans
2010-02-04 13:39:38 UTC (almost 15 years ago)

how to invert greyscale values only...

That's it! Perfect. Thanks Peter. (and my printer's black ink cartridge thanks you - heh heh) Not only is this an exact solution for my goal, but you have also taught me how to think more properly about the nature of the problem from the perspective of GIMP as a tool whereas I was coming at it from the brute force programmers way.

Thanks everyone for helping me. I really appreciate it.

In lieu of being able to buy everyone who helped a round of beer, is there a way for me to show my gratitude to the GIMP community? Would a donation to GIMP help you guys?

-rich

----- Original Message ---- From: yahvuu
To: Rich Evans
Cc: Gimp-user@lists.XCF.Berkeley.EDU Sent: Thu, February 4, 2010 4:31:19 AM Subject: Re: [Gimp-user] how to invert greyscale values only...

hi,

Rich Evans wrote:

[..] Is there a
technique or tool to invert any part of the image that is only a shade of grey? i.e. invert pixeils with a saturation of ~0 (if that is how you say it).

The on-board tools are just fine for this.

"Do something to some pixels (here: invert) and leave the rest unchanged" translates to: duplicate the layer, do that something and apply a suitable layer mask.

Where the layer mask is white, the modified pixels from the top layer are visible, otherwise the unchanged pixels from the bottom layer show through.

So a layer mask is needed which equates the image's saturation, such that it is white (= show inverted pixels) where the saturation is zero (or close to zero).

The saturation gets calculated during conversion to the HSV color model: Color->Components->Decompose delivers a "saturation" layer. The lighter this layers is, the more saturation the corresponding image pixel has.

In consequence, it must be inverted. To further mask out image pixels, which are not close to a saturation of 0, a threshold of 254 can be applied. (More on that later).

Using this layer as a layer mask for the "inverted" layer will reveal wether this train of thought is correct...

The steps:

1. Create inverse copy of picture

Duplicate the picture layer

Invert that new layer

2. Create HSV color separation

Select picture layer and do Colors->Components->Decompose ("color model HSV"), which creates a new image.

Copy the "saturation" layer to your original image. (simply drag the layer from the layers dialog to the image window.)

Invert that new layer

(for better finetuning, we'll do the thresholding later)

3. Turn saturation layer into a layer mask for the inverted picture

somebody please help out and insert a sane way to copy a layer to another layer's mask

With saturation layer: Add Layer Mask ("Grayscale copy of layer")

Mask to Selection

Delete the saturation layer (all required information is in the selection mask)

With the "inverted picture" layer:

Add Layer Mask ("Selection")

Select->None

now we're basicly done

4. Fine-tuning of layer mask

Select newly created layer mask

According to the question, now a Colors->Threshold of 254 should be applied, but
Color->Levels and dragging the middle slider to the right gives better control.

Don't expect the saturation mask to be perfect, some rounding errors due to 8bit resolution might show up.

have fun, peter

yahvuu
2010-02-05 15:05:27 UTC (almost 15 years ago)

how to invert greyscale values only...

Rich Evans wrote:

That's it! Perfect.

glad to hear it works as expected. Just want to add that the programmer's route, aka doing it by the math, is quite viable, too. Some selected options:

- the MathMap plugin probably enables the most concise solution: http://www.complang.tuwien.ac.at/schani/mathmap/

- with knowledge in C, it's not a big step to prototype using either Lua (the gluas plugin) or the built-in python-fu.

- a plain C plugin gives the best processing speed at the price of the slowest development cycle.

In lieu of being able to buy everyone who helped a round of beer, is there a way for me to show my gratitude to the GIMP community? Would a donation to GIMP help you guys?

New contributors are always welcome! There are plenty of opportunities to help the project, by far it's not just about coding [1]. And posing useful problems here is already helpful, too. Of course, donations are always welcome [2].

regards, peter

[1] http://www.gimp.org/develop [2] http://www.gimp.org/donating