It is currently Thu Apr 25, 2024 2:17 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 19 posts ] 
Author Message
 Post subject: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Sun May 03, 2015 7:05 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: May 03, 2015
Posts: 13
Location: Genova, Italy
Hello, and sorry for my bad English
I am a GIMP user and amateur photographer, who likes to experiment with picture.

I was thinking about an effect like "color accent", but graduated by the difference between the accented color and the other colors of the image, instead of emphasize only the chosen color.

I tried to write a little program in Java to do it, but, in addition to never having worked with images, I realized that my programming skills are very rusty (the last time I followed the design of a program from scratch, Java was something new and I still use the Turbo Pascal...). So here I am.

I want to ask if someone can write (or if there is already) a plug-in that do the following things:

Take an “Input” image and the Gimp Foreground color

For every pixel of the image calculate the “euclidean distance” between RGB value of the pixel and the one of the Foreground color (these values will be used again, so it might be useful to store them into a matrix [width * height] to avoid to recalculate, we can call it DistanceMtx), and put the max value found in a variable (in the following Max_distance).

Create a new “Output” image (or a new layer), where, for every pixel[x,y], we have (HSL color model):

OutputL[x,y] = InputL[x,y]
OutputH[x,y] = InputH[x,y]
OutputS[x,y] = InputS[x,y]*(1- DistanceMtx[x,y]/Max_distance)


(obviously a control is needed for images with uniform color that is the same of Foreground Color, they would have "Max_distance" = 0 and DistanceMtx[x,y]=0 for every x and y, so we have 0/0)

The color near the chosen one maintains the same saturation, the most “far” colors become very desaturated (if they already have a low saturation value, they become shades of gray).

An additional option could be the use Lightness (from HSL) difference instead of RGB euclidean distance (the ones much lighter or much darker become gray).

Other option can be:
* Use the max saturation value (100?) as max instead of the original one of the pixel
OutputS[x,y]=100 *(1- DistanceMtx[x,y]/Max_distance)

* Use the Foreground Color saturation value instead of the original one of the pixel (no pixel in Output image/layer with saturation higher of the Foreground Color)
OutputS[x,y]=ForegroundS *(1- DistanceMtx[x,y]/Max_distance)

Someone wants to help?

greetings
Alessio


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Mon May 04, 2015 6:32 am  (#2) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
That is an interesting idea for a plug-in. While I don't have the time to write one currently, until someone comes along to write it I would suggest the following technique that should get you pretty close to the same result in many situations.

  • Start by duplicating your original layer (I used this one from Wikipedia)
  • Use the eyedropper :colpick to set the FG color to your reference (I choice the color of the bridge)
  • Create a new layer filled with that FG color
  • Set the layer mode of the new layer to "Difference"
  • Perform "Layer->New From Visible"
  • Delete your FG color layer

You should now have a setup similar to the following:
Attachment:
SS-gradual-desat1.jpg
SS-gradual-desat1.jpg [ 190.21 KiB | Viewed 3420 times ]

  • Desaturate the new visible layer using the "Average"
  • Perform "Colors->Auto->White Balance" on the layer
  • Perform "Edit->Cut" (this will remove the new layer)
  • Add a layermask to the duplicate layer that was created in the first step
  • Paste your cut buffer into the layermask (remember to anchor it)

Attachment:
SS-gradual-desat2.jpg
SS-gradual-desat2.jpg [ 172.26 KiB | Viewed 3420 times ]
You should be left with two layers: your original layer and one above it with a layermask. The layermask should reveal the original layer where the colors are close* to your FG color. This means you can desaturate the top layer to get a gradual desaturate. Better still might be to use the Hue-Saturation filter to decrease the saturation of the upper layer. You also have the option of using Hue-Saturation on the original (bottom) layer to increase its saturation.


* The color difference determined by this approach is not the euclidian distance (which would be the square root of the sum of the three channel differences) but the average of the sum of the three channel differences. Without actually writing a plug-in -- or using G'Mic or Mathmap -- I can't think of a way to incorporate euclidian distances using stock GIMP functionality.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Mon May 04, 2015 5:13 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: May 03, 2015
Posts: 13
Location: Genova, Italy
Thanks! :bigthup

I made some try, the result isn't exactly what I have in mind, but they are near.

I'm will made some other test playng a little with the contrast of the mask with Curves, to simulate an increase of the "distance" value.


Attachments:
File comment: Original
DSCI1955a.jpg
DSCI1955a.jpg [ 1.11 MiB | Viewed 3330 times ]
File comment: Color (the brown tower above the house)
DSCI1955c.jpg
DSCI1955c.jpg [ 1.06 KiB | Viewed 3330 times ]
File comment: "Desaturated"
DSCI1955b.jpg
DSCI1955b.jpg [ 1.1 MiB | Viewed 3330 times ]
Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Tue Jul 14, 2015 9:37 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: May 03, 2015
Posts: 13
Location: Genova, Italy
I have made some experiments with scripts (well... mostly "Frankenstein" experiments inspired by others scripts and examples), and i wrote something that reproduce the method saulgoode has suggested to me.

This is the result
Attachment:
relative-desat.scm [4.23 KiB]
Downloaded 113 times


I start by saying that was written in 2 1/2 hours, does not have any form of control on possibile error on the source layer and probably also badly programmed, but it works, so if someone wants to play with it...

After you apply it there are 3 layers, all in "Normal" mode:

* SourceDesat: the original one, at the bottom of the layers stack

* DecrSat: the layer with the layermask and the decreased (or increased) saturation (and lightness), at the top of the layers stack

* IncrSat: a layer that can be used to increase (or decrease) saturation (and lightness), below DecrSat

The control parameters are 5, saturation and lightness change value of DecrSat and IncrSat, and a value to increase or decrease the contrast of the layermask of DecrSat, to make more or less pronounced the effect.

The color to create the mask is taken from Foreground Color.

I try to put a control to eventually change it, using Foreground as default, but I fail. Many script i see on the net use "SF-COLOR xxxxxxx (car (gimp-context-get-foreground))", but if I try in the control seem to be always black, independently from the Gimp Foreground Color.

And thanks again for the tips!


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Tue Jul 14, 2015 10:35 pm  (#5) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
cool techniques! :cool

_________________
TinT


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 12:11 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: May 03, 2015
Posts: 13
Location: Genova, Italy
Best results are with images that contain very different and saturated colors

Attachment:
01.png
01.png [ 1.73 MiB | Viewed 3070 times ]


Attachment:
02.png
02.png [ 926.47 KiB | Viewed 3070 times ]


Attachment:
03.png
03.png [ 1.94 MiB | Viewed 3070 times ]


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 2:20 am  (#7) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
this is fun to play with
original:
Image

i decomposed image into HSL and used the H layer and selected a H value of yellow flowers and differenced it from H layer and used that as a mask and got this:
Image

_________________
TinT


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 2:29 am  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
Hi Alessio,

I might help for this. I've implemented what you describe, with an additional parameter 'amplitude' (let's call it 'A'), so that I compute :

OutputL[x,y] = InputL[x,y]
OutputH[x,y] = InputH[x,y]
OutputS[x,y] = InputS[x,y]*(1- DistanceMtx[x,y]/Max_distance)^A

It gives you more control on the amplitude of the effect applied.
I've uploaded the filter in the G'MIC plug-in for GIMP, as you can see below. Maybe you could try to install G'MIC and test the filter, and tell me
if that is what you expect ?

Attachment:
gmic_gca.png
gmic_gca.png [ 358.21 KiB | Viewed 3054 times ]


So far, here is the script I've written for that effect. It's done in the G'MIC scripting language, so not really easy to read, but really fast to do :)
Link to the script : http://pastebin.com/VDNRpGCV

EDIT : I've inverted the amplitude control, now the more amplitude, the more desaturated colors you get.


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 2:59 am  (#9) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
I think I'll stick to doing it via the Saturation Curve in Photivo:
Attachment:
Untitled.png
Untitled.png [ 871.37 KiB | Viewed 3047 times ]

Kevin


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 3:06 am  (#10) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
yoggysot wrote:
I try to put a control to eventually change it, using Foreground as default, but I fail. Many script i see on the net use "SF-COLOR xxxxxxx (car (gimp-context-get-foreground))", but if I try in the control seem to be always black, independently from the Gimp Foreground Color.

The problem is that the SF-COLOR value (indeed, the entire 'script-fu-register' procedure) only gets evaluated when the script is initially installed -- it is not re-evaluated when you run the installed command.

The colors is "always" black because black is the default foreground color when you first open GIMP (and script-fus are installed). Even if you change the foreground color before running the command, that initial SF-COLOR value stays the same (until you perform a "Filters->Script-fu->Refresh").


Your script is well written, however, I would caution against selecting your layers based on their names. When you set a layer name (using 'gimp-layer-new' for example), the actual layer name may not end up what you set it to; if the layer name is already used for another layer then GIMP will use a different name by appending a #nnn to the name you request. It is better to use the layerID of your layer whenever possible.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 9:43 am  (#11) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
Ronounours wrote:
Hi Alessio,

I might help for this. I've implemented what you describe, with an additional parameter 'amplitude' (let's call it 'A'), so that I compute :

OutputL[x,y] = InputL[x,y]
OutputH[x,y] = InputH[x,y]
OutputS[x,y] = InputS[x,y]*(1- DistanceMtx[x,y]/Max_distance)^A

It gives you more control on the amplitude of the effect applied.
I've uploaded the filter in the G'MIC plug-in for GIMP, as you can see below. Maybe you could try to install G'MIC and test the filter, and tell me
if that is what you expect ?

Attachment:
gmic_gca.png


So far, here is the script I've written for that effect. It's done in the G'MIC scripting language, so not really easy to read, but really fast to do :)
Link to the script : http://pastebin.com/VDNRpGCV

EDIT : I've inverted the amplitude control, now the more amplitude, the more desaturated colors you get.


This GMic looks so sweet, but how do i get access to it?
I tried refreshing my GMIC filter but didn't see it, please help with easy instructions, i have never manually installed a GMIC script before.

EDIT: hang on i see UPDATE INFORMATION..maybe i'll try that first.

EDIT: yeah installed GMIC 64bit windows it says i have 434 filters but still don't see this filter.

_________________
TinT


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 10:35 am  (#12) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
trandocuctin : Mine says 435 filters, and I believe the 435th is the one you are looking for :) What happens when you push the 'filter update' button ?


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 10:45 am  (#13) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
Ronounours wrote:
trandocuctin : Mine says 435 filters, and I believe the 435th is the one you are looking for :) What happens when you push the 'filter update' button ?

That was it..I just had to push the update, I thought if I installed it it would have the udpates, guess not ..
Thanks... Now I am gonna play, so excited.

Here i used the filter and selected red flowers, result is pretty awesome.
Image

_________________
TinT


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 11:07 am  (#14) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
this new filter is just so much fun to play with man.
original
Image

filter selected the glow of lights
Image

_________________
TinT


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 1:30 pm  (#15) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
can't stop playing with this filter.
I think every camera should have this filter.
sorry hope you don't mind me playing with your posted image as well. :D
Image

Image

below I tried to apply the filter to separate copies of the same image, yellow lights and boat blues and use sg's method of masking to combine 2 images together to reveal blues and yellows.
Image

_________________
TinT


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 3:29 pm  (#16) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
Nice outcomes.
I'm happy to see this filter can be useful for someone!


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Wed Jul 15, 2015 4:28 pm  (#17) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
Thank you so much for the GMIC filter.

_________________
TinT


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Thu Jul 16, 2015 12:06 am  (#18) 
Offline
GimpChat Member
User avatar

Joined: May 03, 2015
Posts: 13
Location: Genova, Italy
saulgoode wrote:
The problem is that the SF-COLOR value (indeed, the entire 'script-fu-register' procedure) only gets evaluated when the script is initially installed -- it is not re-evaluated when you run the installed command.


Ok, I understood

saulgoode wrote:
Your script is well written, however, I would caution against selecting your layers based on their names. When you set a layer name (using 'gimp-layer-new' for example), the actual layer name may not end up what you set it to; if the layer name is already used for another layer then GIMP will use a different name by appending a #nnn to the name you request.


I noticed it while making some trial. I use the layerID for the mask and the "New from visible" layer, the next step will be to rewrite also the rest of the code.


@Ronounours: thanks for the script! I alredy have G'MIC installed, I update it and the plug in seem to work as I wanted

@paynekj: I never use Photivo for its big ram requiment :( my main PC is a 6 years old dual core, but it's limited to 2 Gb of ram (motherboard limitation) and I still use a 32bit WinXP. Maybe i can try to reproduce it with the Curves+ plug in in Paint.net


Top
 Post subject: Re: Ask for help for a filter like "color accent" but more "graduated"
PostPosted: Thu Jul 16, 2015 11:26 am  (#19) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
I had to try Photivo's saturation curve and I have to say it's pretty sweet too...
but only problem is it keeps crashing on me sometimes partway through saving a file so i get this black bar at the bottom of my image...(but when it works it's sweet). :hehe

_________________
TinT


Top
Post new topic Reply to topic  [ 19 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) use of a color curves preset in a python filter

42

No new posts New GEGL filter that inverts transparency and allows a color fill

2

No new posts Attachment(s) New G'MIC filter "Color Wheel"

12

No new posts Attachment(s) GEGL Color Light Fusion (12 blend modes for color overlay)

9

No new posts Attachment(s) Background color chanage and typed text color change

8



* Login  



Powered by phpBB3 © phpBB Group